localization with pyramid

45 views
Skip to first unread message

Petr Blahos

unread,
Sep 25, 2013, 2:39:22 PM9/25/13
to forma...@googlegroups.com
Hi,

I am somehow unable to understand how to get localization properly work
with formalchemy and pyramid (not pyramid_formalchemy), Is my perception 
that if formalchemy detects pyramid, it will use pyramid's localizer to localize
things, correct? Is it also true, that in such case the messages found only in
formalchemy (especially validators) will never get translated?

Could somebody point me to a sample application that has both of these
things working?

Thanks,
--
Petr

Petr Blahos

unread,
Oct 23, 2013, 3:22:47 PM10/23/13
to forma...@googlegroups.com
Well, my solution so far is to add formalchemy's translations to my app's locale dir:
    config.add_translation_dirs('myapp:locale', 'formalchemy:i18n_resources')
but that will load the formalchemy's locale under domain formalchemy. Therefore 
I also copied functions get_localizer and make_localizer from pyramid.i18n, and in
make_localizer I re-domainize the formalchemy translations to myapp's domain,
like this:
        if mofile.endswith('.mo') and os.path.isfile(mopath):
            with open(mopath, 'rb') as mofp:
                domain = mofile[:-3]
                if "formalchemy"==domain: domain = "faapp"
                dtrans = Translations(mofp, domain)
                translations.add(dtrans)
Is it a too ugly hack or do you think it is passable?

I also set 
    request.environ['fa.translate'] = auto_translate
so that formalchemy does has to do a bit less.
--
Petr




--
You received this message because you are subscribed to the Google Groups "FormAlchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to formalchemy...@googlegroups.com.
To post to this group, send email to forma...@googlegroups.com.
Visit this group at http://groups.google.com/group/formalchemy.
For more options, visit https://groups.google.com/groups/opt_out.



--
_________________________________
http://sites.google.com/site/petrsstuff/
Reply all
Reply to author
Forward
0 new messages