There was a bug in language selection with web2py:

To reproduce:

- in Firefox (can do in other browsers), open Edit =>Preferces =>
Languages   and choose multiple languages;

What happens:

The implicitly default language ('en-us') is never selected when there are
multiple language choices in your browser; instead, the FIRST LANGUAGE from
your browser preferences list which has a translation file in your
application/myapp/languages directory is used.

Expected Behavior:

First language in your browser preferences list of languages for which there
is a "translation" will be selected (INCLUDING the default language of the
site / app - that is, the default language the strings are written in).

The attached patch fixes this (makes DEFAULT_LANGUAGE  explicit).

FUTURE WORK:

You can now change the default language of your site, by changing the
DEFAULT_LANGUAGE setting in gluon/languages.py.
A Better setup will be to have your app (say, in models/db.py or
models/0.py) be able to set the DEFAULT_LANGUAGE for its request.

ANALYSIS:
What is currently preventing this:   the environment for request (and
therefore the translator, and default language...) is setup BEFORE the
application directory is read for the request.

One possible solution:
Store the default translator instance per language, have a site default, and
allow "switching", or lazy instantiation on first encounter of a "new"
default language (something like this in models/db.py:

T.default_language='it-it'

This will have to work with multiple languages set in your browser.
Comments / discussion of this part welcomed.

In the meantime, here is a patch to correct the current bug.

Regards,
- Yarko

On Thu, Nov 19, 2009 at 1:19 AM, szimszon <[email protected]> wrote:

>
> Tnx.
>
> On Nov 18, 9:03 pm, mdipierro <[email protected]> wrote:
> > I think you found a bug. I will watch the video again.
> >
> > On Nov 18, 2:00 pm, szimszon <[email protected]> wrote:
> >
> > > I expect a different behavior or I don't understand how translation
> > > works :-o
> >
> > > What is different if there is T.force and T.current... and no.
> >
> > > If there is no T.force... just Italian language preferred by the
> > > browser, your example text is translated to Italian and the flash
> > > messages in the top right corner (so Italian translation is present
> > > for the flash message). 4:27min
> > > If there is T.force... only your example message is translated to
> > > Italian the flash not. 6:20min
> > > Is it to be expected?
> >
> > > On Nov 18, 8:43 pm, mdipierro <[email protected]> wrote:
> >
> > > > I do not understand the comment. Did you expect a different behavior
> > > > than shown in the video or you cannot reproduce the behavior shown in
> > > > the video?
> >
> > > > On Nov 18, 7:07 am, szimszon <[email protected]> wrote:
> >
> > > > > Hm. I look at the video and,
> >
> > > > > First time you add language "it" to the brower preferences and
> moved
> > > > > up then the flash is translated to Italian in the web page.
> > > > > But after the T.force thing and Italian was the browser preferred
> one
> > > > > the flash was in English...
> >
> > > > > On Nov 18, 1:29 am, mdipierro <[email protected]> wrote:
> >
> > > > > > Perhaps this can help.
> >
> > > > > >http://www.vimeo.com/7520812
> >
> > > > > > Massimo
> >
> > > > > > On Nov 17, 4:20 pm, jensmun <[email protected]> wrote:
> >
> > > > > > > Hi,
> >
> > > > > > > Thanks for this everybody. Looks really cool.
> >
> > > > > > > I've been playing with this tonight for the first time and
> everything
> > > > > > > was fine until I got to internationalization. It doesn't seem
> to
> > > > > > > respond at all or randomly to me changing language on FF3.5.5
> and OSX
> > > > > > > 10.5.
> >
> > > > > > > Nothing changes - and I've checkedhttp://
> www.cs.tut.fi/cgi-bin/run/~jkorpela/lang.cgi<http://www.cs.tut.fi/cgi-bin/run/%7Ejkorpela/lang.cgi>
> > > > > > > to make sure I'm on eg. spanish or italian.
> >
> > > > > > > Is this something that is wrong on my side?
> >
> > > > > > > Thanks, Jens
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

=== modified file 'gluon/languages.py'
--- gluon/languages.py	2009-11-08 21:02:16 +0000
+++ gluon/languages.py	2009-11-20 21:26:52 +0000
@@ -7,6 +7,19 @@
 License: GPL v2
 """
 
+# The default language assumed for application strings;
+#  Anything else will be translated, as needed.
+#  This is read only once on web2py startup, so sites need to
+#  override this to match the
+#  language used in strings on their site in app sources;
+#  would be nice to reset this per app, but will need to 
+#  modify structure so that there is some match between app language,
+#  and Translator instantiation.  Will need to think about how
+#  to best accomplish this (by app DEFAULT_LANGUAGE? array of Translator
+#  instances, initialized once at first use perhaps...)
+#  For now, this works:
+DEFAULT_LANGUAGE='en-us'
+
 import sys
 import os
 import re
@@ -105,7 +118,7 @@
 
     def __init__(self, request):
         self.folder = request.folder
-        self.current_languages = []
+        self.current_languages = [DEFAULT_LANGUAGE]
         self.accepted_language = None
         self.language_file = None
         self.http_accept_language = request.env.http_accept_language
@@ -154,7 +167,7 @@
         return mt
 
 
-def findT(path, language='en-us'):
+def findT(path, language=DEFAULT_LANGUAGE):
     """
     must be run by the admin app
     """

Reply via email to