I wonder if anyone here has had any experience with i18n in Pyramid inside
Mako templates and could explain to me this mind-boggling error.
I've set up my application such that, in views, almost all being classes, I
fetch the request's localizer and use it to get a translation fonction for
simple messages (that I call "_" but is the "auto_translate" generated by
the following function):
TRANSLATION_STRING_FACTORY_APP = i18n.TranslationStringFactory('messages')
def construct_auto_translate(localizer):
def auto_translate(s, *args, **kwargs):
if not isinstance(s, i18n.TranslationString):
s = TRANSLATION_STRING_FACTORY_APP(s)
return localizer.translate(s, *args, **kwargs)
return auto_translate
I also use the localizer to get the "pluralize" function, that I use under
the name "n". Something like:
self.localizer = self.request.localizer
n = self.localizer.pluralize
Inside views, both "_(...)" and "n(...)" work as expected. Translated
strings are fetched and the plural forms also work well. I pass the same
functions to the templates and the "_(...)" one works as expected, but the
pluralize one can't ever fetch translated strings.
I can move the same function call ("n(singular, plural, nbr, ...)") from my
template to the corresponding view without changes and just add the return
value to the template arguments and the message is translated fine. It
doesn't work only when it's placed inside the mako template.
I've tried to follow the calls to pluralize and figure what was different
in both cases. I couldn't see any difference except all the way back to the
built-in gettext module's ngettext not returning the same value when called
from the template as when called from the view. The Pyramid Translations
object on which the call to ngettext is made seems to be constructed
correctly in both cases.
I could move all translations using plural forms from the templates to the
views but I would rather keep them there. Does anyone have any idea of what
might be causing the translations to fail in that particular case?
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.