Bug and fix about languages.py (i18n)

8 views
Skip to first unread message

Iceberg

unread,
Feb 19, 2010, 8:09:09 AM2/19/10
to web2py-users
Hi there,

I upgrade from web2py 1.74.8 to latest trunk and then my admin can not
login normally, instead it generates error ticket. Tracing down the
bug, I found the reason and cure.

1. Since rev 146, web2py uses the browser's prefer language as the
default language setting. It is good. My browser's prefer language is
"zh-cn" (Chinese), it is also fine. But it happened that the current
Chinese language file, web2py\applications\admin\languages\zh-cn.py,
introduced by Jobinson in rev79 (http://code.google.com/p/web2py/
source/detail?r=063cc48352), is totally unacceptable. It contains the
unmatched-quotation syntax error, besides it does not finish
translation at all, many english strings are "translated" into empty
string, and some others are not translated precisely.

So the first suggestion, in my humble opinion, is to delete web2py
\applications\admin\languages\zh-cn.py. After all, a web2py developer/
user should be able to read all english words in admin app, so no need
to have a non-english version which is not likely to be always
synchronized with the official ones.


2. On the other hand, web2py's core code should be robust, to survive
a language file with syntax error inside (now we know it happens). So
the last line of function read_dict(filename) of web2py/gluon/
languages.py, should change into:

try:
return eval(lang_text)
except:
import logging
logging.exception('Syntax error in %s'%filename)
return {}


Regards,
Iceberg

mdipierro

unread,
Feb 19, 2010, 8:47:17 AM2/19/10
to web2py-users
I fixed what you suggested in trunk, please check it. I did not remove
zh-cn.py but I removed those lines that do not have a translation.

Massimo

Iceberg

unread,
Feb 20, 2010, 8:08:15 PM2/20/10
to web2py-users
The latest fix to language.py is fine. And your fix to zh-cn.py
reminds me one more trick, how about changing one more line of
read_dict() like this?

try:
return dict((k,v) for k,v in eval(lang_text).items()
if v) # to strip empty translation
except:
...


By the way, if you do feel reluctant to let go zh-cn.py, I can work
out a full translated version. But, although I know a "full set" of
strings to be translated can be obtained by clicking "update all
language" in admin, however there there is no "EDIT" page for appadmin
itself. So where can I start?

mdipierro

unread,
Feb 20, 2010, 8:28:37 PM2/20/10
to web2py-users

Iceberg

unread,
Feb 21, 2010, 1:51:23 AM2/21/10
to web2py-users, ice...@qq.com
During my translation process, I found something tricky, probably a
bug:

1. Open a tab in my Chrome to do the translate-submit-translate-submit
cycle
2. Open another tab, do something, such as testing another web2py app.
3. Switch back to tab #1, do a submit. Oops, all language pairs are
messed up. At this moment you have to cry if you don't have a backup.

Massimo might want to take a look about that.

Anyway, I finished the chinese translation. Will mail to Massimo in a
separate mail.

Reply all
Reply to author
Forward
0 new messages