durusmail: quixote-users: i18n and l10n in quixote applications, how?
i18n and l10n in quixote applications, how?
2005-06-05
2005-06-05
2005-06-05
Re: i18n and l10n in quixote applications, how?
2005-06-06
2005-06-08
i18n and l10n in quixote applications, how?
Mario Ruggier
2005-06-05
Not sure that quixote has an idiom for this... ;)

I am using a very simple scheme. I have a very simple db of text
instances (can just be a dict), having a property per language I wish
to support, plus a string key (or any hashable thingy) for each
instance, and an optional category. In my case this is implemented as a
durus db, but could be in anything you like.

Then I have a singleton class whose instance (i18n_server) has one
important method:

     def serve(self, key, lang='en'):
         returns the translated text for the specified language,
         or if that value is not defined, the en version for it,
         or the key itself
         plus, if no such key, one is created

Outside of this class, I have a factory function that returns a
convenient translator function:

def get_text_translator(lang='en'):
     def t(key, lang=lang):
         return i18n_server.serve(key,lang)
     return t

that is called on each publisher.start_request(), and the result is
attached to the request:

     def start_request(self):
         ...
         request.t = get_text_translator(session.lang)

then, template code can just do:
     t = request.t
     t('key') # to get the translation for 'key', in the user's selected
lang

This has worked fine for me, also inside of ptl templates (even if i
use ptl very minimally)...
Comments anyone?

mario



On Jun 5, 2005, at 7:34 PM, Damjan wrote:

> What's the quixote idiom for writing translatable applications?
>
> I'm thinking of using python gettext, but I'm not sure if it will work
> with PTL.
>
> Any other posibilities?
>
> --
> damjan | дамјан
> This is my jabber ID --> damjan@bagra.net.mk <-- not my mail address!!!
> _______________________________________________
> Quixote-users mailing list
> Quixote-users@mems-exchange.org
> http://mail.mems-exchange.org/mailman/listinfo/quixote-users

reply