Workaround for i18n bug

1 view
Skip to first unread message

Victor

unread,
Nov 9, 2009, 6:35:12 AM11/9/09
to TurboGears
I notice that TurboGears2 can't pick correct language automatically by
languages given by browser. For example, the acceptable languages
setting of my browser is [zh-tw, en-us, en]. I do provide zh_TW in my
i18n folder, it works fine if I set the language to zh_TW. But most of
browser write the language in zh-tw form, gettext can't recognize
that, so it just fallback to en. I wrote a workaround to fix problem:

# XXX work around for languages in dash form problem
# gettext can't recognize that form, for example, it can recognize
# 'zh_tw' rather than zh-tw, so we need to replace all dash to
# underscore to fix this problem
import tg.i18n
oldFunc = tg.i18n.set_temporary_lang
def newSetTemporaryLang(languages):
languages = map(lambda lang: lang.replace('-', '_'),
languages)
return oldFunc(languages)
tg.i18n.set_temporary_lang = newSetTemporaryLang

Posted here:
http://trac.turbogears.org/ticket/2406
Reply all
Reply to author
Forward
0 new messages