I've upgraded from TG 1.0.1 to 1.0.2.2 and relied on what the changelog said:
FormEncode ("FE") messages would be localized (or at least localizable) from
that on.
With TG 1.0.1 at least my validators have thrown translateable messages which
appeared then in the correct language. (FE's own messages were still in English.)
Unluckily, with TG 1.0.2.2 FE's messages are neither localizable (no .MO created
or added) nor displayed localized (even if apropriate PO was shipped with it).
To make things worse what has at least worked with my own validators now does not!
Did anyone experience a similar issue? Did I forget to include something? (I've
already tried the '_ = lambda x: x' hack.)
Thanks in advance
W-Mark Kubacki
It is working for me. But I think you need to copy FormEncode's .po
files over to the locale directory of your TG project.
-- Chris
Does not work.
To point it out: Although my validators are already translated they're not
displayed correctly - as if gettext didn't work.
-- Mark
Just checked it out again. You don't even need to copy FormEncode's .po
file; the .mo file is copied automatically when FormEncode is installed.
Here is how you should get a dummy project running:
* install TurboGears 1.0.2.2
* at the console:
tg-admin quickstart foo
cd foo
tg-admin i18n collect
tg-admin i18n add de
* in welcome.kid, after <body> insert:
<div py:replace="form()"/>
* replace controllers.py with the following:
------------------------------
from turbogears import controllers, expose, validate, error_handler
from turbogears import widgets, validators
class NoWar(validators.FancyValidator):
def _(s): return s
gettextargs = {'domain': 'messages'}
messages = {'war': _("Don't mention the war!")}
def validate_python(self, value, state):
if 'war' in value:
raise validators.Invalid(
self.message('war', state), value, state)
foo_form = widgets.TableForm(
fields=[widgets.TextField(
name="Not_Empty", validator=validators.NotEmpty()),
widgets.TextField(
name="No_War", validator=NoWar())])
class Root(controllers.RootController):
@expose(template="foo.templates.welcome")
@validate(form)
@error_handler()
def index(self, **kw):
return dict(form=foo_form, now='now')
------------------------------
* at the console:
tg-admin i18n collect
tg-admin i18n merge
* in foo/locales/de/LC_MESSAGES/messages.po set:
msgid "Don't mention the war!"
msgstr "War da was?"
* at the console:
tg-admin i18n compile
python start-foo.py
* Both error messages should show up in German,
the standard message from FormEncode if you leave the first field empty,
the custom message "War da was" if you enter "war" in the second field.
-- Chris
With TG 1.0.1 only FormEncode's validators didn't work. With 1.0.2.2 both,
FormEncode's and my (formerly working) _("") messages are broken.
-- Mark