diff --git a/COPYRIGHT b/COPYRIGHT index f75b94b..b48e73e 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -132,3 +132,40 @@ License of Mumble (valid for both the images and Murmur*.ice): SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +=============================================================================== + +The directory pyweb/rosetta provides the rosetta Django application that allows +easy editing of Django's translation files. The app is published on Google Code +under the MIT license: + + +Upstream Author: + mbonetti + +Copyright: + + All rights reserved. + +License: + + The MIT License + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + diff --git a/pyweb/rosetta/__init__.py b/pyweb/rosetta/__init__.py new file mode 100644 index 0000000..248ed45 --- /dev/null +++ b/pyweb/rosetta/__init__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +VERSION = (0, 5, 1) + +def get_version(svn=False, limit=3): + "Returns the version as a human-format string." + v = '.'.join([str(i) for i in VERSION[:limit]]) + if svn and limit >= 3: + from django.utils.version import get_svn_revision + import os + svn_rev = get_svn_revision(os.path.dirname(__file__)) + if svn_rev: + v = '%s.%s' % (v, svn_rev) + return v diff --git a/pyweb/rosetta/conf/__init__.py b/pyweb/rosetta/conf/__init__.py new file mode 100644 index 0000000..76f7515 --- /dev/null +++ b/pyweb/rosetta/conf/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + diff --git a/pyweb/rosetta/conf/settings.py b/pyweb/rosetta/conf/settings.py new file mode 100644 index 0000000..f8b8849 --- /dev/null +++ b/pyweb/rosetta/conf/settings.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +from django.conf import settings + +# Number of messages to display per page. +MESSAGES_PER_PAGE = getattr(settings,'ROSETTA_MESSAGES_PER_PAGE',10) + + +# Enable Google translation suggestions +ENABLE_TRANSLATION_SUGGESTIONS = getattr(settings,'ROSETTA_ENABLE_TRANSLATION_SUGGESTIONS',True) + +# Displays this language beside the original MSGID in the admin +MAIN_LANGUAGE = getattr(settings,'ROSETTA_MAIN_LANGUAGE', None) + + +""" +When running WSGI daemon mode, using mod_wsgi 2.0c5 or later, this setting +controls whether the contents of the gettext catalog files should be +automatically reloaded by the WSGI processes each time they are modified. + +Notes: + + * The WSGI daemon process must have write permissions on the WSGI script file + (as defined by the WSGIScriptAlias directive.) + * WSGIScriptReloading must be set to On (it is by default) + * For performance reasons, this setting should be disabled in production environments + * When a common rosetta installation is shared among different Django projects, + each one running in its own distinct WSGI virtual host, you can activate + auto-reloading in individual projects by enabling this setting in the project's + own configuration file, i.e. in the project's settings.py + +Refs: + + * http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode + * http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIReloadMechanism + +""" +WSGI_AUTO_RELOAD = getattr(settings,'ROSETTA_WSGI_AUTO_RELOAD', False) + diff --git a/pyweb/rosetta/locale/de/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/de/LC_MESSAGES/django.mo new file mode 100644 index 0000000..283f98e Binary files /dev/null and b/pyweb/rosetta/locale/de/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/de/LC_MESSAGES/django.po b/pyweb/rosetta/locale/de/LC_MESSAGES/django.po new file mode 100644 index 0000000..378e87f --- /dev/null +++ b/pyweb/rosetta/locale/de/LC_MESSAGES/django.po @@ -0,0 +1,174 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"PO-Revision-Date: 2008-06-16 10:11+0100\n" +"Last-Translator: Martin Mahner \n" +"Language-Team: patrick lauber \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Poedit-Language: German\n" +"X-Poedit-Country: SWITZERLAND\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Home" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Sprachwahl" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Fortschritt" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Texte" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Übersetzt" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "Unscharf" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Veraltet" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Datei" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "Nichts zu übersetzen!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"Sie haben keine Sprachen in der Einstellungsdatei definiert oder bis jetzt " +"noch keine Übersetzungskataloge generiert." + +# python-format +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Unter Django's I18N documentation finden " +"Sie eine Anleitung, wie sie Internationalisierung in Ihrem Projekt " +"einrichten." + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Wähle eine andere Datei" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Laden sie diesen Katalog herunter" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Fortschritt: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "" +"Datei ist schreibgeschützt: Laden Sie die Datei herunter wenn sie mit dem " +"Editieren fertig sind!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Englisch" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Übersetze in %(rosetta_i18n_lang_name)s" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Anzeige:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Nur unübersetzte" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Nur übersetzte" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "Nur unscharfe" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "Alle" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Suchen" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Los" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "Original" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Gefunden in" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "vorschlagen" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "%(more_count)s mehr" +msgstr[1] "%(more_count)s mehr" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Speichern und nächsten Block übersetzen" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Zur Seite:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Anzeigen:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s Text" +msgstr[1] "%(hits)s/%(message_number)s Texte" + +#~ msgid "Both" +#~ msgstr "Beide" diff --git a/pyweb/rosetta/locale/es/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/es/LC_MESSAGES/django.mo new file mode 100644 index 0000000..99a6d85 Binary files /dev/null and b/pyweb/rosetta/locale/es/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/es/LC_MESSAGES/django.po b/pyweb/rosetta/locale/es/LC_MESSAGES/django.po new file mode 100644 index 0000000..c87f67d --- /dev/null +++ b/pyweb/rosetta/locale/es/LC_MESSAGES/django.po @@ -0,0 +1,171 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"PO-Revision-Date: 2008-11-30 12:12\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Translated-Using: django-rosetta 0.4.RC2\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Inicio" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Selección de idioma" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Progreso" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Mensajes" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Traducido" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "Velloso" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Obsoleto" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Archivo" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "¡Nada que traducir!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"No has especificado ningún idioma en tu archivo de settings o no has " +"generado todavía un batch para traducción de catálogos." + +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Por favor visita la Documentación de Django " +"sobre I18N para obtener una guía sobre cómo añadir internacionalización " +"a tu proyecto." + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Selecciona otro archivo" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Descarga este catálogo" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Progreso: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "" +"El archivo está en modo lectura: ¡Descarga el archivo cuando termines de " +"editarlo!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Inglés" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Traducir al %(rosetta_i18n_lang_name)s " + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Pantalla:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Sin traducir sólo" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Traducidos sólo" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "Vellosos sólo" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Búsqueda" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Ir" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Ocurrencia(s)" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "sugerir" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "%(more_count)s más" +msgstr[1] "%(more_count)s más" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Guardar y traducir siguiente bloque" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Ir a la página:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Mostrando:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s mensaje" +msgstr[1] "%(hits)s/%(message_number)s mensajes" + +#~ msgid "Both" +#~ msgstr "Ambos" diff --git a/pyweb/rosetta/locale/fr/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/fr/LC_MESSAGES/django.mo new file mode 100644 index 0000000..bb22743 Binary files /dev/null and b/pyweb/rosetta/locale/fr/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/fr/LC_MESSAGES/django.po b/pyweb/rosetta/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..362250a --- /dev/null +++ b/pyweb/rosetta/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,172 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"PO-Revision-Date: 2008-09-22 11:02\n" +"Last-Translator: Admin Admin \n" +"Language-Team: French \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Translated-Using: django-rosetta 0.4.RC2\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Accueil" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Sélection de la langue" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "Application" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Progression" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Messages" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Traduits" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "Flous" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Obsolètes" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Fichier" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "Rien à Traduire!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"Vous n'avez spécifié aucune langue dans votre fichier de configuration, ou " +"n'avez pas encore généré le catalogue initial de traductions pour votre " +"projet." + +# python-format +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Veuillez vous référer à la documentation sur " +"l'internationalisation de Django pour un guide sur comment activer et " +"configurer la traduction de votre projet." + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Choisir un autre fichier" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Télécharger ce catalogue" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Progression: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "" +"Fichier en seule lecture: télécharger le fichier à la fin de l'édition!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Anglais" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Traduire en %(rosetta_i18n_lang_name)s" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Afficher:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Non-traduits uniquement" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Traduits uniquement" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "Flous uniquement" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "Tous" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Recherche" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Go" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "Original" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Occurrences(s)" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "suggérer" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "%(more_count)s de plus" +msgstr[1] "%(more_count)s de plus" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Sauver et traduire le prochain bloc" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Passer à la page:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Affichés:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s message" +msgstr[1] " %(hits)s/%(message_number)s messages" + +#~ msgid "Both" +#~ msgstr "Les deux" diff --git a/pyweb/rosetta/locale/hu/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/hu/LC_MESSAGES/django.mo new file mode 100644 index 0000000..4f9fb49 Binary files /dev/null and b/pyweb/rosetta/locale/hu/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/hu/LC_MESSAGES/django.po b/pyweb/rosetta/locale/hu/LC_MESSAGES/django.po new file mode 100644 index 0000000..4bf066d --- /dev/null +++ b/pyweb/rosetta/locale/hu/LC_MESSAGES/django.po @@ -0,0 +1,165 @@ +# Copyright (C) 2008 +# Gergely Kontra , 2008. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"PO-Revision-Date: 2008-10-09 19:08+0100\n" +"Last-Translator: Gergely Kontra \n" +"Language-Team: nomail \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Translated-Using: django-rosetta 0.4.RC2\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Főoldal" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Nyelvválasztás" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Állapot" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Üzenet" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Lefordítva" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Elavult" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Fájl" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "Nincs mit fordítani!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"Nincs beállítva egyetlen nyelv sem van nem hozott létre egy fordítási " +"katalóguskoteget." + +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Projekted többnyelvűvé alakításához lásd a Django I18N dokumentációt!" + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Másik fájl választása" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Katalógus letöltése" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "%(percent_translated)s% kész" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "A fájl írásvédett: töltse le a katalógust, ha végzett!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Angol" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Fordítsa %(rosetta_i18n_lang_name)s nyelvre" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Szűrés:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Fordításra vár" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Lefordított" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Keresés" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Keress" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Előfordulások" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "ajánl" + +#: templates/rosetta/pofile.html:84 +#, fuzzy, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "még %(more_count)s" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Mentés" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Ugorj erre az oldalra:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Szűrés:" + +#: templates/rosetta/pofile.html:115 +#, fuzzy, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s üzenet" + +#~ msgid "Both" +#~ msgstr "Minden" diff --git a/pyweb/rosetta/locale/it/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/it/LC_MESSAGES/django.mo new file mode 100644 index 0000000..4f47241 Binary files /dev/null and b/pyweb/rosetta/locale/it/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/it/LC_MESSAGES/django.po b/pyweb/rosetta/locale/it/LC_MESSAGES/django.po new file mode 100644 index 0000000..684aac3 --- /dev/null +++ b/pyweb/rosetta/locale/it/LC_MESSAGES/django.po @@ -0,0 +1,168 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"Last-Translator: Marco Bonetti \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Inizio" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Selezione della lingua" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "Applicazione" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Progressione" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Messaggio" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Tradotto" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Obsoleto" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "File" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "Nulla da tradurre!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"Non avete specificato nessuna lingua nelle vostre impostazioni, o non avete " +"ancore generato un catalogo iniziale da tradurre." + +# python-format +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Vogliate riferirvi alla documentazione " +"sull'internazionalizzazione di Django per una giuda su come impostare le " +"traduzioni per il vostro progetto." + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Scegliere un altro file" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Scaricare il catalogo" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Progressione: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "file in solo lettura: scaricare il file alla fine dell'edizione!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Inglese" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Tradurre verso il %(rosetta_i18n_lang_name)s" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Mostra:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Solo non tradotti" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Solo tradotti" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "Solo fuzzy" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "Tutti" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Cercare" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Via" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "Originale" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Occorrenze" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "suggerire" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "un altro" +msgstr[1] "ancora %(more_count)s" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Salvare e tradurre il prossimo blocco" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Passare alla pagina:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Mostrato:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s messaggio" +msgstr[1] "%(hits)s/%(message_number)s messaggi" + +#~ msgid "Both" +#~ msgstr "Entrambi" diff --git a/pyweb/rosetta/locale/nl/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/nl/LC_MESSAGES/django.mo new file mode 100644 index 0000000..372aa82 Binary files /dev/null and b/pyweb/rosetta/locale/nl/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/nl/LC_MESSAGES/django.po b/pyweb/rosetta/locale/nl/LC_MESSAGES/django.po new file mode 100644 index 0000000..f4f9aa8 --- /dev/null +++ b/pyweb/rosetta/locale/nl/LC_MESSAGES/django.po @@ -0,0 +1,171 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) 2008 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the rosetta package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"PO-Revision-Date: 2008-06-05 17:06+0200\n" +"Last-Translator: Joost Cassee \n" +"Language-Team: Joost Cassee \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Voorpagina" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Taalselectie" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Voortgang" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Berichten" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Vertaald" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Niet meer gebruikt" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Bestand" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "Niets te vertalen!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"U heeft geen talen gespecificeerd in het bestand settings.py of nog geen " +"catalogus gegenereerd." + +# python-format +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Zie Django's I18N documentatie (Engels) " +"voor meer informatie over internationalisatie." + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Selecteer een ander bestand" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Download deze catalogus" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Voortgang: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "" +"Dit is bestand is alleen-lezen; download dit bestand wanneer u klaar bent " +"met bewerken!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Engels" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Vertalen in het %(rosetta_i18n_lang_name)s" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Beeld:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Alleen onvertaald" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Alleen vertaald" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Zoeken" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Ga" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Gevonden in" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "" +msgstr[1] "" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Opslaan en volgende blok vertalen" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Snel naar pagina:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Tonen:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s bericht" +msgstr[1] "%(hits)s/%(message_number)s berichten" + +#~ msgid "Both" +#~ msgstr "Beide" diff --git a/pyweb/rosetta/locale/pl/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/pl/LC_MESSAGES/django.mo new file mode 100644 index 0000000..931aedd Binary files /dev/null and b/pyweb/rosetta/locale/pl/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/pl/LC_MESSAGES/django.po b/pyweb/rosetta/locale/pl/LC_MESSAGES/django.po new file mode 100644 index 0000000..a268433 --- /dev/null +++ b/pyweb/rosetta/locale/pl/LC_MESSAGES/django.po @@ -0,0 +1,170 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"PO-Revision-Date: 2008-09-12 12:16\n" +"Last-Translator: \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Translated-Using: django-rosetta 0.4.RC2\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Początek" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Wybór języka" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Postęp" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Komunikaty" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Przetłumaczone" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Przestarzałe" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Plik" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "Nie ma nic do przetłumaczenia!" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" +"Nie podałeś żadnych języków w plikach ustawień, lub nie wygenerowałeś " +"jeszcze katalogów do tłumaczeń." + +# python-format +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" +"Sprawdź pomoc dotyczącą internacjonalizacji " +"Django I18N , aby znaleźć dokumentację na temat internacjonalizacji " +"twojego projektu." + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Wybierz inny plik" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Pobierz ten katalog" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Postęp: %(percent_translated)s %" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "Plik jest tylko do odczytu: pobierz go kiedy skończysz edytować" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Angielski" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Przetłumacz na %(rosetta_i18n_lang_name)s " + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Wyświetl:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Tylko nieprzetłumaczone" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Tylko przetłumaczone" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Szukaj" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Idź" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Wystąpienie(a)" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "sugeruj" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "%(more_count)s więcej" +msgstr[1] "%(more_count)s więcej" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Zapisz i tłumacz następny blok" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Przejdź do strony:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Wyświetlanie:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s komunikat" +msgstr[1] "%(hits)s/%(message_number)s komunikatów" + +#~ msgid "Both" +#~ msgstr "Oba" diff --git a/pyweb/rosetta/locale/ru/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/ru/LC_MESSAGES/django.mo new file mode 100644 index 0000000..b13e007 Binary files /dev/null and b/pyweb/rosetta/locale/ru/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/ru/LC_MESSAGES/django.po b/pyweb/rosetta/locale/ru/LC_MESSAGES/django.po new file mode 100644 index 0000000..b59254d --- /dev/null +++ b/pyweb/rosetta/locale/ru/LC_MESSAGES/django.po @@ -0,0 +1,163 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"Last-Translator: Nazar Leush \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Начало" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Выбор языка" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Обработано" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Сообщений" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "С переводом" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Устаревших" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Файл" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" + +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Выбрать другой файл" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Скачать этот каталог" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Обработано: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "" +"Файл только для чтения: загрузите файл после завершения редактирования!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Английский" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Перевод на %(rosetta_i18n_lang_name)s" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Отображать:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Только без перевода" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Только с переводом" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Поиск" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Вперёд" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Встречается в" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "" +msgstr[1] "" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Сохранить и перевести следующий блок" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Перейти к странице:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Отображение:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s сообщение" +msgstr[1] "%(hits)s/%(message_number)s сообщений" + +#~ msgid "Both" +#~ msgstr "Все" diff --git a/pyweb/rosetta/locale/uk/LC_MESSAGES/django.mo b/pyweb/rosetta/locale/uk/LC_MESSAGES/django.mo new file mode 100644 index 0000000..568367f Binary files /dev/null and b/pyweb/rosetta/locale/uk/LC_MESSAGES/django.mo differ diff --git a/pyweb/rosetta/locale/uk/LC_MESSAGES/django.po b/pyweb/rosetta/locale/uk/LC_MESSAGES/django.po new file mode 100644 index 0000000..637c628 --- /dev/null +++ b/pyweb/rosetta/locale/uk/LC_MESSAGES/django.po @@ -0,0 +1,162 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Rosetta\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-10-21 12:21+0200\n" +"Last-Translator: Nazar Leush \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: templates/rosetta/languages.html:3 templates/rosetta/pofile.html:13 +msgid "Home" +msgstr "Домівка" + +#: templates/rosetta/languages.html:3 templates/rosetta/languages.html.py:4 +msgid "Language selection" +msgstr "Вибір мови" + +#: templates/rosetta/languages.html:14 +msgid "Application" +msgstr "" + +#: templates/rosetta/languages.html:15 +msgid "Progress" +msgstr "Завершено" + +#: templates/rosetta/languages.html:16 +msgid "Messages" +msgstr "Повідомлень" + +#: templates/rosetta/languages.html:17 +msgid "Translated" +msgstr "Перекладено" + +#: templates/rosetta/languages.html:18 templates/rosetta/pofile.html:48 +msgid "Fuzzy" +msgstr "" + +#: templates/rosetta/languages.html:19 +msgid "Obsolete" +msgstr "Застарілих" + +#: templates/rosetta/languages.html:20 +msgid "File" +msgstr "Файл" + +#: templates/rosetta/languages.html:41 +msgid "Nothing to translate!" +msgstr "" + +#: templates/rosetta/languages.html:42 +msgid "" +"You haven't specified any languages in your settings file, or haven't yet " +"generated a batch of translation catalogs." +msgstr "" + +#: templates/rosetta/languages.html:43 +#, python-format +msgid "" +"Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project." +msgstr "" + +#: templates/rosetta/pofile.html:7 +msgid "Pick another file" +msgstr "Вибрати інший файл" + +#: templates/rosetta/pofile.html:8 +msgid "Download this catalog" +msgstr "Завантажити цей каталог" + +#: templates/rosetta/pofile.html:16 +msgid "Progress: %(percent_translated)s%" +msgstr "Завершено: %(percent_translated)s%" + +#: templates/rosetta/pofile.html:17 +msgid "File is read-only: download the file when done editing!" +msgstr "Файл тільки для читання: завантажте файл після завершення редагування!" + +#: templates/rosetta/pofile.html:19 +msgid "English" +msgstr "Англійська" + +#: templates/rosetta/pofile.html:21 +#, python-format +msgid "Translate into %(rosetta_i18n_lang_name)s" +msgstr "Переклад на %(rosetta_i18n_lang_name)s" + +#: templates/rosetta/pofile.html:24 +msgid "Display:" +msgstr "Відображати:" + +#: templates/rosetta/pofile.html:25 +msgid "Untranslated only" +msgstr "Тільки неперекладені" + +#: templates/rosetta/pofile.html:26 +msgid "Translated only" +msgstr "Тільки перекладені" + +#: templates/rosetta/pofile.html:27 +msgid "Fuzzy only" +msgstr "" + +#: templates/rosetta/pofile.html:28 +msgid "All" +msgstr "" + +#: templates/rosetta/pofile.html:34 +msgid "Search" +msgstr "Пошук" + +#: templates/rosetta/pofile.html:36 +msgid "Go" +msgstr "Вперед" + +#: templates/rosetta/pofile.html:45 +msgid "Original" +msgstr "" + +#: templates/rosetta/pofile.html:49 +msgid "Occurrences(s)" +msgstr "Зустрічається в" + +#: templates/rosetta/pofile.html:73 +msgid "suggest" +msgstr "" + +#: templates/rosetta/pofile.html:84 +#, python-format +msgid "%(more_count)s more" +msgid_plural "%(more_count)s more" +msgstr[0] "" +msgstr[1] "" + +#: templates/rosetta/pofile.html:96 +msgid "Save and translate next block" +msgstr "Записати і перекласти наступний блок" + +#: templates/rosetta/pofile.html:100 +msgid "Skip to page:" +msgstr "Перейти до сторінки:" + +#: templates/rosetta/pofile.html:113 +msgid "Displaying:" +msgstr "Відображення:" + +#: templates/rosetta/pofile.html:115 +#, python-format +msgid "%(hits)s/%(message_number)s message" +msgid_plural "%(hits)s/%(message_number)s messages" +msgstr[0] "%(hits)s/%(message_number)s повідомлення" +msgstr[1] "%(hits)s/%(message_number)s повідомлень" + +#~ msgid "Both" +#~ msgstr "Всі" diff --git a/pyweb/rosetta/models.py b/pyweb/rosetta/models.py new file mode 100644 index 0000000..6f6ad32 --- /dev/null +++ b/pyweb/rosetta/models.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +from django.db import models +# Create your models here. diff --git a/pyweb/rosetta/polib.py b/pyweb/rosetta/polib.py new file mode 100644 index 0000000..1b32268 --- /dev/null +++ b/pyweb/rosetta/polib.py @@ -0,0 +1,1443 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# License: MIT (see LICENSE file provided) +# vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: + +""" +**polib** allows you to manipulate, create, modify gettext files (pot, po +and mo files). You can load existing files, iterate through it's entries, +add, modify entries, comments or metadata, etc... or create new po files +from scratch. + +**polib** provides a simple and pythonic API, exporting only three +convenience functions (*pofile*, *mofile* and *detect_encoding*), and the +four core classes, *POFile*, *MOFile*, *POEntry* and *MOEntry* for creating +new files/entries. + +**Basic example**: + +>>> import polib +>>> # load an existing po file +>>> po = polib.pofile('tests/test_utf8.po') +>>> for entry in po: +... # do something with entry... +... pass +>>> # add an entry +>>> entry = polib.POEntry(msgid='Welcome', msgstr='Bienvenue') +>>> entry.occurrences = [('welcome.py', '12'), ('anotherfile.py', '34')] +>>> po.append(entry) +>>> # to save our modified po file: +>>> # po.save() +>>> # or you may want to compile the po file +>>> # po.save_as_mofile('tests/test_utf8.mo') + + + * Copyright (C) 2010, David JEAN LOUIS + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + + +""" + +__author__ = 'David JEAN LOUIS ' +__version__ = '0.4.3' +__all__ = ['pofile', 'POFile', 'POEntry', 'mofile', 'MOFile', 'MOEntry', + 'detect_encoding', 'escape', 'unescape'] + +import codecs +import struct +import textwrap +import types + +default_encoding = 'utf-8' + +# function pofile() {{{ + +def pofile(fpath, **kwargs): + """ + Convenience function that parse the po/pot file *fpath* and return + a POFile instance. + + **Keyword arguments**: + - *fpath*: string, full or relative path to the po/pot file to parse + - *wrapwidth*: integer, the wrap width, only useful when -w option was + passed to xgettext (optional, default to 78) + - *autodetect_encoding*: boolean, if set to False the function will + not try to detect the po file encoding (optional, default to True) + - *encoding*: string, an encoding, only relevant if autodetect_encoding + is set to False + + **Example**: + + >>> import polib + >>> po = polib.pofile('tests/test_weird_occurrences.po') + >>> po #doctest: +ELLIPSIS + + >>> import os, tempfile + >>> for fname in ['test_iso-8859-15.po', 'test_utf8.po']: + ... orig_po = polib.pofile('tests/'+fname) + ... tmpf = tempfile.NamedTemporaryFile().name + ... orig_po.save(tmpf) + ... try: + ... new_po = polib.pofile(tmpf) + ... for old, new in zip(orig_po, new_po): + ... if old.msgid != new.msgid: + ... old.msgid + ... new.msgid + ... if old.msgstr != new.msgstr: + ... old.msgid + ... new.msgid + ... finally: + ... os.unlink(tmpf) + >>> po_file = polib.pofile('tests/test_save_as_mofile.po') + >>> tmpf = tempfile.NamedTemporaryFile().name + >>> po_file.save_as_mofile(tmpf) + >>> try: + ... mo_file = polib.mofile(tmpf) + ... for old, new in zip(po_file, mo_file): + ... if po_file._encode(old.msgid) != mo_file._encode(new.msgid): + ... 'OLD: ', po_file._encode(old.msgid) + ... 'NEW: ', mo_file._encode(new.msgid) + ... if po_file._encode(old.msgstr) != mo_file._encode(new.msgstr): + ... 'OLD: ', po_file._encode(old.msgstr) + ... 'NEW: ', mo_file._encode(new.msgstr) + ... print new.msgstr + ... finally: + ... os.unlink(tmpf) + """ + if kwargs.get('autodetect_encoding', True) == True: + enc = detect_encoding(fpath) + else: + enc = kwargs.get('encoding', default_encoding) + parser = _POFileParser(fpath, enc) + instance = parser.parse() + instance.wrapwidth = kwargs.get('wrapwidth', 78) + return instance + +# }}} +# function mofile() {{{ + +def mofile(fpath, **kwargs): + """ + Convenience function that parse the mo file *fpath* and return + a MOFile instance. + + **Keyword arguments**: + - *fpath*: string, full or relative path to the mo file to parse + - *wrapwidth*: integer, the wrap width, only useful when -w option was + passed to xgettext to generate the po file that was used to format + the mo file (optional, default to 78) + - *autodetect_encoding*: boolean, if set to False the function will + not try to detect the po file encoding (optional, default to True) + - *encoding*: string, an encoding, only relevant if autodetect_encoding + is set to False + + **Example**: + + >>> import polib + >>> mo = polib.mofile('tests/test_utf8.mo') + >>> mo #doctest: +ELLIPSIS + + >>> import os, tempfile + >>> for fname in ['test_iso-8859-15.mo', 'test_utf8.mo']: + ... orig_mo = polib.mofile('tests/'+fname) + ... tmpf = tempfile.NamedTemporaryFile().name + ... orig_mo.save(tmpf) + ... try: + ... new_mo = polib.mofile(tmpf) + ... for old, new in zip(orig_mo, new_mo): + ... if old.msgid != new.msgid: + ... old.msgstr + ... new.msgstr + ... finally: + ... os.unlink(tmpf) + """ + if kwargs.get('autodetect_encoding', True) == True: + enc = detect_encoding(fpath, True) + else: + enc = kwargs.get('encoding', default_encoding) + parser = _MOFileParser(fpath, enc) + instance = parser.parse() + instance.wrapwidth = kwargs.get('wrapwidth', 78) + return instance + +# }}} +# function detect_encoding() {{{ + +def detect_encoding(fpath, binary_mode=False): + """ + Try to detect the encoding used by the file *fpath*. The function will + return polib default *encoding* if it's unable to detect it. + + **Keyword argument**: + - *fpath*: string, full or relative path to the mo file to parse. + + **Examples**: + + >>> print(detect_encoding('tests/test_noencoding.po')) + utf-8 + >>> print(detect_encoding('tests/test_utf8.po')) + UTF-8 + >>> print(detect_encoding('tests/test_utf8.mo', True)) + UTF-8 + >>> print(detect_encoding('tests/test_iso-8859-15.po')) + ISO_8859-15 + >>> print(detect_encoding('tests/test_iso-8859-15.mo', True)) + ISO_8859-15 + """ + import re + rx = re.compile(r'"?Content-Type:.+? charset=([\w_\-:\.]+)') + if binary_mode: + mode = 'rb' + else: + mode = 'r' + f = open(fpath, mode) + for l in f.readlines(): + match = rx.search(l) + if match: + f.close() + return match.group(1).strip() + f.close() + return default_encoding + +# }}} +# function escape() {{{ + +def escape(st): + """ + Escape special chars and return the given string *st*. + + **Examples**: + + >>> escape('\\t and \\n and \\r and " and \\\\') + '\\\\t and \\\\n and \\\\r and \\\\" and \\\\\\\\' + """ + st = st.replace('\\', r'\\') + st = st.replace('\t', r'\t') + st = st.replace('\r', r'\r') + st = st.replace('\n', r'\n') + st = st.replace('\"', r'\"') + return st + +# }}} +# function unescape() {{{ + +def unescape(st): + """ + Unescape special chars and return the given string *st*. + + **Examples**: + + >>> unescape('\\\\t and \\\\n and \\\\r and \\\\" and \\\\\\\\') + '\\t and \\n and \\r and " and \\\\' + """ + st = st.replace(r'\"', '"') + st = st.replace(r'\n', '\n') + st = st.replace(r'\r', '\r') + st = st.replace(r'\t', '\t') + st = st.replace(r'\\', '\\') + return st + +# }}} +# class _BaseFile {{{ + +class _BaseFile(list): + """ + Common parent class for POFile and MOFile classes. + This class must **not** be instanciated directly. + """ + + def __init__(self, fpath=None, wrapwidth=78, encoding=default_encoding): + """ + Constructor. + + **Keyword arguments**: + - *fpath*: string, path to po or mo file + - *wrapwidth*: integer, the wrap width, only useful when -w option + was passed to xgettext to generate the po file that was used to + format the mo file, default to 78 (optional). + """ + list.__init__(self) + # the opened file handle + self.fpath = fpath + # the width at which lines should be wrapped + self.wrapwidth = wrapwidth + # the file encoding + self.encoding = encoding + # header + self.header = '' + # both po and mo files have metadata + self.metadata = {} + self.metadata_is_fuzzy = 0 + + def __str__(self): + """String representation of the file.""" + ret = [] + entries = [self.metadata_as_entry()] + \ + [e for e in self if not e.obsolete] + for entry in entries: + ret.append(entry.__str__(self.wrapwidth)) + for entry in self.obsolete_entries(): + ret.append(entry.__str__(self.wrapwidth)) + return '\n'.join(ret) + + def __repr__(self): + """Return the official string representation of the object.""" + return '<%s instance at %x>' % (self.__class__.__name__, id(self)) + + def metadata_as_entry(self): + """Return the metadata as an entry""" + e = POEntry(msgid='') + mdata = self.ordered_metadata() + if mdata: + strs = [] + for name, value in mdata: + # Strip whitespace off each line in a multi-line entry + value = '\n'.join([v.strip() for v in value.split('\n')]) + strs.append('%s: %s' % (name, value)) + e.msgstr = '\n'.join(strs) + '\n' + return e + + def save(self, fpath=None, repr_method='__str__'): + """ + Save the po file to file *fpath* if no file handle exists for + the object. If there's already an open file and no fpath is + provided, then the existing file is rewritten with the modified + data. + + **Keyword arguments**: + - *fpath*: string, full or relative path to the file. + - *repr_method*: string, the method to use for output. + """ + if self.fpath is None and fpath is None: + raise IOError('You must provide a file path to save() method') + contents = getattr(self, repr_method)() + if fpath is None: + fpath = self.fpath + if repr_method == 'to_binary': + fhandle = open(fpath, 'wb') + else: + fhandle = codecs.open(fpath, 'w', self.encoding) + fhandle.write(contents) + fhandle.close() + + def find(self, st, by='msgid'): + """ + Find entry which msgid (or property identified by the *by* + attribute) matches the string *st*. + + **Keyword arguments**: + - *st*: string, the string to search for + - *by*: string, the comparison attribute + + **Examples**: + + >>> po = pofile('tests/test_utf8.po') + >>> entry = po.find('Thursday') + >>> entry.msgstr + u'Jueves' + >>> entry = po.find('Some unexistant msgid') + >>> entry is None + True + >>> entry = po.find('Jueves', 'msgstr') + >>> entry.msgid + u'Thursday' + """ + for e in self: + if getattr(e, by) == st: + return e + return None + + def ordered_metadata(self): + """ + Convenience method that return the metadata ordered. The return + value is list of tuples (metadata name, metadata_value). + """ + # copy the dict first + metadata = self.metadata.copy() + data_order = [ + 'Project-Id-Version', + 'Report-Msgid-Bugs-To', + 'POT-Creation-Date', + 'PO-Revision-Date', + 'Last-Translator', + 'Language-Team', + 'MIME-Version', + 'Content-Type', + 'Content-Transfer-Encoding' + ] + ordered_data = [] + for data in data_order: + try: + value = metadata.pop(data) + ordered_data.append((data, value)) + except KeyError: + pass + # the rest of the metadata won't be ordered there are no specs for this + keys = metadata.keys() + list(keys).sort() + for data in keys: + value = metadata[data] + ordered_data.append((data, value)) + return ordered_data + + def to_binary(self): + """Return the mofile binary representation.""" + import array + import struct + import types + offsets = [] + entries = self.translated_entries() + # the keys are sorted in the .mo file + def cmp(_self, other): + if _self.msgid > other.msgid: + return 1 + elif _self.msgid < other.msgid: + return -1 + else: + return 0 + # add metadata entry + entries.sort(cmp) + mentry = self.metadata_as_entry() + mentry.msgstr = mentry.msgstr.replace('\\n', '').lstrip() + entries = [mentry] + entries + entries_len = len(entries) + ids, strs = '', '' + for e in entries: + # For each string, we need size and file offset. Each string is + # NUL terminated; the NUL does not count into the size. + if e.msgid_plural: + indexes = e.msgstr_plural.keys() + indexes.sort() + msgstr = [] + for index in indexes: + msgstr.append(e.msgstr_plural[index]) + msgid = self._encode(e.msgid + '\0' + e.msgid_plural) + msgstr = self._encode('\0'.join(msgstr)) + else: + msgid = self._encode(e.msgid) + msgstr = self._encode(e.msgstr) + offsets.append((len(ids), len(msgid), len(strs), len(msgstr))) + ids += msgid + '\0' + strs += msgstr + '\0' + # The header is 7 32-bit unsigned integers. + keystart = 7*4+16*entries_len + # and the values start after the keys + valuestart = keystart + len(ids) + koffsets = [] + voffsets = [] + # The string table first has the list of keys, then the list of values. + # Each entry has first the size of the string, then the file offset. + for o1, l1, o2, l2 in offsets: + koffsets += [l1, o1+keystart] + voffsets += [l2, o2+valuestart] + offsets = koffsets + voffsets + output = struct.pack("IIIIIII", + 0x950412de, # Magic number + 0, # Version + entries_len, # # of entries + 7*4, # start of key index + 7*4+entries_len*8, # start of value index + 0, 0) # size and offset of hash table + output += array.array("I", offsets).tostring() + output += ids + output += strs + return output + + def _encode(self, mixed): + """ + Encode the given argument with the file encoding if the type is unicode + and return the encoded string. + """ + if type(mixed) == types.UnicodeType: + return mixed.encode(self.encoding) + return mixed + +# }}} +# class POFile {{{ + +class POFile(_BaseFile): + ''' + Po (or Pot) file reader/writer. + POFile objects inherit the list objects methods. + + **Example**: + + >>> po = POFile() + >>> entry1 = POEntry( + ... msgid="Some english text", + ... msgstr="Un texte en anglais" + ... ) + >>> entry1.occurrences = [('testfile', 12),('another_file', 1)] + >>> entry1.comment = "Some useful comment" + >>> entry2 = POEntry( + ... msgid="Peace in some languages", + ... msgstr="Pace سلام שלום Hasîtî 和平" + ... ) + >>> entry2.occurrences = [('testfile', 15),('another_file', 5)] + >>> entry2.comment = "Another useful comment" + >>> entry3 = POEntry( + ... msgid='Some entry with quotes " \\"', + ... msgstr='Un message unicode avec des quotes " \\"' + ... ) + >>> entry3.comment = "Test string quoting" + >>> po.append(entry1) + >>> po.append(entry2) + >>> po.append(entry3) + >>> po.header = "Some Header" + >>> print(po) + # Some Header + msgid "" + msgstr "" + + #. Some useful comment + #: testfile:12 another_file:1 + msgid "Some english text" + msgstr "Un texte en anglais" + + #. Another useful comment + #: testfile:15 another_file:5 + msgid "Peace in some languages" + msgstr "Pace سلام שלום Hasîtî 和平" + + #. Test string quoting + msgid "Some entry with quotes \\" \\"" + msgstr "Un message unicode avec des quotes \\" \\"" + + ''' + + def __str__(self): + """Return the string representation of the po file""" + ret, headers = '', self.header.split('\n') + for header in headers: + if header[:1] in [',', ':']: + ret += '#%s\n' % header + else: + ret += '# %s\n' % header + return ret + _BaseFile.__str__(self) + + def save_as_mofile(self, fpath): + """ + Save the binary representation of the file to *fpath*. + + **Keyword arguments**: + - *fpath*: string, full or relative path to the file. + """ + _BaseFile.save(self, fpath, 'to_binary') + + def percent_translated(self): + """ + Convenience method that return the percentage of translated + messages. + + **Example**: + + >>> import polib + >>> po = polib.pofile('tests/test_pofile_helpers.po') + >>> po.percent_translated() + 50 + >>> po = POFile() + >>> po.percent_translated() + 100 + """ + total = len([e for e in self if not e.obsolete]) + if total == 0: + return 100 + translated = len(self.translated_entries()) + return int((100.00 / float(total)) * translated) + + def translated_entries(self): + """ + Convenience method that return a list of translated entries. + + **Example**: + + >>> import polib + >>> po = polib.pofile('tests/test_pofile_helpers.po') + >>> len(po.translated_entries()) + 6 + """ + return [e for e in self if e.translated() and not e.obsolete] + + def untranslated_entries(self): + """ + Convenience method that return a list of untranslated entries. + + **Example**: + + >>> import polib + >>> po = polib.pofile('tests/test_pofile_helpers.po') + >>> len(po.untranslated_entries()) + 6 + """ + return [e for e in self if not e.translated() and not e.obsolete] + + def fuzzy_entries(self): + """ + Convenience method that return the list of 'fuzzy' entries. + + **Example**: + + >>> import polib + >>> po = polib.pofile('tests/test_pofile_helpers.po') + >>> len(po.fuzzy_entries()) + 2 + """ + return [e for e in self if 'fuzzy' in e.flags] + + def obsolete_entries(self): + """ + Convenience method that return the list of obsolete entries. + + **Example**: + + >>> import polib + >>> po = polib.pofile('tests/test_pofile_helpers.po') + >>> len(po.obsolete_entries()) + 4 + """ + return [e for e in self if e.obsolete] + + def merge(self, refpot): + """ + XXX this could not work if encodings are different, needs thinking + and general refactoring of how polib handles encoding... + + Convenience method that merge the current pofile with the pot file + provided. It behaves exactly as the gettext msgmerge utility: + + - comments of this file will be preserved, but extracted comments + and occurrences will be discarded + - any translations or comments in the file will be discarded, + however dot comments and file positions will be preserved + + **Keyword argument**: + - *refpot*: object POFile, the reference catalog. + + **Example**: + + >>> import polib + >>> refpot = polib.pofile('tests/test_merge.pot') + >>> po = polib.pofile('tests/test_merge_before.po') + >>> po.merge(refpot) + >>> expected_po = polib.pofile('tests/test_merge_after.po') + >>> unicode(po) == unicode(expected_po) + True + """ + for entry in refpot: + e = self.find(entry.msgid) + if e is None: + e = POEntry() + self.append(e) + e.merge(entry) + # ok, now we must "obsolete" entries that are not in the refpot + # anymore + for entry in self: + if refpot.find(entry.msgid) is None: + entry.obsolete = True + +# }}} +# class MOFile {{{ + +class MOFile(_BaseFile): + ''' + Mo file reader/writer. + MOFile objects inherit the list objects methods. + + **Example**: + + >>> mo = MOFile() + >>> entry1 = POEntry( + ... msgid="Some english text", + ... msgstr="Un texte en anglais" + ... ) + >>> entry2 = POEntry( + ... msgid="I need my dirty cheese", + ... msgstr="Je veux mon sale fromage" + ... ) + >>> entry3 = MOEntry( + ... msgid='Some entry with quotes " \\"', + ... msgstr='Un message unicode avec des quotes " \\"' + ... ) + >>> mo.append(entry1) + >>> mo.append(entry2) + >>> mo.append(entry3) + >>> print(mo) + msgid "" + msgstr "" + + msgid "Some english text" + msgstr "Un texte en anglais" + + msgid "I need my dirty cheese" + msgstr "Je veux mon sale fromage" + + msgid "Some entry with quotes \\" \\"" + msgstr "Un message unicode avec des quotes \\" \\"" + + ''' + + def __init__(self, *args, **kwargs): + """ + MOFile constructor. Mo files have two other properties: + - magic_number: the magic_number of the binary file, + - version: the version of the mo spec. + """ + _BaseFile.__init__(self, *args, **kwargs) + self.magic_number = None + self.version = 0 + + def save_as_pofile(self, fpath): + """ + Save the string representation of the file to *fpath*. + + **Keyword argument**: + - *fpath*: string, full or relative path to the file. + """ + _BaseFile.save(self, fpath) + + def save(self, fpath): + """ + Save the binary representation of the file to *fpath*. + + **Keyword argument**: + - *fpath*: string, full or relative path to the file. + """ + _BaseFile.save(self, fpath, 'to_binary') + + def percent_translated(self): + """ + Convenience method to keep the same interface with POFile instances. + """ + return 100 + + def translated_entries(self): + """ + Convenience method to keep the same interface with POFile instances. + """ + return self + + def untranslated_entries(self): + """ + Convenience method to keep the same interface with POFile instances. + """ + return [] + + def fuzzy_entries(self): + """ + Convenience method to keep the same interface with POFile instances. + """ + return [] + + def obsolete_entries(self): + """ + Convenience method to keep the same interface with POFile instances. + """ + return [] + +# }}} +# class _BaseEntry {{{ + +class _BaseEntry(object): + """ + Base class for POEntry or MOEntry objects. + This class must *not* be instanciated directly. + """ + + def __init__(self, *args, **kwargs): + """Base Entry constructor.""" + self.msgid = kwargs.get('msgid', '') + self.msgstr = kwargs.get('msgstr', '') + self.msgid_plural = kwargs.get('msgid_plural', '') + self.msgstr_plural = kwargs.get('msgstr_plural', {}) + self.obsolete = kwargs.get('obsolete', False) + self.encoding = kwargs.get('encoding', default_encoding) + self.msgctxt = kwargs.get('msgctxt', None) + + def __repr__(self): + """Return the official string representation of the object.""" + return '<%s instance at %x>' % (self.__class__.__name__, id(self)) + + def __str__(self, wrapwidth=78): + """ + Common string representation of the POEntry and MOEntry + objects. + """ + if self.obsolete: + delflag = '#~ ' + else: + delflag = '' + ret = [] + # write the msgctxt if any + if self.msgctxt is not None: + ret += self._str_field("msgctxt", delflag, "", self.msgctxt) + # write the msgid + ret += self._str_field("msgid", delflag, "", self.msgid) + # write the msgid_plural if any + if self.msgid_plural: + ret += self._str_field("msgid_plural", delflag, "", self.msgid_plural) + if self.msgstr_plural: + # write the msgstr_plural if any + msgstrs = self.msgstr_plural + keys = list(msgstrs) + keys.sort() + for index in keys: + msgstr = msgstrs[index] + plural_index = '[%s]' % index + ret += self._str_field("msgstr", delflag, plural_index, msgstr) + else: + # otherwise write the msgstr + ret += self._str_field("msgstr", delflag, "", self.msgstr) + ret.append('') + return '\n'.join(ret) + + def _str_field(self, fieldname, delflag, plural_index, field): + lines = field.splitlines(True) # keep line breaks in strings + # potentially, we could do line-wrapping here, but textwrap.wrap + # treats whitespace too carelessly for us to use it. + if len(lines) > 1: + lines = ['']+lines # start with initial empty line + else: + lines = [field] # needed for the empty string case + ret = ['%s%s%s "%s"' % (delflag, fieldname, plural_index, + escape(lines.pop(0)))] + for mstr in lines: + ret.append('%s"%s"' % (delflag, escape(mstr))) + return ret + +# }}} +# class POEntry {{{ + +class POEntry(_BaseEntry): + """ + Represents a po file entry. + + **Examples**: + + >>> entry = POEntry(msgid='Welcome', msgstr='Bienvenue') + >>> entry.occurrences = [('welcome.py', 12), ('anotherfile.py', 34)] + >>> print(entry) + #: welcome.py:12 anotherfile.py:34 + msgid "Welcome" + msgstr "Bienvenue" + + >>> entry = POEntry() + >>> entry.occurrences = [('src/some-very-long-filename-that-should-not-be-wrapped-even-if-it-is-larger-than-the-wrap-limit.c', 32), ('src/eggs.c', 45)] + >>> entry.comment = 'A plural translation. This is a very very very long line please do not wrap, this is just for testing comment wrapping...' + >>> entry.tcomment = 'A plural translation. This is a very very very long line please do not wrap, this is just for testing comment wrapping...' + >>> entry.flags.append('c-format') + >>> entry.msgid = 'I have spam but no egg !' + >>> entry.msgid_plural = 'I have spam and %d eggs !' + >>> entry.msgstr_plural[0] = "J'ai du jambon mais aucun oeuf !" + >>> entry.msgstr_plural[1] = "J'ai du jambon et %d oeufs !" + >>> print(entry) + #. A plural translation. This is a very very very long line please do not + #. wrap, this is just for testing comment wrapping... + # A plural translation. This is a very very very long line please do not wrap, + # this is just for testing comment wrapping... + #: src/some-very-long-filename-that-should-not-be-wrapped-even-if-it-is-larger-than-the-wrap-limit.c:32 + #: src/eggs.c:45 + #, c-format + msgid "I have spam but no egg !" + msgid_plural "I have spam and %d eggs !" + msgstr[0] "J'ai du jambon mais aucun oeuf !" + msgstr[1] "J'ai du jambon et %d oeufs !" + + """ + + def __init__(self, *args, **kwargs): + """POEntry constructor.""" + _BaseEntry.__init__(self, *args, **kwargs) + self.comment = kwargs.get('comment', '') + self.tcomment = kwargs.get('tcomment', '') + self.occurrences = kwargs.get('occurrences', []) + self.flags = kwargs.get('flags', []) + + def __str__(self, wrapwidth=78): + """ + Return the string representation of the entry. + """ + if self.obsolete: + return _BaseEntry.__str__(self) + ret = [] + # comment first, if any (with text wrapping as xgettext does) + if self.comment != '': + for comment in self.comment.split('\n'): + if wrapwidth > 0 and len(comment) > wrapwidth-3: + ret += textwrap.wrap(comment, wrapwidth, + initial_indent='#. ', + subsequent_indent='#. ', + break_long_words=False) + else: + ret.append('#. %s' % comment) + # translator comment, if any (with text wrapping as xgettext does) + if self.tcomment != '': + for tcomment in self.tcomment.split('\n'): + if wrapwidth > 0 and len(tcomment) > wrapwidth-2: + ret += textwrap.wrap(tcomment, wrapwidth, + initial_indent='# ', + subsequent_indent='# ', + break_long_words=False) + else: + ret.append('# %s' % tcomment) + # occurrences (with text wrapping as xgettext does) + if self.occurrences: + filelist = [] + for fpath, lineno in self.occurrences: + if lineno: + filelist.append('%s:%s' % (fpath, lineno)) + else: + filelist.append(fpath) + filestr = ' '.join(filelist) + if wrapwidth > 0 and len(filestr)+3 > wrapwidth: + # XXX textwrap split words that contain hyphen, this is not + # what we want for filenames, so the dirty hack is to + # temporally replace hyphens with a char that a file cannot + # contain, like "*" + lines = textwrap.wrap(filestr.replace('-', '*'), + wrapwidth, + initial_indent='#: ', + subsequent_indent='#: ', + break_long_words=False) + # end of the replace hack + for line in lines: + ret.append(line.replace('*', '-')) + else: + ret.append('#: '+filestr) + # flags + if self.flags: + flags = [] + for flag in self.flags: + flags.append(flag) + ret.append('#, %s' % ', '.join(flags)) + ret.append(_BaseEntry.__str__(self)) + + return '\n'.join(ret) + + def __cmp__(self, other): + ''' + Called by comparison operations if rich comparison is not defined. + + **Tests**: + >>> a = POEntry(msgid='a', occurrences=[('b.py', 1), ('b.py', 3)]) + >>> b = POEntry(msgid='b', occurrences=[('b.py', 1), ('b.py', 3)]) + >>> c1 = POEntry(msgid='c1', occurrences=[('a.py', 1), ('b.py', 1)]) + >>> c2 = POEntry(msgid='c2', occurrences=[('a.py', 1), ('a.py', 3)]) + >>> po = POFile() + >>> po.append(a) + >>> po.append(b) + >>> po.append(c1) + >>> po.append(c2) + >>> po.sort() + >>> print(po) + # + msgid "" + msgstr "" + + #: a.py:1 a.py:3 + msgid "c2" + msgstr "" + + #: a.py:1 b.py:1 + msgid "c1" + msgstr "" + + #: b.py:1 b.py:3 + msgid "a" + msgstr "" + + #: b.py:1 b.py:3 + msgid "b" + msgstr "" + + ''' + def compare_occurrences(a, b): + """ + Compare an entry occurrence with another one. + """ + if a[0] != b[0]: + return a[0] < b[0] + if a[1] != b[1]: + return a[1] < b[1] + return 0 + + # First: Obsolete test + if self.obsolete != other.obsolete: + if self.obsolete: + return -1 + else: + return 1 + # Work on a copy to protect original + occ1 = self.occurrences[:] + occ2 = other.occurrences[:] + # Sorting using compare method + occ1.sort(compare_occurrences) + occ2.sort(compare_occurrences) + # Comparing sorted occurrences + pos = 0 + for entry1 in occ1: + try: + entry2 = occ2[pos] + except IndexError: + return 1 + pos = pos + 1 + if entry1[0] != entry2[0]: + if entry1[0] > entry2[0]: + return 1 + else: + return -1 + if entry1[1] != entry2[1]: + if entry1[1] > entry2[1]: + return 1 + else: + return -1 + # Finally: Compare message ID + if self.msgid > other.msgid: return 1 + else: return -1 + + def translated(self): + """ + Return True if the entry has been translated or False. + """ + if self.obsolete or 'fuzzy' in self.flags: + return False + if self.msgstr != '': + return True + if self.msgstr_plural: + for pos in self.msgstr_plural: + if self.msgstr_plural[pos] == '': + return False + return True + return False + + def merge(self, other): + """ + Merge the current entry with the given pot entry. + """ + self.msgid = other.msgid + self.occurrences = other.occurrences + self.comment = other.comment + self.flags = other.flags + self.msgid_plural = other.msgid_plural + if other.msgstr_plural: + for pos in other.msgstr_plural: + try: + # keep existing translation at pos if any + self.msgstr_plural[pos] + except KeyError: + self.msgstr_plural[pos] = '' + +# }}} +# class MOEntry {{{ + +class MOEntry(_BaseEntry): + """ + Represents a mo file entry. + + **Examples**: + + >>> entry = MOEntry() + >>> entry.msgid = 'translate me !' + >>> entry.msgstr = 'traduisez moi !' + >>> print(entry) + msgid "translate me !" + msgstr "traduisez moi !" + + """ + + def __str__(self, wrapwidth=78): + """ + Return the string representation of the entry. + """ + return _BaseEntry.__str__(self, wrapwidth) + +# }}} +# class _POFileParser {{{ + +class _POFileParser(object): + """ + A finite state machine to parse efficiently and correctly po + file format. + """ + + def __init__(self, fpath, enc=default_encoding): + """ + Constructor. + + **Keyword argument**: + - *fpath*: string, path to the po file + """ + try: + self.fhandle = codecs.open(fpath, 'rU', enc) + except LookupError: + enc = default_encoding + self.fhandle = codecs.open(fpath, 'rU', enc) + self.instance = POFile(fpath=fpath, encoding=enc) + self.transitions = {} + self.current_entry = POEntry() + self.current_state = 'ST' + self.current_token = None + # two memo flags used in handlers + self.msgstr_index = 0 + self.entry_obsolete = 0 + # Configure the state machine, by adding transitions. + # Signification of symbols: + # * ST: Beginning of the file (start) + # * HE: Header + # * TC: a translation comment + # * GC: a generated comment + # * OC: a file/line occurence + # * FL: a flags line + # * CT: a message context + # * MI: a msgid + # * MP: a msgid plural + # * MS: a msgstr + # * MX: a msgstr plural + # * MC: a msgid or msgstr continuation line + all = ['ST', 'HE', 'GC', 'OC', 'FL', 'CT', 'TC', 'MS', 'MP', 'MX', 'MI'] + + self.add('TC', ['ST', 'HE'], 'HE') + self.add('TC', ['GC', 'OC', 'FL', 'TC', 'MS', 'MP', 'MX', 'MI'], 'TC') + self.add('GC', all, 'GC') + self.add('OC', all, 'OC') + self.add('FL', all, 'FL') + self.add('CT', ['ST', 'HE', 'GC', 'OC', 'FL', 'TC', 'MS', 'MX'], 'CT') + self.add('MI', ['ST', 'HE', 'GC', 'OC', 'FL', 'CT', 'TC', 'MS', 'MX'], + 'MI') + self.add('MP', ['TC', 'GC', 'MI'], 'MP') + self.add('MS', ['MI', 'MP', 'TC'], 'MS') + self.add('MX', ['MI', 'MX', 'MP', 'TC'], 'MX') + self.add('MC', ['CT', 'MI', 'MP', 'MS', 'MX'], 'MC') + + def parse(self): + """ + Run the state machine, parse the file line by line and call process() + with the current matched symbol. + """ + i, lastlen = 1, 0 + for line in self.fhandle: + line = line.strip() + if line == '': + i = i+1 + continue + if line[:3] == '#~ ': + line = line[3:] + self.entry_obsolete = 1 + else: + self.entry_obsolete = 0 + self.current_token = line + if line[:2] == '#:': + # we are on a occurrences line + self.process('OC', i) + elif line[:9] == 'msgctxt "': + # we are on a msgctxt + self.process('CT', i) + elif line[:7] == 'msgid "': + # we are on a msgid + self.process('MI', i) + elif line[:8] == 'msgstr "': + # we are on a msgstr + self.process('MS', i) + elif line[:1] == '"': + # we are on a continuation line or some metadata + self.process('MC', i) + elif line[:14] == 'msgid_plural "': + # we are on a msgid plural + self.process('MP', i) + elif line[:7] == 'msgstr[': + # we are on a msgstr plural + self.process('MX', i) + elif line[:3] == '#, ': + # we are on a flags line + self.process('FL', i) + elif line[:2] == '# ' or line == '#': + if line == '#': line = line + ' ' + # we are on a translator comment line + self.process('TC', i) + elif line[:2] == '#.': + # we are on a generated comment line + self.process('GC', i) + i = i+1 + + if self.current_entry: + # since entries are added when another entry is found, we must add + # the last entry here (only if there are lines) + self.instance.append(self.current_entry) + # before returning the instance, check if there's metadata and if + # so extract it in a dict + firstentry = self.instance[0] + if firstentry.msgid == '': # metadata found + # remove the entry + firstentry = self.instance.pop(0) + self.instance.metadata_is_fuzzy = firstentry.flags + key = None + for msg in firstentry.msgstr.splitlines(): + try: + key, val = msg.split(':', 1) + self.instance.metadata[key] = val.strip() + except: + if key is not None: + self.instance.metadata[key] += '\n'+ msg.strip() + # close opened file + self.fhandle.close() + return self.instance + + def add(self, symbol, states, next_state): + """ + Add a transition to the state machine. + Keywords arguments: + + symbol -- string, the matched token (two chars symbol) + states -- list, a list of states (two chars symbols) + next_state -- the next state the fsm will have after the action + """ + for state in states: + action = getattr(self, 'handle_%s' % next_state.lower()) + self.transitions[(symbol, state)] = (action, next_state) + + def process(self, symbol, linenum): + """ + Process the transition corresponding to the current state and the + symbol provided. + + Keywords arguments: + symbol -- string, the matched token (two chars symbol) + linenum -- integer, the current line number of the parsed file + """ + try: + (action, state) = self.transitions[(symbol, self.current_state)] + if action(): + self.current_state = state + except Exception, exc: + raise + raise IOError('Syntax error in po file (line %s)' % linenum) + + # state handlers + + def handle_he(self): + """Handle a header comment.""" + if self.instance.header != '': + self.instance.header += '\n' + self.instance.header += self.current_token[2:] + return 1 + + def handle_tc(self): + """Handle a translator comment.""" + if self.current_state in ['MC', 'MS', 'MX']: + self.instance.append(self.current_entry) + self.current_entry = POEntry() + if self.current_entry.tcomment != '': + self.current_entry.tcomment += '\n' + self.current_entry.tcomment += self.current_token[2:] + return True + + def handle_gc(self): + """Handle a generated comment.""" + if self.current_state in ['MC', 'MS', 'MX']: + self.instance.append(self.current_entry) + self.current_entry = POEntry() + if self.current_entry.comment != '': + self.current_entry.comment += '\n' + self.current_entry.comment += self.current_token[3:] + return True + + def handle_oc(self): + """Handle a file:num occurence.""" + if self.current_state in ['MC', 'MS', 'MX']: + self.instance.append(self.current_entry) + self.current_entry = POEntry() + occurrences = self.current_token[3:].split() + for occurrence in occurrences: + if occurrence != '': + try: + fil, line = occurrence.split(':') + if not line.isdigit(): + fil = fil + line + line = '' + self.current_entry.occurrences.append((fil, line)) + except: + self.current_entry.occurrences.append((occurrence, '')) + return True + + def handle_fl(self): + """Handle a flags line.""" + if self.current_state in ['MC', 'MS', 'MX']: + self.instance.append(self.current_entry) + self.current_entry = POEntry() + self.current_entry.flags += self.current_token[3:].split(', ') + return True + + def handle_ct(self): + """Handle a msgctxt.""" + if self.current_state in ['MC', 'MS', 'MX']: + self.instance.append(self.current_entry) + self.current_entry = POEntry() + self.current_entry.msgctxt = unescape(self.current_token[9:-1]) + return True + + def handle_mi(self): + """Handle a msgid.""" + if self.current_state in ['MC', 'MS', 'MX']: + self.instance.append(self.current_entry) + self.current_entry = POEntry() + self.current_entry.obsolete = self.entry_obsolete + self.current_entry.msgid = unescape(self.current_token[7:-1]) + return True + + def handle_mp(self): + """Handle a msgid plural.""" + self.current_entry.msgid_plural = unescape(self.current_token[14:-1]) + return True + + def handle_ms(self): + """Handle a msgstr.""" + self.current_entry.msgstr = unescape(self.current_token[8:-1]) + return True + + def handle_mx(self): + """Handle a msgstr plural.""" + index, value = self.current_token[7], self.current_token[11:-1] + self.current_entry.msgstr_plural[index] = unescape(value) + self.msgstr_index = index + return True + + def handle_mc(self): + """Handle a msgid or msgstr continuation line.""" + if self.current_state == 'CT': + self.current_entry.msgctxt += unescape(self.current_token[1:-1]) + elif self.current_state == 'MI': + self.current_entry.msgid += unescape(self.current_token[1:-1]) + elif self.current_state == 'MP': + self.current_entry.msgid_plural += \ + unescape(self.current_token[1:-1]) + elif self.current_state == 'MS': + self.current_entry.msgstr += unescape(self.current_token[1:-1]) + elif self.current_state == 'MX': + msgstr = self.current_entry.msgstr_plural[self.msgstr_index] +\ + unescape(self.current_token[1:-1]) + self.current_entry.msgstr_plural[self.msgstr_index] = msgstr + # don't change the current state + return False + +# }}} +# class _MOFileParser {{{ + +class _MOFileParser(object): + """ + A class to parse binary mo files. + """ + BIG_ENDIAN = 0xde120495 + LITTLE_ENDIAN = 0x950412de + + def __init__(self, fpath, enc=default_encoding): + """_MOFileParser constructor.""" + self.fhandle = open(fpath, 'rb') + self.instance = MOFile(fpath=fpath, encoding=enc) + + def parse_magicnumber(self): + """ + Parse the magic number and raise an exception if not valid. + """ + + def parse(self): + """ + Build the instance with the file handle provided in the + constructor. + """ + magic_number = self._readbinary('. + It returns a tuple or a mixed value if the tuple length is 1. + """ + bytes = self.fhandle.read(numbytes) + tup = struct.unpack(fmt, bytes) + if len(tup) == 1: + return tup[0] + return tup + +# }}} +# __main__ {{{ + +if __name__ == '__main__': + """ + **Main function**:: + - to **test** the module just run: *python polib.py [-v]* + - to **profile** the module: *python polib.py -p * + """ + import sys + if len(sys.argv) > 2 and sys.argv[1] == '-p': + def test(f): + if f.endswith('po'): + p = pofile(f) + else: + p = mofile(f) + s = str(p) + import profile + profile.run('test("'+sys.argv[2]+'")') + else: + import doctest + doctest.testmod() + +# }}} diff --git a/pyweb/rosetta/poutil.py b/pyweb/rosetta/poutil.py new file mode 100644 index 0000000..6a070fa --- /dev/null +++ b/pyweb/rosetta/poutil.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +import re, string, sys, os +from django.conf import settings +try: + set +except NameError: + from sets import Set as set # Python 2.3 fallback + +def find_pos(lang, include_djangos = False, include_rosetta = False): + """ + scans a couple possible repositories of gettext catalogs for the given + language code + + """ + + paths = [] + + # project/locale + parts = settings.SETTINGS_MODULE.split('.') + project = __import__(parts[0], {}, {}, []) + paths.append(os.path.join(os.path.dirname(project.__file__), 'locale')) + + # django/locale + if include_djangos: + paths.append(os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')) + + # settings + for localepath in settings.LOCALE_PATHS: + if os.path.isdir(localepath): + paths.append(localepath) + + # project/app/locale + for appname in settings.INSTALLED_APPS: + if 'rosetta' == appname and include_rosetta == False: + continue + + p = appname.rfind('.') + if p >= 0: + app = getattr(__import__(appname[:p], {}, {}, [appname[p+1:]]), appname[p+1:]) + else: + app = __import__(appname, {}, {}, []) + + apppath = os.path.join(os.path.dirname(app.__file__), 'locale') + + if os.path.isdir(apppath): + paths.append(apppath) + + ret = set() + rx=re.compile(r'(\w+)/../\1') + langs = (lang,) + if u'-' in lang: + _l,_c = map(lambda x:x.lower(),lang.split(u'-')) + langs += (u'%s_%s' %(_l, _c), u'%s_%s' %(_l, _c.upper()), ) + elif u'_' in lang: + _l,_c = map(lambda x:x.lower(),lang.split(u'_')) + langs += (u'%s-%s' %(_l, _c), u'%s-%s' %(_l, _c.upper()), ) + + for path in paths: + for lang_ in langs: + dirname = rx.sub(r'\1', '%s/%s/LC_MESSAGES/' %(path,lang_)) + for fn in ('django.po','djangojs.po',): + if os.path.isfile(dirname+fn): + ret.add(os.path.abspath(dirname+fn)) + return list(ret) + +def pagination_range(first,last,current): + r = [] + + r.append(first) + if first + 1 < last: r.append(first+1) + + if current -2 > first and current -2 < last: r.append(current-2) + if current -1 > first and current -1 < last: r.append(current-1) + if current > first and current < last: r.append(current) + if current + 1 < last and current+1 > first: r.append(current+1) + if current + 2 < last and current+2 > first: r.append(current+2) + + if last-1 > first: r.append(last-1) + r.append(last) + + r = list(set(r)) + r.sort() + prev = 10000 + for e in r[:]: + if prev + 1 < e: + try: + r.insert(r.index(e), '...') + except ValueError: + pass + prev = e + return r diff --git a/pyweb/rosetta/templates/rosetta/base.html b/pyweb/rosetta/templates/rosetta/base.html new file mode 100644 index 0000000..292ceb8 --- /dev/null +++ b/pyweb/rosetta/templates/rosetta/base.html @@ -0,0 +1,41 @@ + + + + + + + + + + + + Rosetta - {% block pagetitle %}{% endblock %} + + +
+ + +
+ {% block main %}{% endblock %} +
+ +
+ + diff --git a/pyweb/rosetta/templates/rosetta/css/rosetta.css b/pyweb/rosetta/templates/rosetta/css/rosetta.css new file mode 100644 index 0000000..11d6f91 --- /dev/null +++ b/pyweb/rosetta/templates/rosetta/css/rosetta.css @@ -0,0 +1,28 @@ +#user-tools p span { margin-left:2em; } +table{width:100%;} +td.translation label {font-size: 95%;} +td.translation textarea, td.original { font-size:110%;} +td.translation,td.original {width:30%;} +td.original .plural-container { position:relative} +td.translation textarea{ width:98.5%; min-height:25px; margin:2px 0; } +.rtl td.translation textarea { direction: rtl;} +.plural span {display:block; margin:2px 0; position:absolute} +td.location code,td.location a { font-size:95%; display:block;} +td.location code.hide { display:none;} +.submit-row {margin-bottom:0;} +li.nobubble,li.nobubble:hover { background-image:none;} +.object-tools li.active, .object-tools li.active a { color:yellow;} +p.paginator input { float:right;} +p.paginator span.space { margin: 0 0.5em;} +.paginator {text-align:left; border:none; background:transparent; } +.paginator strong { margin-left:1em;} +th.r,td.r {text-align:right;} +th.c,td.c {text-align: center;} +td.original code {font-size:90%; padding: 0 1px; } +tr.row2 td.original code {background-color:#FFB2A5; padding: 0 0.3em;} +tr.row1 td.original code {background-color:#FFB2A5;} +.alert { font-weight:bold;padding:4px 5px 4px 25px; margin-left:1em; color: red; background:transparent url({{ADMIN_MEDIA_PREFIX}}img/admin/icon_alert.gif) 5px .3em no-repeat; } +#footer { clear:both; color:#999; font-size:9px; margin:0 6px; text-align:left;} +#changelist table tbody td:first-child, #changelist table thead th:first-child {text-align: left;} +td.hint {color: #777;} +div.module {margin-bottom: 20px;} diff --git a/pyweb/rosetta/templates/rosetta/js/rosetta.js b/pyweb/rosetta/templates/rosetta/js/rosetta.js new file mode 100644 index 0000000..ba6bcd4 --- /dev/null +++ b/pyweb/rosetta/templates/rosetta/js/rosetta.js @@ -0,0 +1,57 @@ +google.setOnLoadCallback(function() { + $('.location a').show().toggle(function() { + $('.hide', $(this).parent()).show(); + }, function() { + $('.hide', $(this).parent()).hide(); + }); +{% if ENABLE_TRANSLATION_SUGGESTIONS %} + $('a.suggest').click(function() { + var a=$(this), str=a.html(); orig=$('.original', a.parents('tr')).html(),trans=$('textarea',a.parent()); + orig = unescape(orig).replace(//g,'\n').replace(//g,'').replace(/<\/code>/g,'').replace(/>/g,'>').replace(/</g,'<'); + a.attr('class','suggesting').html('...'); + google.language.translate(orig, "en", '{{rosetta_i18n_lang_code}}', function(result) { + if (!result.error) { + trans.val(unescape(result.translation).replace(/'/g,'\'').replace(/"/g,'"').replace(/%\s+(\([^\)]+\))\s*s/g,' %$1s ')); + a.hide(); + } else { + a.hide().before($(''+result.error.message+'')); + } + }); + return false; + }); +{% endif %} + $('td.plural').each(function(i) { + var td = $(this), trY = parseInt(td.closest('tr').offset().top); + $('textarea', $(this).closest('tr')).each(function(j) { + var textareaY= parseInt($(this).offset().top) - trY; + $($('.part',td).get(j)).css('top',textareaY + 'px'); + }); + }); + + $('.translation textarea').blur(function() { + if($(this).val()) { + $('.alert', $(this).parents('tr')).remove(); + var RX = /%(?:\([^\s\)]*\))?[sdf]/g, + origs=$('.original', $(this).parents('tr')).html().match(RX), + trads=$(this).val().match(RX), + error = $('Unmatched variables'); + if (origs && trads) { + for (var i = trads.length; i--;){ + var key = trads[i]; + if (-1 == $.inArray(key, origs)) { + $(this).before(error) + return false; + } + } + return true; + } else { + if (!(origs === null && trads === null)) { + $(this).before(error); + return false; + } + } + return true; + } + }); + +}); diff --git a/pyweb/rosetta/templates/rosetta/languages.html b/pyweb/rosetta/templates/rosetta/languages.html new file mode 100644 index 0000000..257f8b3 --- /dev/null +++ b/pyweb/rosetta/templates/rosetta/languages.html @@ -0,0 +1,45 @@ +{% extends "rosetta/base.html" %} +{% load i18n %} +{% block breadcumbs %}{% trans "Home" %} › {% trans "Language selection" %}{% endblock %} +{% block pagetitle %}{% trans "Language selection" %}{% endblock %} +{% block main %} + {% if has_pos %} + {% for lid,language,pos in languages %} + {% if pos %} +
+

{{language}}

+ + + + + + + + + + + + + + {% for app,path,po in pos %} + + + + + + + + + + {% endfor %} + +
{% trans "Application" %}{% trans "Progress"%}{% trans "Messages" %}{% trans "Translated" %}{% trans "Fuzzy"%}{% trans "Obsolete"%}{% trans "File" %}
{{ app|title }}{{po.percent_translated|floatformat:2}}%{{po|length}}{{po.translated_entries|length}}{{po.fuzzy_entries|length}}{{po.obsolete_entries|length}}{{ path }}
+
+ {% endif %} + {% endfor %} + {% else %} +

{% trans "Nothing to translate!" %}

+

{% trans "You haven't specified any languages in your settings file, or haven't yet generated a batch of translation catalogs." %}

+

{% blocktrans with "http://docs.djangoproject.com/en/dev/topics/i18n/#topics-i18n" as i18n_doc_link %}Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project.{% endblocktrans %}

+ {% endif %} +{% endblock %} diff --git a/pyweb/rosetta/templates/rosetta/pofile.html b/pyweb/rosetta/templates/rosetta/pofile.html new file mode 100644 index 0000000..8433d62 --- /dev/null +++ b/pyweb/rosetta/templates/rosetta/pofile.html @@ -0,0 +1,125 @@ +{% extends "rosetta/base.html" %} +{% load rosetta i18n %} + +{% block header %} + {{block.super}} + +{% endblock %} +{% block breadcumbs %} + {% trans "Home" %} › + {{ rosetta_i18n_lang_name }} › + {{ rosetta_i18n_app|title }} › + {% blocktrans with rosetta_i18n_pofile.percent_translated|floatformat:2 as percent_translated %}Progress: {{ percent_translated }}%{% endblocktrans %} + {% if not rosetta_i18n_write %}{% trans "File is read-only: download the file when done editing!" %}{% endif %} +{% endblock %} +{% block pagetitle %}{% trans "English" %} - {{rosetta_i18n_lang_name}} ({{ rosetta_i18n_pofile.percent_translated|floatformat:0 }}%){% endblock %} +{% block main %} +

{% blocktrans %}Translate into {{rosetta_i18n_lang_name}}{% endblocktrans %}

+ + +
+
+ +
+ +
+ + + + {% rosetta_csrf_token %} + + {% if main_language %}{% endif %} + + + + + + + {% for message in messages %} + + {% if message.msgid_plural %} + + + {% else %} + + {% if main_language %}{% endif %} + + {% endif %} + + + + {% endfor %} + +
{% trans "Original" %}{{ main_language }}{{ rosetta_i18n_lang_name }}{% trans "Fuzzy" %}{% trans "Occurrences(s)" %}
+
+ {{message.msgid|format_message|linebreaksbr}} + {{message.msgid_plural|format_message|linebreaksbr}} +
+
+ {% for k, msgstr in message.msgstr_plural.items|dictsort:"0" %} + + + {% endfor %} + {{ message.msgid|format_message|linebreaksbr }}{{ message.main_lang|format_message|linebreaksbr }} + + {% if ENABLE_TRANSLATION_SUGGESTIONS %}{% trans "suggest" %}{% endif %} + + + + {% for fn,lineno in message.occurrences %} + {{ fn }}:{{lineno}} + {% endfor %} + {% if message.occurrences|length|gt:"3" %} + … ({% blocktrans count message.occurrences|length|minus:"3" as more_count %}{{more_count}} more{% plural %}{{more_count}} more{% endblocktrans %}) + {% endif %} +
+
+

+ {% if query %} + + {% endif %} + + + + {% if needs_pagination %} + {% trans "Skip to page:" %} + {% for i in page_range %} + {% ifequal i '...' %} + {{ i }} + {% else %} + {% ifequal i page %} + {{i}} + {% else %} + {{i}} + {% endifequal %} + {% endifequal %} + {% endfor %} + {% else %} + {% trans "Displaying:" %} + {% endif %} + {% blocktrans count rosetta_i18n_pofile|length as message_number and paginator.object_list|length as hits %}{{hits}}/{{message_number}} message{% plural %}{{hits}}/{{message_number}} messages{% endblocktrans %} + + +

+
+
+
+{% endblock %} diff --git a/pyweb/rosetta/templatetags/__init__.py b/pyweb/rosetta/templatetags/__init__.py new file mode 100644 index 0000000..76f7515 --- /dev/null +++ b/pyweb/rosetta/templatetags/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + diff --git a/pyweb/rosetta/templatetags/rosetta.py b/pyweb/rosetta/templatetags/rosetta.py new file mode 100644 index 0000000..3d3a6e5 --- /dev/null +++ b/pyweb/rosetta/templatetags/rosetta.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +from django import template +from django.utils.safestring import mark_safe +from django.utils.html import escape +import re +from django.template import Node + +register = template.Library() +rx = re.compile(r'(%(\([^\s\)]*\))?[sd])') + +def format_message(message): + return mark_safe(rx.sub('\\1', escape(message).replace(r'\n','
\n'))) +format_message=register.filter(format_message) + + +def lines_count(message): + return 1 + sum([len(line)/50 for line in message.split('\n')]) +lines_count=register.filter(lines_count) + +def mult(a,b): + return int(a)*int(b) +mult=register.filter(mult) + +def minus(a,b): + try: + return int(a) - int(b) + except: + return 0 +minus=register.filter(minus) + + +def gt(a,b): + try: + return int(a) > int(b) + except: + return False +gt=register.filter(gt) + + +def is_fuzzy(message): + return message and hasattr(message, 'flags') and 'fuzzy' in message.flags +is_fuzzy = register.filter(is_fuzzy) + +class RosettaCsrfTokenPlaceholder(Node): + def render(self, context): + return mark_safe(u"") + +def rosetta_csrf_token(parser, token): + try: + from django.template.defaulttags import csrf_token + return csrf_token(parser,token) + except ImportError: + return RosettaCsrfTokenPlaceholder() +rosetta_csrf_token=register.tag(rosetta_csrf_token) diff --git a/pyweb/rosetta/urls.py b/pyweb/rosetta/urls.py new file mode 100644 index 0000000..4c6fa9e --- /dev/null +++ b/pyweb/rosetta/urls.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +from django.conf.urls.defaults import * +from django.views.generic.simple import direct_to_template +urlpatterns = patterns('rosetta.views', + url(r'^$', 'home', name='rosetta-home'), + url(r'^pick/$', 'list_languages', name='rosetta-pick-file'), + url(r'^download/$', 'download_file', name='rosetta-download-file'), + url(r'^select/(?P[\w\-]+)/(?P\d+)/$','lang_sel', name='rosetta-language-selection'), +) diff --git a/pyweb/rosetta/views.py b/pyweb/rosetta/views.py new file mode 100644 index 0000000..dad7329 --- /dev/null +++ b/pyweb/rosetta/views.py @@ -0,0 +1,322 @@ +# -*- coding: utf-8 -*- + +""" + * Copyright (C) 2010, mbonetti + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. +""" + +from django.conf import settings +from django.contrib.auth.decorators import user_passes_test +from django.core.paginator import Paginator, InvalidPage +from django.core.urlresolvers import reverse, resolve, Resolver404 +from django.http import Http404, HttpResponseRedirect, HttpResponse +from django.shortcuts import render_to_response +from django.utils.encoding import smart_unicode, force_unicode, iri_to_uri +from django.utils.translation import ugettext_lazy as _ +from django.views.decorators.cache import never_cache +from rosetta.polib import pofile +from rosetta.poutil import find_pos, pagination_range +from rosetta.conf import settings as rosetta_settings +import re, os, rosetta, datetime, unicodedata +from django.template import RequestContext + + +try: + resolve(settings.LOGIN_URL) +except Resolver404: + try: + resolve('/admin/') + except Resolver404: + raise Exception('Rosetta cannot log you in!\nYou must define a LOGIN_URL in your settings if you don\'t run the Django admin site at a standard URL.') + else: + LOGIN_URL = '/admin/' +else: + LOGIN_URL = settings.LOGIN_URL + + +def home(request): + """ + Displays a list of messages to be translated + """ + + def fix_nls(in_,out_): + """Fixes submitted translations by filtering carriage returns and pairing + newlines at the begging and end of the translated string with the original + """ + if 0 == len(in_) or 0 == len(out_): + return out_ + + if "\r" in out_ and "\r" not in in_: + out_=out_.replace("\r",'') + + if "\n" == in_[0] and "\n" != out_[0]: + out_ = "\n" + out_ + elif "\n" != in_[0] and "\n" == out_[0]: + out_ = out_.lstrip() + if "\n" == in_[-1] and "\n" != out_[-1]: + out_ = out_ + "\n" + elif "\n" != in_[-1] and "\n" == out_[-1]: + out_ = out_.rstrip() + return out_ + + version = rosetta.get_version(True) + if 'rosetta_i18n_fn' in request.session: + rosetta_i18n_fn=request.session.get('rosetta_i18n_fn') + rosetta_i18n_app = get_app_name(rosetta_i18n_fn) + rosetta_i18n_pofile = request.session.get('rosetta_i18n_pofile') + rosetta_i18n_lang_code = request.session['rosetta_i18n_lang_code'] + rosetta_i18n_lang_bidi = (rosetta_i18n_lang_code in settings.LANGUAGES_BIDI) + rosetta_i18n_write = request.session.get('rosetta_i18n_write', True) + + if 'filter' in request.GET: + if request.GET.get('filter') in ('untranslated', 'translated', 'fuzzy', 'all'): + filter_ = request.GET.get('filter') + request.session['rosetta_i18n_filter'] = filter_ + return HttpResponseRedirect(reverse('rosetta-home')) + + rosetta_i18n_filter = request.session.get('rosetta_i18n_filter', 'all') + + if '_next' in request.POST: + rx=re.compile(r'^m_([0-9]+)') + rx_plural=re.compile(r'^m_([0-9]+)_([0-9]+)') + file_change = False + for k in request.POST.keys(): + if rx_plural.match(k): + id=int(rx_plural.match(k).groups()[0]) + idx=int(rx_plural.match(k).groups()[1]) + rosetta_i18n_pofile[id].msgstr_plural[str(idx)] = fix_nls(rosetta_i18n_pofile[id].msgid_plural[idx], request.POST.get(k)) + file_change = True + elif rx.match(k): + id=int(rx.match(k).groups()[0]) + rosetta_i18n_pofile[id].msgstr = fix_nls(rosetta_i18n_pofile[id].msgid, request.POST.get(k)) + file_change = True + + if file_change and 'fuzzy' in rosetta_i18n_pofile[id].flags and not request.POST.get('f_%d' %id, False): + rosetta_i18n_pofile[id].flags.remove('fuzzy') + elif file_change and 'fuzzy' not in rosetta_i18n_pofile[id].flags and request.POST.get('f_%d' %id, False): + rosetta_i18n_pofile[id].flags.append('fuzzy') + + if file_change and rosetta_i18n_write: + + try: + rosetta_i18n_pofile.metadata['Last-Translator'] = unicodedata.normalize('NFKD', u"%s %s <%s>" %(request.user.first_name,request.user.last_name,request.user.email)).encode('ascii', 'ignore') + rosetta_i18n_pofile.metadata['X-Translated-Using'] = u"django-rosetta %s" % rosetta.get_version(False) + rosetta_i18n_pofile.metadata['PO-Revision-Date'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M%z') + except UnicodeDecodeError: + pass + try: + rosetta_i18n_pofile.save() + rosetta_i18n_pofile.save_as_mofile(rosetta_i18n_fn.replace('.po','.mo')) + + # Try auto-reloading via the WSGI daemon mode reload mechanism + if rosetta_settings.WSGI_AUTO_RELOAD and \ + request.environ.has_key('mod_wsgi.process_group') and \ + request.environ.get('mod_wsgi.process_group',None) and \ + request.environ.has_key('SCRIPT_FILENAME') and \ + int(request.environ.get('mod_wsgi.script_reloading', '0')): + try: + os.utime(request.environ.get('SCRIPT_FILENAME'), None) + except OSError: + pass + + except: + request.session['rosetta_i18n_write'] = False + + request.session['rosetta_i18n_pofile']=rosetta_i18n_pofile + + # Retain query arguments + query_arg = '' + if 'query' in request.REQUEST: + query_arg = '?query=%s' %request.REQUEST.get('query') + if 'page' in request.GET: + if query_arg: + query_arg = query_arg + '&' + else: + query_arg = '?' + query_arg = query_arg + 'page=%d' % int(request.GET.get('page')) + + + return HttpResponseRedirect(reverse('rosetta-home') + iri_to_uri(query_arg)) + + + rosetta_i18n_lang_name = _(request.session.get('rosetta_i18n_lang_name')) + rosetta_i18n_lang_code = request.session.get('rosetta_i18n_lang_code') + + if 'query' in request.REQUEST and request.REQUEST.get('query','').strip(): + query=request.REQUEST.get('query').strip() + rx=re.compile(query, re.IGNORECASE) + paginator = Paginator([e for e in rosetta_i18n_pofile if rx.search(smart_unicode(e.msgstr)+smart_unicode(e.msgid)+u''.join([o[0] for o in e.occurrences]))], rosetta_settings.MESSAGES_PER_PAGE) + else: + if rosetta_i18n_filter == 'untranslated': + paginator = Paginator(rosetta_i18n_pofile.untranslated_entries(), rosetta_settings.MESSAGES_PER_PAGE) + elif rosetta_i18n_filter == 'translated': + paginator = Paginator(rosetta_i18n_pofile.translated_entries(), rosetta_settings.MESSAGES_PER_PAGE) + elif rosetta_i18n_filter == 'fuzzy': + paginator = Paginator(rosetta_i18n_pofile.fuzzy_entries(), rosetta_settings.MESSAGES_PER_PAGE) + else: + paginator = Paginator([e for e in rosetta_i18n_pofile if not e.obsolete], rosetta_settings.MESSAGES_PER_PAGE) + + if 'page' in request.GET and int(request.GET.get('page')) <= paginator.num_pages and int(request.GET.get('page')) > 0: + page = int(request.GET.get('page')) + else: + page = 1 + messages = paginator.page(page).object_list + if rosetta_settings.MAIN_LANGUAGE and rosetta_settings.MAIN_LANGUAGE != rosetta_i18n_lang_code: + + main_language = None + for language in settings.LANGUAGES: + if language[0] == rosetta_settings.MAIN_LANGUAGE: + main_language = _(language[1]) + break + + fl = ("/%s/" % rosetta_settings.MAIN_LANGUAGE).join(rosetta_i18n_fn.split("/%s/" % rosetta_i18n_lang_code)) + po = pofile(fl) + + main_messages = [] + for message in messages: + message.main_lang = po.find(message.msgid).msgstr + + needs_pagination = paginator.num_pages > 1 + if needs_pagination: + if paginator.num_pages >= 10: + page_range = pagination_range(1, paginator.num_pages, page) + else: + page_range = range(1,1+paginator.num_pages) + ADMIN_MEDIA_PREFIX = settings.ADMIN_MEDIA_PREFIX + ENABLE_TRANSLATION_SUGGESTIONS = rosetta_settings.ENABLE_TRANSLATION_SUGGESTIONS + + return render_to_response('rosetta/pofile.html', locals(), context_instance=RequestContext(request)) + + + else: + return list_languages(request) +home=user_passes_test(lambda user:can_translate(user),LOGIN_URL)(home) +home=never_cache(home) + + +def download_file(request): + import zipfile, os + from StringIO import StringIO + # original filename + rosetta_i18n_fn=request.session.get('rosetta_i18n_fn', None) + # in-session modified catalog + rosetta_i18n_pofile = request.session.get('rosetta_i18n_pofile', None) + # language code + rosetta_i18n_lang_code = request.session.get('rosetta_i18n_lang_code', None) + + if not rosetta_i18n_lang_code or not rosetta_i18n_pofile or not rosetta_i18n_fn: + return HttpResponseRedirect(reverse('rosetta-home')) + try: + if len(rosetta_i18n_fn.split('/')) >= 5: + offered_fn = '_'.join(rosetta_i18n_fn.split('/')[-5:]) + else: + offered_fn = rosetta_i18n_fn.split('/')[-1] + po_fn = str(rosetta_i18n_fn.split('/')[-1]) + mo_fn = str(po_fn.replace('.po','.mo')) # not so smart, huh + zipdata = StringIO() + zipf = zipfile.ZipFile(zipdata, mode="w") + zipf.writestr(po_fn, str(rosetta_i18n_pofile)) + zipf.writestr(mo_fn, rosetta_i18n_pofile.to_binary()) + zipf.close() + zipdata.seek(0) + + response = HttpResponse(zipdata.read()) + response['Content-Disposition'] = 'attachment; filename=%s.%s.zip' %(offered_fn,rosetta_i18n_lang_code) + response['Content-Type'] = 'application/x-zip' + return response + except Exception, e: + return HttpResponseRedirect(reverse('rosetta-home')) + +download_file=user_passes_test(lambda user:can_translate(user),LOGIN_URL)(download_file) +download_file=never_cache(download_file) + + + +def list_languages(request): + """ + Lists the languages for the current project, the gettext catalog files + that can be translated and their translation progress + """ + languages = [] + do_django = 'django' in request.GET + do_rosetta = 'rosetta' in request.GET + has_pos = False + for language in settings.LANGUAGES: + pos = find_pos(language[0],include_djangos=do_django,include_rosetta=do_rosetta) + has_pos = has_pos or len(pos) + languages.append( + (language[0], + _(language[1]), + [(get_app_name(l), os.path.realpath(l), pofile(l)) for l in pos], + ) + ) + ADMIN_MEDIA_PREFIX = settings.ADMIN_MEDIA_PREFIX + version = rosetta.get_version(True) + return render_to_response('rosetta/languages.html', locals(), context_instance=RequestContext(request)) +list_languages=user_passes_test(lambda user:can_translate(user),LOGIN_URL)(list_languages) +list_languages=never_cache(list_languages) + +def get_app_name(path): + app = path.split("/locale")[0].split("/")[-1] + return app + +def lang_sel(request,langid,idx): + """ + Selects a file to be translated + """ + if langid not in [l[0] for l in settings.LANGUAGES]: + raise Http404 + else: + + do_django = 'django' in request.GET + do_rosetta = 'rosetta' in request.GET + + file_ = find_pos(langid,include_djangos=do_django,include_rosetta=do_rosetta)[int(idx)] + + request.session['rosetta_i18n_lang_code'] = langid + request.session['rosetta_i18n_lang_name'] = unicode([l[1] for l in settings.LANGUAGES if l[0] == langid][0]) + request.session['rosetta_i18n_fn'] = file_ + po = pofile(file_) + for i in range(len(po)): + po[i].id = i + + request.session['rosetta_i18n_pofile'] = po + try: + os.utime(file_,None) + request.session['rosetta_i18n_write'] = True + except OSError: + request.session['rosetta_i18n_write'] = False + + return HttpResponseRedirect(reverse('rosetta-home')) +lang_sel=user_passes_test(lambda user:can_translate(user),LOGIN_URL)(lang_sel) +lang_sel=never_cache(lang_sel) + +def can_translate(user): + if not user.is_authenticated(): + return False + elif user.is_superuser: + return True + else: + try: + from django.contrib.auth.models import Group + translators = Group.objects.get(name='translators') + return translators in user.groups.all() + except Group.DoesNotExist: + return False diff --git a/pyweb/settings.py b/pyweb/settings.py index cc0e80e..a366eeb 100644 --- a/pyweb/settings.py +++ b/pyweb/settings.py @@ -190,4 +190,5 @@ INSTALLED_APPS = ( 'django.contrib.sites', 'registration', 'mumble', + 'rosetta', )