Further refine the translation process and add pt_BR as a language

This commit is contained in:
Sharoon Thomas 2012-02-10 15:39:17 -05:00
parent 3d99085cc7
commit ec520c4511
7 changed files with 158 additions and 82 deletions

43
README.rst Normal file
View File

@ -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.

1
babel.cfg Normal file
View File

@ -0,0 +1 @@
[python: **.py]

View File

@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: pt_BR <LL@li.org>\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 ""

View File

@ -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'))

View File

@ -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')

View File

@ -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')