[Zope3-Users] Translations with variables embedded in HTMLattributes

Doyon, Jean-Francois jdoyon at NRCan.gc.ca
Tue Aug 28 16:21:09 EDT 2007


Because you're working with an attribute value, which isn't deemed
content per say, it's not text/cdata in the templating world.

Here's a proper i18n:name example from my own templates:

<h2 i18n:translate="">List of <tal:replace
		tal:replace="topic/title" i18n:name="title" /> Maps</h2>


Because you're manipulating a string that's meant as an attribute value,
that breaks the model somewhat.

You could try:

<a tal:attributes="href string:/?lang=${lang}" tal:define="lang
python:translate(myvalue)">Link</a>

But where translate() is a function you defined somewhere.

That's how I handle these cases.  I have a utils.i18ntranslate()
function, which I can use through
modules/Products/MyProduct/utils/i18ntranslate (and in python code of
course, if needed).

The variable substitution available is meant to be used by message ID's,
and I don't expect a URL is used as a message ID ... Probably never
should.  The approach above seems to make more sense to me.

Anyways, that's how I do it (And I have a multilingual site, so I know
what you're going through!) :)

J.F.

-----Original Message-----
From: Asheesh Laroia [mailto:asheesh at creativecommons.org] 
Sent: August 28, 2007 16:02
To: Doyon, Jean-Francois
Cc: zope3-users at zope.org
Subject: RE: [Zope3-Users] Translations with variables embedded in
HTMLattributes

On Tue, 28 Aug 2007, Doyon, Jean-Francois wrote:

> Seems like you're trying to manipulate a string (a URL?) to do 
> translation within it, in which case you shouldn't do this within your

> TAL, but instead have a separate piece of logic to do it (Python 
> Script for example).

Translations can have variables in gettext.  All I'm trying to do is try
to handle a case of this variables substitution that the TAL syntax
makes hard.  I don't see why that justifies not using the built-in i18n
feature of Zope's TAL.

-- Asheesh.

--
"We live, in a very kooky time."
 		-- Herb Blashtfalt


More information about the Zope3-users mailing list