Simultaneous multi-language system.

89 views
Skip to first unread message

demetrio

unread,
Jul 13, 2011, 1:22:23 PM7/13/11
to web2py-users
Hi everyone, i don't know if "Simultaneous multi-language system" is
the correct way to say what i need... i'll explain myself.

I'm developing an application that by request of our customer, needs
to have 2 languages at the same time. For example, if this app were in
spanish and english, in the navigator should appear something like:

Casa / House

In the view we want to do something like this

{{=T("House", "es-es")}} / {{=T("House", "en-en")}}

But i don't know if web2py can permit to do this or something like
that.

I was thinking of writing a function like this:

def MultiT(text,separator=" / "):
T.force("es-es")
ret_text = T(text)
T.force("en-en")
ret_text += separator + T(text)
return ret_text

But it does not work. Also, do not know how this affects the system
when updating the language files with the strings to translate (now
the files are updated automatically when pressing the "update
languages" button in admin, and I guess that it would make it on run
time.

Any sugestions?

Best regards
Daniel

pbreit

unread,
Jul 13, 2011, 6:21:29 PM7/13/11
to web...@googlegroups.com
Wow, that's a weird request. I suspect it is going to be easiest just to program the two variations without T().

Christopher Steel

unread,
Jul 20, 2011, 5:07:37 PM7/20/11
to web...@googlegroups.com
On the one hand If you only want to display two languages at the same time at all times then translations are not required.

If on the other hand you want people to be able to switch between languages like this http://voiceofaccess.org ,  then translations are required but displaying both languages at the same time is not required because people can switch languages on the fly.


C.


Daniel Gonzalez Zaballos

unread,
Jul 20, 2011, 5:29:10 PM7/20/11
to web...@googlegroups.com
The thing is that in Spain, there are some bilingual regions with their own language besides the official language. Sometimes they require that an app be in the main language (spanish) and their specifical language and the capatility to switch between them, and rarely (this case), have both simultaneosly. If in the future, we sell the same app to a customer in a different region with its own language, we will need to revise all the code to find the literals and traduce them, and worse, have to maintain different versions of the same application with the only difference of the language.

That's one of the reasons why we are looking for an optimal solution, like a way to extend the T() object.

Thanks for your time.
Best regards
Daniel


2011/7/20 Christopher Steel <chris...@gmail.com>

Anthony

unread,
Jul 20, 2011, 6:53:02 PM7/20/11
to web...@googlegroups.com
I think there are a few possibilities. First, your MultiT function could work, but you'd have to use str(T(text)) instead of T(text). The reason is that T() returns a lazyT object, not the translated string (it isn't translated until rendering). You can force the translation by calling the lazyT.__str__ method via str(T(text)).
 
Another option is to define your own T() objects for each language and force them to use the specific language. For example:
 
In a model file:
from gluon.languages import translator
enT=translator(request)
enT.force('en-en')
esT=translator(request)
esT.force('es-es')
 
In a view:
{{=esT('House')}} / {{=enT('House')}}
 
 
It would probably be easy to abstract the above by defining a class that stores multiple T objects and lets you easily add additional ones.
 
A third option might be to create a special multi-language translation file. For example, you could create a file called es-en.py, which could include translations such as:
 
'House': 'Casa / House'
 
 
Hope that helps.
 
Anthony

Massimo Di Pierro

unread,
Jul 21, 2011, 1:13:16 AM7/21/11
to web2py-users
I think for now Anthony's proposal is the way to go. Open a ticket in
google code and we can think of other options.

Daniel Gonzalez Zaballos

unread,
Jul 21, 2011, 4:16:01 AM7/21/11
to web...@googlegroups.com
i'll start with the Anthony suggestion.
I've opened the ticket:

Thank you to everybody

2011/7/21 Massimo Di Pierro <massimo....@gmail.com>

jamarcer

unread,
Jul 22, 2011, 4:52:43 AM7/22/11
to web2py-users
Hello:

I have added a comment to the ticket, explaining an approach to this
issue.

It is based on Anthony's proposal, as demetrio said :).

I am demetrio's companion, so I will test this approach, or others
possible solutions.

Regards.

Link to ticket: http://code.google.com/p/web2py/issues/detail?id=342


On 21 jul, 10:16, Daniel Gonzalez Zaballos <dgzabal...@gmail.com>
wrote:
> i'll start with the Anthony suggestion.
> I've opened the ticket:http://code.google.com/p/web2py/issues/detail?id=342
>
> Thank you to everybody
>
> 2011/7/21 Massimo Di Pierro <massimo.dipie...@gmail.com>

jamarcer

unread,
Jul 22, 2011, 5:52:14 AM7/22/11
to web2py-users
Hello:

I have added a comment to the ticket:

http://code.google.com/p/web2py/issues/detail?id=342

It is an approach to the issue, based in Anthony's proposal: a class
that stores multiple T objects.

I am demetrio's companion. We develop the same application, but we
have different roles :), so I will test this approach, and other
possible solutions.

Regards.

On 21 jul, 10:16, Daniel Gonzalez Zaballos <dgzabal...@gmail.com>
wrote:
> i'll start with the Anthony suggestion.
> I've opened the ticket:http://code.google.com/p/web2py/issues/detail?id=342
>
> Thank you to everybody
>
> 2011/7/21 Massimo Di Pierro <massimo.dipie...@gmail.com>

Massimo Di Pierro

unread,
Jul 23, 2011, 3:43:43 AM7/23/11
to web2py-users
There is a solution in trunk. Please check it:
http://code.google.com/p/web2py/issues/detail?id=342


print T("hello") #defualt
print T("hello", language="it-it") #etc etc

Jesús Martínez

unread,
Jul 23, 2011, 5:07:15 AM7/23/11
to web...@googlegroups.com
It works.

Thanks Massimo.

2011/7/23 Massimo Di Pierro <massimo....@gmail.com>
Reply all
Reply to author
Forward
0 new messages