Translating templates

6 views
Skip to first unread message

Demetrio Girardi

unread,
Dec 14, 2011, 3:13:47 PM12/14/11
to django...@googlegroups.com
My project has a bunch of text embedded deep within the html markup in
templates that I need to translate. The text, imo, belongs to templates and it
has no place in the application logic.

From what I understand, localization in templates is limited to variables,
which is not useful to me. For example, I'll have a template like this:

> <lots><of><markup><to><make><this><look><fancy>
> We are the greatest company in the world. yadda yadda.
> <a><lot><of><other><markup>
> {% actual useful stuff%}
> <etc>A lot of other useless text otherwise the page isn't professional
> enough </etc>

I cannot simply pass the template file to the translators because they would
be confused by the markup. Is there a "correct" way to handle localization of
decorative text?

Karen Tracey

unread,
Dec 14, 2011, 9:46:50 PM12/14/11
to django...@googlegroups.com
On Wed, Dec 14, 2011 at 3:13 PM, Demetrio Girardi <demetrio...@gmail.com> wrote:
My project has a bunch of text embedded deep within the html markup in
templates that I need to translate. The text, imo, belongs to templates and it
has no place in the application logic.

From what I understand, localization in templates is limited to variables,

That's not correct, where did you get that idea?
 
which is not useful to me. For example, I'll have a template like this:

> <lots><of><markup><to><make><this><look><fancy>
> We are the greatest company in the world. yadda yadda.
> <a><lot><of><other><markup>
> {% actual useful stuff%}
> <etc>A lot of other useless text otherwise the page isn't professional
> enough </etc>

You use the trans template tag to mark plain strings in template code for translation, blocktrans if the strings have variables embedded in them. See ttps://docs.djangoproject.com/en/1.3/topics/i18n/internationalization/#specifying-translation-strings-in-template-code for details. E.g.:

 <lots><of><markup><to><make><this><look><fancy>
{% trans "We are the greatest company in the world. yadda yadda." %}

<a><lot><of><other><markup>
{% actual useful stuff%}
<etc> {% trans "A lot of other useless text otherwise the page isn't professional
 enough" %} </etc>

Once all strings are marked, you use the makemessages command (https://docs.djangoproject.com/en/1.3/topics/i18n/localization/#message-files) to generate message files, and that's what you hand to translators to translate.

Karen
--
http://tracey.org/kmt/

Reply all
Reply to author
Forward
0 new messages