Re: Getting translation of python code string to work

[email protected]
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
> Hi Morten,

Hi Leonard,

> On Tue, May 31, 2011 at 13:19,  <[email protected]> wrote:
>> Hi,
>>
>> I have a oldschool style Zope 2 product, which has an i18n
>> directory containing translations.
>>
>> Using i18n:domain="SimpleChat" in this product works fine in
>> the page templates,
>
> Well, ZPTs generate message objects automatically from translated
> content, but they also explicitly translate all the message objects
> they get during interpolation between the literal parts of the
> template and the dynamically generated ones.
>
>> but when I start translating text in
>> a Python module using _("Translate me") I just get English
>> text (instead of Norwegian, which is what I want).
>
> When you say "I just get English text", what does exactly "get" mean
> in terms of code?
>
> Mind you, if you simple call unicode(message) you'll most likely only
> get the English version back. Same thing if you do:
>
>   u"some other string: %s" % message
>
> To get an actual translation, you need to call
> zope.i18n.translate(message), eventually passing the
> "target_languate=..." parameter.
>
> Take a look at the zope.i18n module for details, specifically the
> translate() and negotiate() functions.

OK.  Well I have this function now:

def _(msgid, request):
    language = request['LANGUAGE']
    return translate(msgid, domain='SimpleChat', target_language=language)

Which sends all the relevant bits to the translate function.  But, this
doesn't work either, and I can see it is because the interpolate function
call is used in translate.

So do I need to setup some utility?

-Morten

_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.