[FIX] default languange set in partner according to database installation language.

bzr revid: ysa@tinyerp.com-20101230091734-0hrmb3fzpdy78w2v
This commit is contained in:
Yogesh Sakhreliya 2010-12-30 14:47:34 +05:30
parent 6112db95dd
commit 3ebc68162a
5 changed files with 76 additions and 57 deletions

View File

@ -28,6 +28,8 @@
<field name="translatable">True</field>
</record>
<function name="install_lang" model="res.lang"/>
<record id="ad" model="res.country">
<field name="name">Andorra, Principality of</field>
<field name="code">ad</field>

View File

@ -138,7 +138,7 @@ class res_partner(osv.osv):
'email': fields.related('address', 'email', type='char', size=240, string='E-mail'),
'company_id': fields.many2one('res.company', 'Company', select=1),
}
def _default_category(self, cr, uid, context={}):
if 'category_id' in context and context['category_id']:
return [context['category_id']]
@ -149,6 +149,7 @@ class res_partner(osv.osv):
'customer': lambda *a: 1,
'category_id': _default_category,
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'res.partner', context=c),
'lang': lambda self, cr, uid, context: context.get('lang',False) or tools.config.get('lang', False)
}
def copy(self, cr, uid, id, default={}, context={}):
name = self.read(cr, uid, [id], ['name'])[0]['name']

View File

@ -24,10 +24,60 @@ from locale import localeconv
import tools
from tools.safe_eval import safe_eval as eval
from tools.translate import _
import locale
import logging
class lang(osv.osv):
_name = "res.lang"
_description = "Languages"
def install_lang(self, cr, uid, **args):
self.load_lang(cr, uid, tools.config.get('lang'))
return True
def load_lang(self, cr, uid, lang, lang_name=None):
# create the language with locale information
fail = True
logger = logging.getLogger('i18n')
iso_lang = tools.get_iso_codes(lang)
for ln in tools.get_locales(lang):
try:
locale.setlocale(locale.LC_ALL, str(ln))
fail = False
break
except locale.Error:
continue
if fail:
lc = locale.getdefaultlocale()[0]
msg = 'Unable to get information for locale %s. Information from the default locale (%s) have been used.'
logger.warning(msg, lang, lc)
if not lang_name:
lang_name = tools.get_languages().get(lang, lang)
def fix_xa0(s):
if s == '\xa0':
return '\xc2\xa0'
return s
lang_info = {
'code': lang,
'iso_code': iso_lang,
'name': lang_name,
'translatable': 1,
'date_format' : str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')),
'time_format' : str(locale.nl_langinfo(locale.T_FMT)),
'decimal_point' : fix_xa0(str(locale.localeconv()['decimal_point'])),
'thousands_sep' : fix_xa0(str(locale.localeconv()['thousands_sep'])),
}
try:
self.create(cr, uid, lang_info)
finally:
tools.resetlocale()
return True
def _get_default_date_format(self,cursor,user,context={}):
return '%m/%d/%Y'
@ -69,7 +119,7 @@ class lang(osv.osv):
thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
decimal_point = lang_obj.decimal_point
grouping = lang_obj.grouping
return (grouping, thousands_sep, decimal_point)
return (grouping, thousands_sep, decimal_point)
def write(self, cr, uid, ids, vals, context=None):
for lang_id in ids :
@ -95,19 +145,19 @@ class lang(osv.osv):
def _group(self, cr, uid, ids, s, monetary=False, grouping=False, thousands_sep=''):
grouping = eval(grouping)
if not grouping:
return (s, 0)
result = ""
seps = 0
spaces = ""
if s[-1] == ' ':
sp = s.find(' ')
spaces = s[sp:]
s = s[:sp]
while s and grouping:
# if grouping is -1, we are done
if grouping[0] == -1:
@ -139,7 +189,7 @@ class lang(osv.osv):
if percent[0] != '%':
raise ValueError("format() must be given exactly one %char format specifier")
lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0], monetary)
lang_grouping, thousands_sep, decimal_point = self._lang_data_get(cr, uid, ids[0], monetary)
formatted = percent % value
# floats and decimal ints need special action!

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
##############################################################################
#
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
@ -15,7 +15,7 @@
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
@ -50,8 +50,8 @@ class db(netsvc.ExportService):
self._pg_psw_env_var_is_set = False # on win32, pg_dump need the PGPASSWORD env var
def dispatch(self, method, auth, params):
if method in [ 'create', 'get_progress', 'drop', 'dump',
'restore', 'rename',
if method in [ 'create', 'get_progress', 'drop', 'dump',
'restore', 'rename',
'change_admin_password', 'migrate_databases' ]:
passwd = params[0]
params = params[1:]
@ -64,7 +64,7 @@ class db(netsvc.ExportService):
raise KeyError("Method not found: %s" % method)
fn = getattr(self, 'exp_'+method)
return fn(*params)
def new_dispatch(self,method,auth,params):
pass
def _create_empty_database(self, name):
@ -93,6 +93,7 @@ class db(netsvc.ExportService):
serv.actions[id]['progress'] = 0
cr = sql_db.db_connect(db_name).cursor()
tools.init_db(cr)
tools.config['lang'] = lang
cr.commit()
cr.close()
cr = None
@ -392,7 +393,7 @@ class common(_ObjectService):
security.check_super(passwd)
else:
raise Exception("Method not found: %s" % method)
fn = getattr(self, 'exp_'+method)
return fn(*params)
@ -568,7 +569,7 @@ GNU Public Licence.
def exp_check_connectivity(self):
return bool(sql_db.db_connect('template1'))
def exp_get_os_time(self):
return os.times()
@ -598,7 +599,7 @@ class objects_proxy(netsvc.ExportService):
res = fn(db, uid, *params)
return res
def new_dispatch(self,method,auth,params):
pass
@ -634,7 +635,7 @@ class wizard(netsvc.ExportService):
fn = getattr(self, 'exp_'+method)
res = fn(db, uid, *params)
return res
def new_dispatch(self,method,auth,params):
pass
@ -697,7 +698,7 @@ class report_spool(netsvc.ExportService):
res = fn(db, uid, *params)
return res
def new_dispatch(self,method,auth,params):
pass
@ -728,7 +729,7 @@ class report_spool(netsvc.ExportService):
self._reports[id]['format'] = format
self._reports[id]['state'] = True
except Exception, exception:
tb = sys.exc_info()
tb_s = "".join(traceback.format_exception(*tb))
logger = netsvc.Logger()

View File

@ -346,7 +346,7 @@ class TinyPoFile(object):
if name is None:
if not fuzzy:
self.warn('Missing "#:" formated comment at line %d for the following source:\n\t%s',
self.warn('Missing "#:" formated comment at line %d for the following source:\n\t%s',
self.cur_line(), source[:30])
return self.next()
return type, name, res_id, source, trad
@ -537,9 +537,9 @@ def trans_generate(lang, modules, dbname=None):
query = 'SELECT name, model, res_id, module' \
' FROM ir_model_data'
query_models = """SELECT m.id, m.model, imd.module
FROM ir_model AS m, ir_model_data AS imd
query_models = """SELECT m.id, m.model, imd.module
FROM ir_model AS m, ir_model_data AS imd
WHERE m.id = imd.res_id AND imd.model = 'ir.model' """
if 'all_installed' in modules:
@ -841,42 +841,7 @@ def trans_load_data(db_name, fileobj, fileformat, lang, lang_name=None, verbose=
if not ids:
# lets create the language with locale information
fail = True
for ln in get_locales(lang):
try:
locale.setlocale(locale.LC_ALL, str(ln))
fail = False
break
except locale.Error:
continue
if fail:
lc = locale.getdefaultlocale()[0]
msg = 'Unable to get information for locale %s. Information from the default locale (%s) have been used.'
logger.warning(msg, lang, lc)
if not lang_name:
lang_name = tools.get_languages().get(lang, lang)
def fix_xa0(s):
if s == '\xa0':
return '\xc2\xa0'
return s
lang_info = {
'code': lang,
'iso_code': iso_lang,
'name': lang_name,
'translatable': 1,
'date_format' : str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y')),
'time_format' : str(locale.nl_langinfo(locale.T_FMT)),
'decimal_point' : fix_xa0(str(locale.localeconv()['decimal_point'])),
'thousands_sep' : fix_xa0(str(locale.localeconv()['thousands_sep'])),
}
try:
lang_obj.create(cr, uid, lang_info)
finally:
resetlocale()
lang_obj.load_lang(cr, 1, lang=lang, lang_name=lang_name)
# now, the serious things: we read the language file