Add code for locale langauge translation

bzr revid: apa@tinyerp.com-20090120130729-y3wwgpy2eoo81gxn
This commit is contained in:
Apa (Open ERP) 2009-01-20 18:37:29 +05:30
parent eae277fbb5
commit 12174cedb5
1 changed files with 33 additions and 2 deletions

View File

@ -33,6 +33,7 @@ import mx.DateTime as mxdt
import tempfile
import tarfile
import codecs
import locale
class UNIX_LINE_TERMINATOR(csv.excel):
@ -520,8 +521,25 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=
try:
uid = 1
cr = pooler.get_db(db_name).cursor()
ids = lang_obj.search(cr, uid, [('code','=',lang)])
lc, encoding = locale.getdefaultlocale()
if not encoding:
encoding = 'UTF-8'
if encoding == 'utf':
encoding = 'UTF-8'
if encoding == 'cp1252':
encoding= '1252'
try:
if os.name == 'nt':
locale.setlocale(locale.LC_ALL, str(_LOCALE2WIN32.get(lang, lang) + '.' + encoding))
else:
locale.setlocale(locale.LC_ALL, str(lang + '.' + encoding))
except Exception:
netsvc.Logger().notifyChannel(' ', netsvc.LOG_WARNING,
'unable to set locale "%s"' % (lang))
locale.setlocale(locale.LC_ALL, str('en_US' + '.' + encoding))
if not ids:
if not lang_name:
lang_name=lang
@ -531,9 +549,22 @@ def trans_load_data(db_name, fileobj, fileformat, lang, strict=False, lang_name=
'code': lang,
'name': lang_name,
'translatable': 1,
'date_format' : locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'),
'time_format' : locale.nl_langinfo(locale.T_FMT),
'grouping' : [],
'decimal_point' : locale.nl_langinfo(locale.RADIXCHAR),
'thousands_sep' : locale.nl_langinfo(locale.THOUSEP)
})
else:
lang_obj.write(cr, uid, ids, {'translatable':1})
lang_obj.write(cr, uid, ids, {'translatable':1,
'date_format' : locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'),
'time_format' : locale.nl_langinfo(locale.T_FMT),
'grouping' : [],
'decimal_point' : locale.nl_langinfo(locale.RADIXCHAR),
'thousands_sep' : locale.nl_langinfo(locale.THOUSEP)
})
locale.resetlocale(locale.LC_ALL)
lang_ids = lang_obj.search(cr, uid, [])
langs = lang_obj.read(cr, uid, lang_ids)
ls = map(lambda x: (x['code'],x['name']), langs)