Ticket #2363 (closed defect: migrated)
Formencode i18n not work with turbogears
| Reported by: | victorlin | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.1 |
| Component: | TurboGears | Version: | 2.0b7 |
| Severity: | normal | Keywords: | i18n, formencode |
| Cc: |
Description
I try to i18n my turbogears2 application. Including error message of formencode. But however, I do set the locale with
formencode.api.set_stdtranslation(
domain="FormEncode", languages=["zh_TW"])
in call of BaseController?, but error messages are still english. I find out that formencode use state from turbogears2 to do translation.
And the translation function turbogears2 provided does not work with formencode.
I can't see why turbogears2 provide its own pylons_formencode_gettext rather than use pylons_formencode_gettext of pylons directly.
I try to modify that function tg2 provied, and everything works fine. These are code I modified:
def pylons_formencode_gettext(value):
from pylons.i18n import ugettext as pylons_gettext
from gettext import NullTranslations
from formencode import api
trans = pylons_gettext(value)
# Translation failed, try formencode
if trans == value:
trans = api._stdtrans(value)
As you see, I just do what pylons do. And everything works fine.
Work around for this problem
Modify config/middleware.py
def make_app(global_conf, full_stack=True, **app_conf): import tg.controllers import pylons.decorators tg.controllers.pylons_formencode_gettext = \ pylons.decorators.pylons_formencode_gettext