Setting the default translation table

275 views
Skip to first unread message

voltron

unread,
Dec 4, 2007, 8:36:59 AM12/4/07
to Gluon Web Framework
How does one :

1. Set the default language for the site
2. Specify which language table to use for the translation, return
T("Hello World") is supposed to translate, but to what language? I
have set up 2 translation tables, en-en, de-de.

Massimo Di Pierro

unread,
Dec 4, 2007, 8:55:13 AM12/4/07
to gl...@googlegroups.com
When a browser requests a page, the browser sends an 'Accept-
Language: en' in the header. Therefore it is the client's browse that
decides which translation to use. If the client does not say or if it
asks a language that is not supported the original strings will be
used unless in the controller you do something like

if not request.env.accept_languge: request.env.accept_language='de-de'

and now you default to german.

You can use other conditions to set the accept_language (for example
ask the user and store the preference in session). That is up to you.

Notice that it and it-it are treated as different languages so to
support italian you need both.

Massimo

voltron

unread,
Dec 4, 2007, 9:24:27 AM12/4/07
to Gluon Web Framework
Hmm, I have not got it to work strangely

## CODE

def trans():
#return dict(message = "Hello World!")
request.env.accept_language='de-de'
#if not request.env.accept_languge:
request.env.accept_language='de-de'
return T("Hello World")


This still outputs "Hello World" even though I have this in my de-
de.py file:

{
'Hello World':'Hallo Welt',
'Hello World!':'Hallo Welt!',

Massimo Di Pierro

unread,
Dec 4, 2007, 6:06:47 PM12/4/07
to gl...@googlegroups.com
My mistake, it should be

def trans():
request.env.http_accept_language='de-de'
import gluon.languages
gluon.languages.translator.__init__(T,request) # reloads the
language file


return T("Hello World")

this should work assuming you have a language de-de.py and you have a
translation string for "Hello World". This will override the
http_accept_language unless you check if you have it.

Anyway, this is ugly, I need to come up with a better way, something
like

def trans():
T.defaults_to('de-de') // not yet implemented


return T("Hello World")

Massimo

> def trans():


> request.env.accept_language='de-de'
> return T("Hello World")

Massimo Di Pierro

unread,
Dec 4, 2007, 6:28:51 PM12/4/07
to gl...@googlegroups.com
One more thing.... this will only change the language from the moment
it is executed.
That means stuff in the model will not be translated according to 'de-
de'.

Anyway my feeling is that it should really be the client's browser to
set the language, not the application.

Massimo

voltron

unread,
Dec 5, 2007, 3:21:03 AM12/5/07
to Gluon Web Framework
Thanks Massimo for the tip. There has been several discussions about
this in the internet, many have come to the conclusion that it is
annoying. There were examples of people coming from multi-lingual
countries that had problems with this, examples:

Belgium -> French, Flämisch, English which language is to be used,
not all the Belgians speak French or vice-versa
Swizerland -> Italian, French German
Canada -> French English
Luxemburg....
...

I myself, have most of my software in English, I dislike applications
that force me to decide which language the user interface should be
in.
Reply all
Reply to author
Forward
0 new messages