Recommendations on where to store translation strings

42 views
Skip to first unread message

Jimbo

unread,
Aug 7, 2016, 4:09:03 PM8/7/16
to web2py-users
Hi,

I have several dictionaries which needs translation, where would you recommended I store these?

I currently have them in model-files and they typically looks something like this:

choices = collections.OrderedDict((
   
('1', T('Choice 1')),
   
('2', T('Choice 2')),
   
...
))

Then I use them in string-Fields with the IS_IN_SET validator.

Since models are evaluated at every request it seems like a waste to have these files with 'static' data being parsed all the time. For example, I currently have around 2000 lines consisting of similar lists representing different choices (country names, etc.).
Therefore it seems natural (to me) to move them into modules and translate them when needed using "current.T" or alternatively to translate them "once and for all" (don't know if this is possible).

However, if I define the dict in a module it seems like these strings are only added to the "language list" when they are first evaluated by some function, see this related question
In this case, how do I go about generating the full list of all the translation strings without manually triggering the translation for each of them?

Maybe I'm going about this the wrong way so would like to hear how other people structure their translation resources.

Thanks
// Jim

Niphlod

unread,
Aug 8, 2016, 4:21:35 PM8/8/16
to web2py-users
uhm. 
a) T() just translates at the "view" level, i.e. when those are actually serialized ... passing over a module containing "choices" wouldn't ACTUALLY translate them .
b) admin's management for T() strings is less than optimal with thousands of elements, and if in the need of a top-class "translation" subsystem I'd either build a better interface for it or use a different library alltogether (or even cook my own, as it's just a dict lookup anyway)
c) code to find all translations is there https://github.com/web2py/web2py/blob/master/gluon/languages.py#L949 ... it **seems** to scout app's modules. In **THAT** case, simply porting the module over the app's path will fetch all translations (you can then move out/delete the module, if you have it system-wide). I don't see a way for web2py to execute each and every code-path in your app to find all your's translations.

Jimbo

unread,
Aug 9, 2016, 2:20:38 PM8/9/16
to web2py-users
Aha, I see. I have probably exercised a lot of my views during development so I got the impression that stating my T's in the models automatically added them to translation.

I will investigate the options you proposed, thanks for the pointers!

Reply all
Reply to author
Forward
0 new messages