From ec520c45110acc89c79989fe4a8ec2dcaee59ff7 Mon Sep 17 00:00:00 2001 From: Sharoon Thomas Date: Fri, 10 Feb 2012 15:39:17 -0500 Subject: [PATCH] Further refine the translation process and add pt_BR as a language --- README.rst | 43 +++++++++++++++ babel.cfg | 1 + i18n/messages.pot | 87 +++++++++++++++++------------- i18n/pt_BR/LC_MESSAGES/messages.po | 83 +++++++++++++++++----------- party.py | 9 ++-- routing.py | 13 ++--- tests/test_i18n.py | 4 +- 7 files changed, 158 insertions(+), 82 deletions(-) create mode 100644 README.rst create mode 100644 babel.cfg diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..05f454f --- /dev/null +++ b/README.rst @@ -0,0 +1,43 @@ +Using Babel to translate nereid +=============================== + +The basic steps in translation are: + + * Extract translations + * Create language/locales + * Translate them + * compile the translations + +To extract translations +----------------------- + + pybabel extract -F babel.cfg -o i18n/messages.pot nereid trytond_nereod + + +To Translate to new language +---------------------------- + + pybabel init -i i18n/messages.pot -d i18n -l pt_BR + + +Now edit the translations/de/LC_MESSAGES/messages.po file as needed. +Check out some gettext tutorials if you feel lost. + + +To compile the translations for use +----------------------------------- + + + pybabel compile -d i18n + + +What if the strings change? +---------------------------- + + + pybabel update -i i18n/messages.pot -d i18n + + +Afterwards some strings might be marked as fuzzy (where it tried to figure out if a +translation matched a changed key). If you have fuzzy entries, make sure to check +them by hand and remove the fuzzy flag before compiling. diff --git a/babel.cfg b/babel.cfg new file mode 100644 index 0000000..efceab8 --- /dev/null +++ b/babel.cfg @@ -0,0 +1 @@ +[python: **.py] diff --git a/i18n/messages.pot b/i18n/messages.pot index f7e9325..550711e 100644 --- a/i18n/messages.pot +++ b/i18n/messages.pot @@ -1,14 +1,14 @@ -# Translations template for Nereid. +# Translations template for PROJECT. # Copyright (C) 2012 ORGANIZATION -# This file is distributed under the same license as the Nereid project. +# This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR , 2012. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: Nereid 0.3\n" +"Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2012-02-10 14:36-0500\n" +"POT-Creation-Date: 2012-02-10 15:35-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,113 +17,126 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 0.9.6\n" -#: trytond_nereid/party.py:39 trytond_nereid/party.py:64 +#: party.py:40 party.py:65 msgid "Name" msgstr "" -#: trytond_nereid/party.py:40 +#: party.py:41 routing.py:96 msgid "e-mail" msgstr "" -#: trytond_nereid/party.py:41 trytond_nereid/party.py:83 +#: party.py:42 party.py:84 msgid "New Password" msgstr "" -#: trytond_nereid/party.py:43 +#: party.py:44 party.py:86 msgid "Passwords must match" msgstr "" -#: trytond_nereid/party.py:44 +#: party.py:45 msgid "Confirm Password" msgstr "" -#: trytond_nereid/party.py:65 +#: party.py:66 msgid "Street" msgstr "" -#: trytond_nereid/party.py:66 +#: party.py:67 msgid "Street (Bis)" msgstr "" -#: trytond_nereid/party.py:67 +#: party.py:68 msgid "Post Code" msgstr "" -#: trytond_nereid/party.py:68 +#: party.py:69 msgid "City" msgstr "" -#: trytond_nereid/party.py:69 +#: party.py:70 msgid "Country" msgstr "" -#: trytond_nereid/party.py:70 +#: party.py:71 msgid "State/County" msgstr "" -#: trytond_nereid/party.py:86 +#: party.py:87 msgid "Repeat Password" msgstr "" -#: trytond_nereid/party.py:99 +#: party.py:100 msgid "Old Password" msgstr "" -#: trytond_nereid/party.py:343 -msgid "A registration already exists with this email. Please contact customer care" -msgstr "" - -#: trytond_nereid/party.py:353 +#: party.py:344 msgid "" -"Registration Complete. Check your email for\n" -" activation" +"A registration already exists with this email. Please contact customer " +"care" msgstr "" -#: trytond_nereid/party.py:389 trytond_nereid/party.py:429 +#: party.py:355 +msgid "Registration Complete. Check your email for activation" +msgstr "" + +#: party.py:390 party.py:430 msgid "Your password has been successfully changed! Please login again" msgstr "" -#: trytond_nereid/party.py:395 +#: party.py:396 msgid "The current password you entered is invalid" msgstr "" -#: trytond_nereid/party.py:446 +#: party.py:447 msgid "Invalid Activation Code" msgstr "" -#: trytond_nereid/party.py:457 +#: party.py:458 msgid "Your account has been activated" msgstr "" -#: trytond_nereid/party.py:496 +#: party.py:497 msgid "Invalid email address" msgstr "" -#: trytond_nereid/party.py:500 +#: party.py:501 msgid "An email has been sent to your account for resetting your credentials" msgstr "" -#: trytond_nereid/party.py:535 +#: party.py:536 msgid "Your account has not been activated yet!" msgstr "" -#: trytond_nereid/routing.py:97 +#: routing.py:97 msgid "Password" msgstr "" -#: trytond_nereid/routing.py:234 -msgid "You are now logged in. Welcome" +#: routing.py:234 +#, python-format +msgid "You are now logged in. Welcome %(name)s" msgstr "" -#: trytond_nereid/routing.py:246 +#: routing.py:247 msgid "Invalid login credentials" msgstr "" -#: trytond_nereid/routing.py:260 +#: routing.py:261 msgid "You have been logged out successfully. Thanks for visiting us" msgstr "" -#: trytond_nereid/tests/test_i18n.py:50 +#: routing.py:318 +msgid "The currency has been successfully changed" +msgstr "" + +#: routing.py:374 +msgid "Your language preference have been saved." +msgstr "" + +#: routing.py:376 +msgid "Sorry! we do not speak your language yet!" +msgstr "" + +#: tests/test_i18n.py:50 msgid "en_US" msgstr "" diff --git a/i18n/pt_BR/LC_MESSAGES/messages.po b/i18n/pt_BR/LC_MESSAGES/messages.po index 2a76b8d..bbafc71 100644 --- a/i18n/pt_BR/LC_MESSAGES/messages.po +++ b/i18n/pt_BR/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Nereid 0.3\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2012-02-10 14:36-0500\n" +"POT-Creation-Date: 2012-02-10 15:35-0500\n" "PO-Revision-Date: 2012-02-10 14:36-0500\n" "Last-Translator: FULL NAME \n" "Language-Team: pt_BR \n" @@ -17,115 +17,134 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 0.9.6\n" -#: trytond_nereid/party.py:39 trytond_nereid/party.py:64 +#: party.py:40 party.py:65 msgid "Name" msgstr "" -#: trytond_nereid/party.py:40 +#: party.py:41 routing.py:96 msgid "e-mail" msgstr "" -#: trytond_nereid/party.py:41 trytond_nereid/party.py:83 +#: party.py:42 party.py:84 msgid "New Password" msgstr "" -#: trytond_nereid/party.py:43 +#: party.py:44 party.py:86 msgid "Passwords must match" msgstr "" -#: trytond_nereid/party.py:44 +#: party.py:45 msgid "Confirm Password" msgstr "" -#: trytond_nereid/party.py:65 +#: party.py:66 msgid "Street" msgstr "" -#: trytond_nereid/party.py:66 +#: party.py:67 msgid "Street (Bis)" msgstr "" -#: trytond_nereid/party.py:67 +#: party.py:68 msgid "Post Code" msgstr "" -#: trytond_nereid/party.py:68 +#: party.py:69 msgid "City" msgstr "" -#: trytond_nereid/party.py:69 +#: party.py:70 msgid "Country" msgstr "" -#: trytond_nereid/party.py:70 +#: party.py:71 msgid "State/County" msgstr "" -#: trytond_nereid/party.py:86 +#: party.py:87 msgid "Repeat Password" msgstr "" -#: trytond_nereid/party.py:99 +#: party.py:100 msgid "Old Password" msgstr "" -#: trytond_nereid/party.py:343 +#: party.py:344 msgid "" "A registration already exists with this email. Please contact customer " "care" msgstr "" -#: trytond_nereid/party.py:353 -msgid "" -"Registration Complete. Check your email for\n" -" activation" +#: party.py:355 +msgid "Registration Complete. Check your email for activation" msgstr "" -#: trytond_nereid/party.py:389 trytond_nereid/party.py:429 +#: party.py:390 party.py:430 msgid "Your password has been successfully changed! Please login again" msgstr "" -#: trytond_nereid/party.py:395 +#: party.py:396 msgid "The current password you entered is invalid" msgstr "" -#: trytond_nereid/party.py:446 +#: party.py:447 msgid "Invalid Activation Code" msgstr "" -#: trytond_nereid/party.py:457 +#: party.py:458 msgid "Your account has been activated" msgstr "" -#: trytond_nereid/party.py:496 +#: party.py:497 msgid "Invalid email address" msgstr "" -#: trytond_nereid/party.py:500 +#: party.py:501 msgid "An email has been sent to your account for resetting your credentials" msgstr "" -#: trytond_nereid/party.py:535 +#: party.py:536 msgid "Your account has not been activated yet!" msgstr "" -#: trytond_nereid/routing.py:97 +#: routing.py:97 msgid "Password" msgstr "" -#: trytond_nereid/routing.py:234 -msgid "You are now logged in. Welcome" +#: routing.py:234 +#, python-format +msgid "You are now logged in. Welcome %(name)s" msgstr "" -#: trytond_nereid/routing.py:246 +#: routing.py:247 msgid "Invalid login credentials" msgstr "" -#: trytond_nereid/routing.py:260 +#: routing.py:261 msgid "You have been logged out successfully. Thanks for visiting us" msgstr "" -#: trytond_nereid/tests/test_i18n.py:50 +#: routing.py:318 +msgid "The currency has been successfully changed" +msgstr "" + +#: routing.py:374 +msgid "Your language preference have been saved." +msgstr "" + +#: routing.py:376 +msgid "Sorry! we do not speak your language yet!" +msgstr "" + +#: tests/test_i18n.py:50 msgid "en_US" msgstr "pt_BR" +#~ msgid "" +#~ "Registration Complete. Check your email for\n" +#~ " activation" +#~ msgstr "" + +#~ msgid "You are now logged in. Welcome" +#~ msgstr "" + diff --git a/party.py b/party.py index 6f66c18..44ad7af 100644 --- a/party.py +++ b/party.py @@ -20,12 +20,13 @@ from werkzeug import redirect, abort from nereid import request, url_for, render_template, login_required, flash from nereid.globals import session, current_app -from nereid.i18n import _, get_translations from trytond.model import ModelView, ModelSQL, fields from trytond.pyson import Eval, Bool, Not from trytond.transaction import Transaction from trytond.config import CONFIG +from .i18n import _, get_translations + class RegistrationForm(Form): "Simple Registration form" @@ -82,7 +83,7 @@ class NewPasswordForm(Form): password = PasswordField(_('New Password'), [ validators.Required(), - validators.EqualTo('confirm', message='Passwords must match')]) + validators.EqualTo('confirm', message=_('Passwords must match'))]) confirm = PasswordField(_('Repeat Password')) @@ -350,8 +351,8 @@ class NereidUser(ModelSQL, ModelView): 'password': registration_form.password.data, }) self.create_act_code(user_id) - flash(_('''Registration Complete. Check your email for - activation''') + flash( + _('Registration Complete. Check your email for activation') ) return redirect( request.args.get('next', url_for('nereid.website.home')) diff --git a/routing.py b/routing.py index a1bc978..20968f8 100644 --- a/routing.py +++ b/routing.py @@ -16,11 +16,11 @@ from wtforms import Form, TextField, PasswordField, validators from nereid import jsonify, flash, render_template, url_for, cache from nereid.globals import session, request from nereid.helpers import login_required, key_from_list, get_flashed_messages -from nereid.i18n import _ from nereid.signals import login, failed_login, logout from trytond.model import ModelView, ModelSQL, fields from trytond.transaction import Transaction +from .i18n import _ # pylint: disable-msg=E1101 class URLMap(ModelSQL, ModelView): @@ -93,7 +93,7 @@ URLMap() class LoginForm(Form): "Default Login Form" - email = TextField('e-mail', [validators.Required(), validators.Email()]) + email = TextField(_('e-mail'), [validators.Required(), validators.Email()]) password = PasswordField(_('Password'), [validators.Required()]) @@ -231,7 +231,8 @@ class WebSite(ModelSQL, ModelView): # want to handle the message shown to user) if result: # NOTE: Translators leave %s as such - flash(_("You are now logged in. Welcome") + result.name) + flash(_("You are now logged in. Welcome %(name)s", + name=result.name)) session['user'] = result.id login.send(self) if request.is_xhr: @@ -314,7 +315,7 @@ class WebSite(ModelSQL, ModelView): abort(403) # Forbidden currency session['currency'] = currency - message = "The currency has been successfully changed" + message = _("The currency has been successfully changed") if request.is_xhr: return jsonify(result = {'success': True, 'message': message}) @@ -370,9 +371,9 @@ class WebSite(ModelSQL, ModelView): exists = lang_obj.search([('code', '=', language)], limit=1) if exists: - flash('Your language preference have been saved.') + flash(_('Your language preference have been saved.')) else: - flash('Sorry! we do not speak your language yet!') + flash(_('Sorry! we do not speak your language yet!')) # redirect to the next url if given else take to home page redirect_to = request.values.get('next') diff --git a/tests/test_i18n.py b/tests/test_i18n.py index 6e1f91f..fbca380 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -12,7 +12,7 @@ from trytond.config import CONFIG CONFIG.options['db_type'] = 'sqlite' from trytond.modules import register_classes register_classes() -from trytond.modules.nereid.i18n import _, get_translations +from trytond.modules.nereid.i18n import _ from nereid.testing import testing_proxy, TestCase from trytond.transaction import Transaction @@ -49,9 +49,7 @@ class TestI18N(TestCase): with Transaction().start(testing_proxy.db_name, 1, None): s = _("en_US") self.assertEqual(s, u'en_US') - print get_translations() with Transaction().set_context(language="pt_BR"): - print get_translations(), s, str(s) self.assertEqual(s, u'pt_BR')