ir.module: use pythonic logging, addons api

bzr revid: p_christ@hol.gr-20101123135856-0px463nz9xei8ho4
This commit is contained in:
P. Christeas
2010-11-23 15:58:56 +02:00
parent fe35e2517b
commit 8e6c11a16c
+10 -6
View File
@@ -27,7 +27,6 @@ import urllib
import zipimport
import addons
import netsvc
import pooler
import release
import tools
@@ -447,7 +446,7 @@ class module(osv.osv):
self.write(cr, uid, [id], {'category_id': p_id})
def update_translations(self, cr, uid, ids, filter_lang=None, context={}):
logger = netsvc.Logger()
logger = logging.getLogger('i18n')
if not filter_lang:
pool = pooler.get_pool(cr.dbname)
lang_obj = pool.get('res.lang')
@@ -467,13 +466,18 @@ class module(osv.osv):
if len(lang) > 5:
raise osv.except_osv(_('Error'), _('You Can Not Load Translation For language Due To Invalid Language/Country Code'))
iso_lang = tools.get_iso_codes(lang)
f = os.path.join(modpath, 'i18n', iso_lang + '.po')
if not os.path.exists(f) and iso_lang.find('_') != -1:
f = os.path.join(modpath, 'i18n', iso_lang.split('_')[0] + '.po')
f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po')
# Implementation notice: we must first search for the full name of
# the language derivative, like "en_UK", and then the generic,
# like "en".
if (not os.path.exists(f)) and '_' in iso_lang:
f = addons.get_module_resource(mod.name, 'i18n', iso_lang.split('_')[0] + '.po')
iso_lang = iso_lang.split('_')[0]
if os.path.exists(f):
logger.notifyChannel("i18n", netsvc.LOG_INFO, 'module %s: loading translation file for language %s' % (mod.name, iso_lang))
logger.info('module %s: loading translation file for language %s', mod.name, iso_lang)
tools.trans_load(cr.dbname, f, lang, verbose=False, context=context)
else:
logger.warning('module %s: no translation for language %s', mod.name, iso_lang)
def check(self, cr, uid, ids, context=None):
logger = logging.getLogger('init')