def _lang_install(self, cr, uid, data, context): revision = data['form']['revision'] try: text = s.get_release(self.lang, self.version, self.profile, revision) filename = tools.config["root_path"] + "/i18n/" + self.lang + ".csv" h_row = { 'type': 'type', 'res_id': 'res_id', 'name': 'name', 'value': 'value', 'src': 'src' } f = open(filename, 'wb') fieldnames = tuple(text[0].keys()) outwriter = csv.DictWriter(f, fieldnames=fieldnames) outwriter.writerow(h_row) for t in text: t['value'] = t['value'].encode('utf8') t['src'] = t['src'].encode('utf8') outwriter.writerows(text) tools.trans_load(cr.dbname, filename, self.lang) except Exception, e: raise wizard.except_wizard('Error !', "server is not properly configuraed")
def update_translations(self, cr, uid, ids, filter_lang=None): logger = netsvc.Logger() if not filter_lang: pool = pooler.get_pool(cr.dbname) lang_obj = pool.get('res.lang') lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) filter_lang = [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)] elif not isinstance(filter_lang, (list, tuple)): filter_lang = [filter_lang] for mod in self.browse(cr, uid, ids): if mod.state != 'installed': continue modpath = addons.get_module_path(mod.name) if not modpath: # unable to find the module. we skip continue for lang in filter_lang: 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') 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)) tools.trans_load(cr.dbname, f, lang, verbose=False)
def load(self, cr, modules, langs, context=None): context = dict(context or {}) # local copy for module_name in modules: modpath = openerp.modules.get_module_path(module_name) if not modpath: continue for lang in langs: lang_code = tools.get_iso_codes(lang) base_lang_code = None if '_' in lang_code: base_lang_code = lang_code.split('_')[0] # Step 1: for sub-languages, load base language first (e.g. es_CL.po is loaded over es.po) if base_lang_code: base_trans_file = openerp.modules.get_module_resource(module_name, 'i18n', base_lang_code + '.po') if base_trans_file: _logger.info('module %s: loading base translation file %s for language %s', module_name, base_lang_code, lang) tools.trans_load(cr, base_trans_file, lang, verbose=False, module_name=module_name, context=context) context['overwrite'] = True # make sure the requested translation will override the base terms later # Step 2: then load the main translation file, possibly overriding the terms coming from the base language trans_file = openerp.modules.get_module_resource(module_name, 'i18n', lang_code + '.po') if trans_file: _logger.info('module %s: loading translation file (%s) for language %s', module_name, lang_code, lang) tools.trans_load(cr, trans_file, lang, verbose=False, module_name=module_name, context=context) elif lang_code != 'en_US': _logger.warning('module %s: no translation for language %s', module_name, lang_code) return True
def update_translations(self, cr, uid, ids, filter_lang=None, context={}): logger = logging.getLogger('i18n') if not filter_lang: pool = pooler.get_pool(cr.dbname) lang_obj = pool.get('res.lang') lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) filter_lang = [ lang.code for lang in lang_obj.browse(cr, uid, lang_ids) ] elif not isinstance(filter_lang, (list, tuple)): filter_lang = [filter_lang] for mod in self.browse(cr, uid, ids): if mod.state != 'installed': continue modpath = addons.get_module_path(mod.name) if not modpath: # unable to find the module. we skip continue for lang in filter_lang: iso_lang = tools.get_iso_codes(lang) f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po') context2 = context and context.copy() or {} if f and '_' in iso_lang: iso_lang2 = iso_lang.split('_')[0] f2 = addons.get_module_resource(mod.name, 'i18n', iso_lang2 + '.po') if f2: logger.info( 'module %s: loading base translation file %s for language %s', mod.name, iso_lang2, lang) tools.trans_load(cr, f2, lang, verbose=False, context=context) context2['overwrite'] = True # 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 f) and '_' in iso_lang: iso_lang = iso_lang.split('_')[0] f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po') if f: logger.info( 'module %s: loading translation file (%s) for language %s', mod.name, iso_lang, lang) tools.trans_load(cr, f, lang, verbose=False, context=context2) elif iso_lang != 'en': logger.warning('module %s: no translation for language %s', mod.name, iso_lang) tools.trans_update_res_ids(cr)
def update_translations(self, cr, uid, ids, filter_lang=None, context=None): if context is None: context = {} logger = logging.getLogger('i18n') if not filter_lang: pool = pooler.get_pool(cr.dbname) lang_obj = pool.get('res.lang') lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) filter_lang = [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)] elif not isinstance(filter_lang, (list, tuple)): filter_lang = [filter_lang] msf_profile_id = self.pool.get('ir.module.module').search(cr, uid, [('name', '=', 'msf_profile')]) if msf_profile_id and msf_profile_id[0] in ids: ids.remove(msf_profile_id[0]) # load msf_profile file at the end (due to es.po file, terms are always overwritten) ids.append(msf_profile_id[0]) for mod in self.browse(cr, uid, ids): if mod.state != 'installed': continue modpath = addons.get_module_path(mod.name) if not modpath: # unable to find the module. we skip continue for lang in filter_lang: iso_lang = tools.get_iso_codes(lang) f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po') context2 = context and context.copy() or {} if f and '_' in iso_lang: iso_lang2 = iso_lang.split('_')[0] f2 = addons.get_module_resource(mod.name, 'i18n', iso_lang2 + '.po') if f2: logger.info('module %s: loading base translation file %s for language %s', mod.name, iso_lang2, lang) tools.trans_load(cr, f2, lang, verbose=False, context=context) context2['overwrite'] = True # 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 f) and '_' in iso_lang: iso_lang = iso_lang.split('_')[0] f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po') if f: logger.info('module %s: loading translation file (%s) for language %s', mod.name, iso_lang, lang) tools.trans_load(cr, f, lang, verbose=False, context=context2) elif iso_lang != 'en': logger.warning('module %s: no translation for language %s', mod.name, iso_lang) tools.trans_update_res_ids(cr)
def load(self, cr, modules, langs, context=None): context = dict(context or {}) # local copy for module_name in modules: modpath = openerp.modules.get_module_path(module_name) if not modpath: continue for lang in langs: lang_code = tools.get_iso_codes(lang) base_lang_code = None if '_' in lang_code: base_lang_code = lang_code.split('_')[0] # Step 1: for sub-languages, load base language first (e.g. es_CL.po is loaded over es.po) if base_lang_code: base_trans_file = openerp.modules.get_module_resource( module_name, 'i18n', base_lang_code + '.po') if base_trans_file: _logger.info( 'module %s: loading base translation file %s for language %s', module_name, base_lang_code, lang) tools.trans_load(cr, base_trans_file, lang, verbose=False, module_name=module_name, context=context) context[ 'overwrite'] = True # make sure the requested translation will override the base terms later # Step 2: then load the main translation file, possibly overriding the terms coming from the base language trans_file = openerp.modules.get_module_resource( module_name, 'i18n', lang_code + '.po') if trans_file: _logger.info( 'module %s: loading translation file (%s) for language %s', module_name, lang_code, lang) tools.trans_load(cr, trans_file, lang, verbose=False, module_name=module_name, context=context) elif lang_code != 'en_US': _logger.warning( 'module %s: no translation for language %s', module_name, lang_code) return True
def _lang_install(self, cr, uid, data, context): revision = data['form']['revision'] try : text = s.get_release(self.lang,self.version,self.profile,revision) filename = tools.config["root_path"] + "/i18n/" + self.lang + ".csv" h_row = {'type': 'type', 'res_id': 'res_id', 'name': 'name', 'value': 'value', 'src': 'src'} f = open(filename,'wb') fieldnames=tuple(text[0].keys()) outwriter = csv.DictWriter(f, fieldnames=fieldnames) outwriter.writerow(h_row) for t in text: t['value'] = t['value'].encode('utf8') t['src']=t['src'].encode('utf8') outwriter.writerows(text) tools.trans_load(cr.dbname, filename, self.lang) except Exception,e: raise wizard.except_wizard('Error !',"server is not properly configuraed")
def update_translations(self, cr, uid, ids, filter_lang=None, context=None): logger = logging.getLogger('i18n') if not filter_lang: pool = pooler.get_pool(cr.dbname) lang_obj = pool.get('res.lang') lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) filter_lang = [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)] elif not isinstance(filter_lang, (list, tuple)): filter_lang = [filter_lang] for mod in self.browse(cr, uid, ids): if mod.state != 'installed': continue modpath = addons.get_module_path(mod.name) if not modpath: # unable to find the module. we skip continue for lang in filter_lang: iso_lang = tools.get_iso_codes(lang) # Implementation notice: We need to load both the base language, # like "en" and then the dialects (like "en_GB"). # With overwrite=False, en will be complemented with 'en_GB' terms. # with overwrite, we need to reverse the loading order to_load = [] f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po') if f: to_load.append((iso_lang, f)) if '_' in iso_lang: iso_lang = iso_lang.split('_')[0] f = addons.get_module_resource(mod.name, 'i18n', iso_lang + '.po') if f: to_load.append((iso_lang, f)) if context and context.get('overwrite', False): to_load.reverse() for (iso_lang, f) in to_load: logger.info('module %s: loading translation file for language %s', mod.name, iso_lang) tools.trans_load(cr, f, lang, verbose=False, context=context) if to_load == [] and lang != 'en_US': logger.warning('module %s: no translation for language %s', mod.name, lang)
def update_translations(self, cr, uid, ids, filter_lang=None): logger = netsvc.Logger() if not filter_lang: pool = pooler.get_pool(cr.dbname) lang_obj = pool.get('res.lang') lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) filter_lang = [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)] elif not isinstance(filter_lang, (list, tuple)): filter_lang = [filter_lang] for mod in self.browse(cr, uid, ids): if mod.state != 'installed': continue modpath = addons.get_module_path(mod.name) if not modpath: # unable to find the module. we skip continue for lang in filter_lang: f = os.path.join(modpath, 'i18n', lang + '.po') if os.path.exists(f): logger.notifyChannel("i18n", netsvc.LOG_INFO, 'module %s: loading translation file for language %s' % (mod.name, lang)) tools.trans_load(cr.dbname, f, lang, verbose=False)
def update_translations(self, cr, uid, ids, filter_lang=None): logger = netsvc.Logger() if not filter_lang: pool = pooler.get_pool(cr.dbname) lang_obj = pool.get('res.lang') lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)]) filter_lang = [ lang.code for lang in lang_obj.browse(cr, uid, lang_ids) ] elif not isinstance(filter_lang, (list, tuple)): filter_lang = [filter_lang] for mod in self.browse(cr, uid, ids): if mod.state != 'installed': continue modpath = addons.get_module_path(mod.name) if not modpath: # unable to find the module. we skip continue for lang in filter_lang: 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') 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)) tools.trans_load(cr.dbname, f, lang, verbose=False)
cr = pooler.get_db(dbname).cursor() tools.trans_export(tools.config["language"], tools.config["translate_modules"] or ["all"], buf, fileformat, cr) cr.close() buf.close() logger.info('translation file written successfully') sys.exit(0) if tools.config["translate_in"]: context = {'overwrite': tools.config["overwrite_existing_translations"]} dbname = tools.config['db_name'] cr = pooler.get_db(dbname).cursor() tools.trans_load(cr, tools.config["translate_in"], tools.config["language"], context=context) tools.trans_update_res_ids(cr) cr.commit() cr.close() sys.exit(0) #---------------------------------------------------------------------------------- # if we don't want the server to continue to run after initialization, we quit here #---------------------------------------------------------------------------------- if tools.config["stop_after_init"]: sys.exit(0) #---------------------------------------------------------- # Launch Servers #----------------------------------------------------------
msg = "new language" logger.notifyChannel("init", netsvc.LOG_INFO, 'writing translation file for %s to %s' % (msg, tools.config["translate_out"])) fileformat = os.path.splitext(tools.config["translate_out"])[-1][1:].lower() buf = file(tools.config["translate_out"], "w") tools.trans_export(tools.config["language"], tools.config["translate_modules"], buf, fileformat) buf.close() logger.notifyChannel("init", netsvc.LOG_INFO, 'translation file written successfully') sys.exit(0) if tools.config["translate_in"]: tools.trans_load(tools.config["db_name"], tools.config["translate_in"], tools.config["language"]) sys.exit(0) #---------------------------------------------------------------------------------- # if we don't want the server to continue to run after initialization, we quit here #---------------------------------------------------------------------------------- if tools.config["stop_after_init"]: sys.exit(0) #---------------------------------------------------------- # Launch Servers #---------------------------------------------------------- LST_SIGNALS = ['SIGINT', 'SIGTERM']
buf = file(tools.config["translate_out"], "w") dbname = tools.config['db_name'] cr = pooler.get_db(dbname).cursor() tools.trans_export(tools.config["language"], tools.config["translate_modules"] or ["all"], buf, fileformat, cr) cr.close() buf.close() logger.info('translation file written successfully') sys.exit(0) if tools.config["translate_in"]: context = {'overwrite': tools.config["overwrite_existing_translations"]} dbname = tools.config['db_name'] cr = pooler.get_db(dbname).cursor() tools.trans_load(cr, tools.config["translate_in"], tools.config["language"], context=context) tools.trans_update_res_ids(cr) cr.commit() cr.close() sys.exit(0) #---------------------------------------------------------------------------------- # if we don't want the server to continue to run after initialization, we quit here #---------------------------------------------------------------------------------- if tools.config["stop_after_init"]: sys.exit(0) #---------------------------------------------------------- # Launch Servers