Translating a line with a link

10 views
Skip to first unread message

suiato

unread,
Jun 3, 2009, 8:14:27 PM6/3/09
to web2py Web Framework
This may be a newbie question, but will someone tell me what'd be the
proper way of putting T() to the line below?
<li>Users can access the store <a
href="{{=request.application}}">here</a></li>

It's in manage/setup.html of the eStore appliance.

I've tried like
<li>{{=T('Users can access the store <a href="/%(req)s">here</a>', dict
(req=request.application))}}</li>
but shown in browser is (when the translation is the same as the
original)
Users can access the store <a href="/estore">here</a>

Thanks,
Teru

mdipierro

unread,
Jun 3, 2009, 8:23:27 PM6/3/09
to web2py Web Framework
<li>{{=T('Users can access the store')}} <a
href="{{=request.application}}">{{=T('here')}}</a></li>

you still need to go to admin and edit the translation in the language
requested by the browser.

Massimo

suiato

unread,
Jun 3, 2009, 9:31:19 PM6/3/09
to web2py Web Framework
Thanks, Massimo

2009/6/4 mdipierro <mdip...@cs.depaul.edu>:
>
> <li>{{=T('Users can access the store')}} <a
> href="{{=request.application}}">{{=T('here')}}</a></li>

OK. It works :)

I hoped T() could include the whole line because word orders are
different (often reversed) in Japanese.
For example, verb in Japanese usually comes at the end, and the
translation of the above line in HTML should look like
ユーザは、<a... >ここ</a>でストアにアクセスできます。

But, I'll manage somehow...

>
> you still need to go to admin and edit the translation in the language
> requested by the browser.

Yes, in fact, I'm about to finish a draft of Japanese translation of
eStore.
I will be happy to share the results if anyone is interested.

>
> Massimo

Cheers,
Teru

mdipierro

unread,
Jun 3, 2009, 10:16:42 PM6/3/09
to web2py Web Framework
It can

<li>{{=XML(str(T('Users can access the store <a href="%s">here</a>',
(request.application)))}}</li>

Massimo

On Jun 3, 8:31 pm, suiato <Homm...@gmail.com> wrote:
> Thanks, Massimo
>
> 2009/6/4 mdipierro <mdipie...@cs.depaul.edu>:

suiato

unread,
Jun 3, 2009, 11:01:28 PM6/3/09
to web2py Web Framework
2009/06/04 11:16 mdipierro <mdip...@cs.depaul.edu>:
>
> It can
>
> <li>{{=XML(str(T('Users can access the store <a href="%s">here</a>',
> (request.application)))}}</li>
>
> Massimo

Wow, great!
It worked after adding a paranthesis ) to close XML. (The correction
was easy to make thanks to the friendly editor in web2py.)

Thanks a lot.

--
Teru

mdipierro

unread,
Jun 3, 2009, 11:12:46 PM6/3/09
to web2py Web Framework
it may work without the str but I have not tried.


On Jun 3, 10:01 pm, suiato <Homm...@gmail.com> wrote:
> 2009/06/04 11:16 mdipierro <mdipie...@cs.depaul.edu>:

suiato

unread,
Jun 3, 2009, 11:51:20 PM6/3/09
to web2py Web Framework
When writing {{=XML(str(T(...)))}}} lines for translation here and
there, I realize it might be better to modify T(), wrapping the
current T() with XML(str()). It will be simpler in expression, and
won't break the compatibility, will it? Otherwise, you might end up
with typing lots of {{=XML(str(T(...)))}}} in the source code when
internationalizing.

--
Teru


On 6月4日, 午後12:01, suiato <Homm...@gmail.com> wrote:
> 2009/06/04 11:16 mdipierro <mdipie...@cs.depaul.edu>:
>
>
>

mdipierro

unread,
Jun 3, 2009, 11:57:00 PM6/3/09
to web2py Web Framework
In model you can just do

Tx=lambda *a: XML(str(T(*a))

and use Tx instead.

suiato

unread,
Jun 4, 2009, 12:08:52 AM6/4/09
to web2py Web Framework
2009/06/04 12:57 mdipierro <mdip...@cs.depaul.edu>:
>
> In model you can just do
>
> Tx=lambda *a: XML(str(T(*a))
>
> and use Tx instead.

This is a good learning experience for me. Lots of thanks, Massimo.

By the way, XML(T()) seems to work when I tested with an example.

Cheers,
Teru

JorgeR

unread,
Jun 4, 2009, 12:47:33 PM6/4/09
to web2py Web Framework
cool

this should go in the wiki under 'tips and tricks'

On Jun 3, 11:08 pm, suiato <Homm...@gmail.com> wrote:
> 2009/06/04 12:57 mdipierro <mdipie...@cs.depaul.edu>:

suiato

unread,
Jun 4, 2009, 11:08:03 PM6/4/09
to web2py Web Framework
On 6月5日, 午前1:47, JorgeR <jorgeh...@gmail.com> wrote:
> cool
>
> this should go in the wiki under 'tips and tricks'

Oh, in https://mdp.cti.depaul.edu/wiki/ ?
Actually, it'd be nice to have a topic on translation/i18n/l10n.

>
> On Jun 3, 11:08 pm, suiato <Homm...@gmail.com> wrote:
>
> > 2009/06/04 12:57 mdipierro <mdipie...@cs.depaul.edu>:
>
> > > In model you can just do
>
> > > Tx=lambda *a: XML(str(T(*a))
>
> > > and use Tx instead.

In my current effort to translate eStore, XML(T()) for links works
well and I'm happily using it.

I still need to work on making the above lambda function work.
Do I just add the line into the model store.py? My first try was not
successful.

--
Teru

mdipierro

unread,
Jun 5, 2009, 8:59:17 AM6/5/09
to web2py Web Framework
in principle yes. what error do you get?

suiato

unread,
Jun 5, 2009, 10:17:25 PM6/5/09
to web2py Web Framework
On 6月5日, 午後9:59, mdipierro <mdipie...@cs.depaul.edu> wrote:
> in principle yes. what error do you get?

Adding the line
Tx=lambda *a: XML(str(T(*a))
to store.py in the model of eStore doesn't cause any errors.
In fact, it seems to be working in Shell.

After a good sleep, I realize findT() is made to look for T(), not Tx
()... isn't it?
If so, the regular expression in languages.py in gluon needs to be
changed to find Tx() as well as T().
I'm not familiar with regular expression, and will appreciate some
advice. The pattern (in ver.1.63.2) is

# pattern to find T(bla bla bla) expressions
PY_STRING_LITERAL_RE = r'(?<=[^\w]T\()(?P<name>'\
+ r"[uU]?[rR]?(?:'''(?:[^']|'{1,2}(?!'))*''')|"\
+ r"(?:'(?:[^'\\]|\\.)*')|" + r'(?:"""(?:[^"]|"{1,2}(?!"))
*""")|'\
+ r'(?:"(?:[^"\\]|\\.)*"))'
regex_translate = re.compile(PY_STRING_LITERAL_RE, re.DOTALL)

By the way, in epydoc(http://mdp.cti.depaul.edu/examples/static/
epydoc/), it's
regex_translate = re.compile(r'(?s)(?<=[^\w]T\()(?P<name>[uU]?[rR]?(?:
\'\'\'(?:[^\']|\'{\1,2}(?!\'))*\'\'\')|(?:\'(?:[^\'\\]|\\.)*\')|
(?:"""(?:[^"]|"{1,2}(?!")\)*""")|(?:"(?:[^"\\]|\\.)*"))')

--
Teru

suiato

unread,
Jun 5, 2009, 10:40:47 PM6/5/09
to web2py Web Framework
I changed the regular expression in gluon/languages.py as below, and
"update all languages" now updates the strings in T() and Tx() :-)

PY_STRING_LITERAL_RE = r'(?<=[^\w]T)x?\((?P<name>'\
+ r"[uU]?[rR]?(?:'''(?:[^']|'{1,2}(?!'))*''')|"\
+ r"(?:'(?:[^'\\]|\\.)*')|" + r'(?:"""(?:[^"]|"{1,2}(?!"))
*""")|'\
+ r'(?:"(?:[^"\\]|\\.)*"))'

To follow naming convention in web2py, would it be better called TX()
instead of Tx()?

--
Teru

mdipierro

unread,
Jun 5, 2009, 10:49:50 PM6/5/09
to web2py Web Framework
I see what you are doing but I do not like the fact that this promotes
Tx to something special while that is a name that I made up as an
example. I do not like to introduce new symbols and functions in
web2py. What if instead we make a

T(....,escape=False)?

with escape=True by default?

I can implement it easily.

Massimo

mdipierro

unread,
Jun 5, 2009, 10:55:57 PM6/5/09
to web2py Web Framework
the more I think about this the more I think that just using XML(T
("....")) where you need this is better.
escape=False would not work because it would return an XML object and
not a string. It would not be that explicit and confuse people.

Massimo

suiato

unread,
Jun 5, 2009, 11:19:27 PM6/5/09
to web2py Web Framework
Thanks for quick response, Massimo

On 6月6日, 午前11:49, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I see what you are doing but I do not like the fact that this promotes
> Tx to something special while that is a name that I made up as an
> example. I do not like to introduce new symbols and functions in
> web2py. What if instead we make a
>
> T(....,escape=False)?
>
> with escape=True by default?
>
> I can implement it easily.

Yes, that would be fine :-)

Then, if I want to make lines for translation a bit shorter, I could
use a lambda function in models
Tx = lambda *a: T(*a, escape=False)
right? or, would it be a bad practice?

> Massimo

--
Teru
Reply all
Reply to author
Forward
0 new messages