On Dec 15, 11:23 am, Andrea Cappelli <[email protected]> wrote:
> Il giorno mar, 15/12/2009 alle 07.37 -0800, mdipierro ha scritto:
>
> > We had a long discussion about this. We had a minor change of behavior
> > that basically assumes the default language is English. We did not
> > make such assumptions before. I opposed such change but apparently I
> > was the only one and everybody else spoke for it. Now you have to be
> > explicit about the fact that your language is Italian (somewhere
> > before you use T):

We need to be careful when describing this:

What web2py DID NOT do before is initialize (for translation) what the
language of the source (the application)  was.

This caused problems when viewing sites if the client had a list of
acceptable delivery languages.

The solution was to be sure web2py had SOME DEFAULT definition for
what the language of the strings within applications is (so that the
correct translation texts would be selected).

Since web2py is written in Chicago, IL,  the default language declared
was (naturally)  'en'.

>
> >    T.current_languages=['it','it-it']
>
> Thank you, using your suggestion I found the solution which consist in
> calling the following function in every controller:

You do not need to do this in every controller (although you _can_,
unless you have a language course as the application, you probably do
not _want_ to!)

If you put  the line Massimo suggests in your models folder (you can
put it in db.py, or you can create a file, something like
"application_language.py" - as long as this is defined in _some_ model
file, it will define for all your controllers).

>
> def set_default_language(T, request):
>     # We assume the project is in italian language
>     T.current_languages = ['it','it-it']

This is a unfortunate naming of this variable - it is confusing...
I should have named it T.app_language (and it should have only been a
single language, as it makes no sense that a string from the source of
your application is simultaneously _two_ languages!).      Please
forgive us, forgive _me_ for the confusion (I submitted the patch, and
should have made things clearer).

In any case, you should - in model/db.py - simply declare what the
default language of the source of the application is.

>
>     # Get choosen language from the user    
>     lang = request.env.http_accept_language.split(",")[0]
>
>     if lang.find('-') != -1:
>         lang = lang.split('-')[0]
>
>     T.force(lang)

If you properly make the setting I mention above, the translation
mechanism will do this - YOU should not be doing this (somehow I think
this code is then directly competing with T('some string') - and I
think the T() code will just repeatedly override at each request what
you have here.... in any case, it is not a good thing, do not do this
here.

I hope this helps.

Regards,
- Yarko

>
> > This may be a concurrency issue. Make sure you lock the file while
> > writing in it from a your own python program.
>
> You are right, I think the problem is that in the earlier version there
> were no lock on language file.
>
> A diff from my revision (992) and the latest (1458) shows that you
> change the way the language file is opened
>
> def write_dict(filename, contents):
> -    f = open(filename, 'w')
> -    f.write('{\n')
> +    fp = open(filename, 'w')
> +    portalocker.lock(fp, portalocker.LOCK_EX)
> +    fp.write('# coding: utf8\n{\n')
>      for key in sorted(contents):
> -        f.write('%s: %s,\n' % (repr(key), repr(contents[key])))
> -    f.write('}\n')
> -    f.close()
> +        fp.write('%s: %s,\n' % (repr(key), repr(contents[key])))
> +    fp.write('}\n')
> +    portalocker.unlock(fp)
> +    fp.close()
>
> So I needed the latest revision to fix the main issue, but without the
> fix you suggest me I wasn't able to get it work
>
> Thank you very much

--

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.


Reply via email to