[FIX] default languange set in partner according to database installation language.
bzr revid: ysa@tinyerp.com-20101230091734-0hrmb3fzpdy78w2v
This commit is contained in:
parent
6112db95dd
commit
3ebc68162a
|
@ -28,6 +28,8 @@
|
||||||
<field name="translatable">True</field>
|
<field name="translatable">True</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<function name="install_lang" model="res.lang"/>
|
||||||
|
|
||||||
<record id="ad" model="res.country">
|
<record id="ad" model="res.country">
|
||||||
<field name="name">Andorra, Principality of</field>
|
<field name="name">Andorra, Principality of</field>
|
||||||
<field name="code">ad</field>
|
<field name="code">ad</field>
|
||||||
|
|
|
@ -138,7 +138,7 @@ class res_partner(osv.osv):
|
||||||
'email': fields.related('address', 'email', type='char', size=240, string='E-mail'),
|
'email': fields.related('address', 'email', type='char', size=240, string='E-mail'),
|
||||||
'company_id': fields.many2one('res.company', 'Company', select=1),
|
'company_id': fields.many2one('res.company', 'Company', select=1),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _default_category(self, cr, uid, context={}):
|
def _default_category(self, cr, uid, context={}):
|
||||||
if 'category_id' in context and context['category_id']:
|
if 'category_id' in context and context['category_id']:
|
||||||
return [context['category_id']]
|
return [context['category_id']]
|
||||||
|
@ -149,6 +149,7 @@ class res_partner(osv.osv):
|
||||||
'customer': lambda *a: 1,
|
'customer': lambda *a: 1,
|
||||||
'category_id': _default_category,
|
'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),
|
'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={}):
|
def copy(self, cr, uid, id, default={}, context={}):
|
||||||
name = self.read(cr, uid, [id], ['name'])[0]['name']
|
name = self.read(cr, uid, [id], ['name'])[0]['name']
|
||||||
|
|
|
@ -24,10 +24,60 @@ from locale import localeconv
|
||||||
import tools
|
import tools
|
||||||
from tools.safe_eval import safe_eval as eval
|
from tools.safe_eval import safe_eval as eval
|
||||||
from tools.translate import _
|
from tools.translate import _
|
||||||
|
import locale
|
||||||
|
import logging
|
||||||
|
|
||||||
class lang(osv.osv):
|
class lang(osv.osv):
|
||||||
_name = "res.lang"
|
_name = "res.lang"
|
||||||
_description = "Languages"
|
_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={}):
|
def _get_default_date_format(self,cursor,user,context={}):
|
||||||
return '%m/%d/%Y'
|
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']
|
thousands_sep = lang_obj.thousands_sep or conv[monetary and 'mon_thousands_sep' or 'thousands_sep']
|
||||||
decimal_point = lang_obj.decimal_point
|
decimal_point = lang_obj.decimal_point
|
||||||
grouping = lang_obj.grouping
|
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):
|
def write(self, cr, uid, ids, vals, context=None):
|
||||||
for lang_id in ids :
|
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=''):
|
def _group(self, cr, uid, ids, s, monetary=False, grouping=False, thousands_sep=''):
|
||||||
grouping = eval(grouping)
|
grouping = eval(grouping)
|
||||||
|
|
||||||
if not grouping:
|
if not grouping:
|
||||||
return (s, 0)
|
return (s, 0)
|
||||||
|
|
||||||
result = ""
|
result = ""
|
||||||
seps = 0
|
seps = 0
|
||||||
spaces = ""
|
spaces = ""
|
||||||
|
|
||||||
if s[-1] == ' ':
|
if s[-1] == ' ':
|
||||||
sp = s.find(' ')
|
sp = s.find(' ')
|
||||||
spaces = s[sp:]
|
spaces = s[sp:]
|
||||||
s = s[:sp]
|
s = s[:sp]
|
||||||
|
|
||||||
while s and grouping:
|
while s and grouping:
|
||||||
# if grouping is -1, we are done
|
# if grouping is -1, we are done
|
||||||
if grouping[0] == -1:
|
if grouping[0] == -1:
|
||||||
|
@ -139,7 +189,7 @@ class lang(osv.osv):
|
||||||
if percent[0] != '%':
|
if percent[0] != '%':
|
||||||
raise ValueError("format() must be given exactly one %char format specifier")
|
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
|
formatted = percent % value
|
||||||
# floats and decimal ints need special action!
|
# floats and decimal ints need special action!
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||||
#
|
#
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
# GNU Affero General Public License for more details.
|
# GNU Affero General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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
|
self._pg_psw_env_var_is_set = False # on win32, pg_dump need the PGPASSWORD env var
|
||||||
|
|
||||||
def dispatch(self, method, auth, params):
|
def dispatch(self, method, auth, params):
|
||||||
if method in [ 'create', 'get_progress', 'drop', 'dump',
|
if method in [ 'create', 'get_progress', 'drop', 'dump',
|
||||||
'restore', 'rename',
|
'restore', 'rename',
|
||||||
'change_admin_password', 'migrate_databases' ]:
|
'change_admin_password', 'migrate_databases' ]:
|
||||||
passwd = params[0]
|
passwd = params[0]
|
||||||
params = params[1:]
|
params = params[1:]
|
||||||
|
@ -64,7 +64,7 @@ class db(netsvc.ExportService):
|
||||||
raise KeyError("Method not found: %s" % method)
|
raise KeyError("Method not found: %s" % method)
|
||||||
fn = getattr(self, 'exp_'+method)
|
fn = getattr(self, 'exp_'+method)
|
||||||
return fn(*params)
|
return fn(*params)
|
||||||
|
|
||||||
def new_dispatch(self,method,auth,params):
|
def new_dispatch(self,method,auth,params):
|
||||||
pass
|
pass
|
||||||
def _create_empty_database(self, name):
|
def _create_empty_database(self, name):
|
||||||
|
@ -93,6 +93,7 @@ class db(netsvc.ExportService):
|
||||||
serv.actions[id]['progress'] = 0
|
serv.actions[id]['progress'] = 0
|
||||||
cr = sql_db.db_connect(db_name).cursor()
|
cr = sql_db.db_connect(db_name).cursor()
|
||||||
tools.init_db(cr)
|
tools.init_db(cr)
|
||||||
|
tools.config['lang'] = lang
|
||||||
cr.commit()
|
cr.commit()
|
||||||
cr.close()
|
cr.close()
|
||||||
cr = None
|
cr = None
|
||||||
|
@ -392,7 +393,7 @@ class common(_ObjectService):
|
||||||
security.check_super(passwd)
|
security.check_super(passwd)
|
||||||
else:
|
else:
|
||||||
raise Exception("Method not found: %s" % method)
|
raise Exception("Method not found: %s" % method)
|
||||||
|
|
||||||
fn = getattr(self, 'exp_'+method)
|
fn = getattr(self, 'exp_'+method)
|
||||||
return fn(*params)
|
return fn(*params)
|
||||||
|
|
||||||
|
@ -568,7 +569,7 @@ GNU Public Licence.
|
||||||
|
|
||||||
def exp_check_connectivity(self):
|
def exp_check_connectivity(self):
|
||||||
return bool(sql_db.db_connect('template1'))
|
return bool(sql_db.db_connect('template1'))
|
||||||
|
|
||||||
def exp_get_os_time(self):
|
def exp_get_os_time(self):
|
||||||
return os.times()
|
return os.times()
|
||||||
|
|
||||||
|
@ -598,7 +599,7 @@ class objects_proxy(netsvc.ExportService):
|
||||||
res = fn(db, uid, *params)
|
res = fn(db, uid, *params)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def new_dispatch(self,method,auth,params):
|
def new_dispatch(self,method,auth,params):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -634,7 +635,7 @@ class wizard(netsvc.ExportService):
|
||||||
fn = getattr(self, 'exp_'+method)
|
fn = getattr(self, 'exp_'+method)
|
||||||
res = fn(db, uid, *params)
|
res = fn(db, uid, *params)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def new_dispatch(self,method,auth,params):
|
def new_dispatch(self,method,auth,params):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -697,7 +698,7 @@ class report_spool(netsvc.ExportService):
|
||||||
res = fn(db, uid, *params)
|
res = fn(db, uid, *params)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def new_dispatch(self,method,auth,params):
|
def new_dispatch(self,method,auth,params):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -728,7 +729,7 @@ class report_spool(netsvc.ExportService):
|
||||||
self._reports[id]['format'] = format
|
self._reports[id]['format'] = format
|
||||||
self._reports[id]['state'] = True
|
self._reports[id]['state'] = True
|
||||||
except Exception, exception:
|
except Exception, exception:
|
||||||
|
|
||||||
tb = sys.exc_info()
|
tb = sys.exc_info()
|
||||||
tb_s = "".join(traceback.format_exception(*tb))
|
tb_s = "".join(traceback.format_exception(*tb))
|
||||||
logger = netsvc.Logger()
|
logger = netsvc.Logger()
|
||||||
|
|
|
@ -346,7 +346,7 @@ class TinyPoFile(object):
|
||||||
|
|
||||||
if name is None:
|
if name is None:
|
||||||
if not fuzzy:
|
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])
|
self.cur_line(), source[:30])
|
||||||
return self.next()
|
return self.next()
|
||||||
return type, name, res_id, source, trad
|
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' \
|
query = 'SELECT name, model, res_id, module' \
|
||||||
' FROM ir_model_data'
|
' FROM ir_model_data'
|
||||||
|
|
||||||
query_models = """SELECT m.id, m.model, imd.module
|
query_models = """SELECT m.id, m.model, imd.module
|
||||||
FROM ir_model AS m, ir_model_data AS imd
|
FROM ir_model AS m, ir_model_data AS imd
|
||||||
WHERE m.id = imd.res_id AND imd.model = 'ir.model' """
|
WHERE m.id = imd.res_id AND imd.model = 'ir.model' """
|
||||||
|
|
||||||
if 'all_installed' in modules:
|
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:
|
if not ids:
|
||||||
# lets create the language with locale information
|
# lets create the language with locale information
|
||||||
fail = True
|
lang_obj.load_lang(cr, 1, lang=lang, lang_name=lang_name)
|
||||||
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()
|
|
||||||
|
|
||||||
|
|
||||||
# now, the serious things: we read the language file
|
# now, the serious things: we read the language file
|
||||||
|
|
Loading…
Reference in New Issue