Ticket #1999 (closed defect: fixed)
[patch] i18n fix for FormEncode & ToscaWidgets
| Reported by: | TimurIzhbulatov | Owned by: | faide |
|---|---|---|---|
| Priority: | highest | Milestone: | 2.0b6 |
| Component: | TurboGears | Version: | trunk |
| Severity: | normal | Keywords: | i18n toscawidgets formencode gettext |
| Cc: |
Description
This patch sets a translator for ToscaWidgets? middleware and adds a request specific translator for standard FormEncode messages.
For the later purpose it uses an approach similar to the one used in Pylons but doesn't rely on formencode.api._stdtrans module global which is a gettext.NullTranslations? instance created at module import time. Instead, a request specific translation object is created and saved in tmpl_context.
Attachments
Change History
comment:3 Changed 3 years ago by faide
- Owner changed from mramm to faide
- Status changed from new to assigned
comment:5 Changed 3 years ago by percious
- Status changed from assigned to new
- Owner changed from faide to percious
comment:10 Changed 3 years ago by TimurIzhbulatov
I've updated the patch for current trunk, and it also works with 2.0b5.1. The test project I used for verification is attached.
Besides internationalized widgets, the project includes translated messages collected from controller code and template (please see i18n/ru/LC_MESSAGES/tg2twi18n.po).
The language is set to Russian in development.ini (lang = ru), so you'll need to comment it out to see the original untranslated messages.
comment:11 Changed 3 years ago by mramm
From here this patch looks good, and I played with it and it seems OK as Timur suggests. Florent, Alberto, Percious, could you comment?
This patch is a blocker for b6 at this point.
comment:12 Changed 3 years ago by faide
At one point I assigned that ticket to myself... I'll try to give a look :)
comment:13 follow-up: ↓ 14 Changed 3 years ago by Gustavo
I think the patch is good, but:
- In controllers.py, line 844 should be a WARN and 851 a INFO, from my point of view.
- There's a comment on pylons_formencode_gettext() which states that it basically comes from Pylons and I couldn't find anything TG-specific, so why don't we use Pylons' implementation?
comment:14 in reply to: ↑ 13 Changed 3 years ago by Gustavo
Please ignore the following, the answer was in the ticket's description -- I had to read it all first:
Replying to Gustavo:
- There's a comment on pylons_formencode_gettext() which states that it basically comes from Pylons and I couldn't find anything TG-specific, so why don't we use Pylons' implementation?
comment:15 Changed 3 years ago by faide
Sorry but this patch breaks a lot of tests.
the setup_i18n function is not properly called during the tests and we get missing attributes in the validation tests because the controller cannot find pylons.c.formencode_translation
This means I have 5 failing tests and I could not find a simple solution to fix those. I cannot take the risk to apply that patch as-is. We should fix those tests before it can go in.
comment:16 Changed 3 years ago by faide
In fact the function is called but I think the language cannot ne retrieved during the tests and thus the:
pylons.c.formencode_translation
attribute cannot be set. This is a test problem because in a live app the language will be properly detected and the attr will be present.
comment:17 Changed 3 years ago by faide
I fixed all the tests. I need some time to cleanup the mess and I'll commit this :)
comment:18 Changed 3 years ago by faide
Applied to r6421 Please review the change regarding the log levels because I did that in a hurry.
