示例#1
0
 def load_module_terms(self, cr, modules, langs, context=None):
     context_template = 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:
             context = dict(context_template)
             lang_code = tools.get_iso_codes(lang)
             # For sub-languages, load base language first (e.g. es_CL.po is loaded over es.po)
             _base_lang_code = ''
             for base_lang_code in lang_code.split('_'):
                 _base_lang_code += '%s%s' % (_base_lang_code and '_'
                                              or '', 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
                 elif lang_code != 'en_US':
                     _logger.warning(
                         'module %s: no translation for language %s',
                         module_name, _base_lang_code)
     return True
示例#2
0
    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
示例#3
0
    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
示例#4
0
 def act_translate(self):
     _logger.info('act_translate() BEGIN')
     self.env.cr.execute(
         "delete from ir_translation where module in ('document','mail')")
     self.env.cr.commit
     module_rcs = self.env['ir.module.module'].search([
         ('name', 'in', ('document', 'mail'))
     ])
     # module_rcs = self.pool['ir.module.module'].browse([])
     modules = [
         m.name for m in module_rcs
         if m.state in ('installed', 'to install', 'to upgrade')
     ]
     for module_name in modules:
         trans_file = openerp.modules.get_module_resource(
             'serenco_translation_vietnam', 'i18n', module_name + '.po')
         if trans_file:
             _logger.info(
                 'module %s: loading translation file (%s) for language %s',
                 module_name, 'vi_VN', 'vi_VN')
             tools.trans_load(self._cr,
                              trans_file,
                              'vi_VN',
                              verbose=False,
                              module_name=module_name)
     return True
 def act_translate(self, cr, uid, ids, context=None):
     _logger.info('act_translate() BEGIN')
     cr.execute("delete from ir_translation")
     cr.commit
     module_ids = self.pool['ir.module.module'].search(cr, uid, [])
     module_rcs = self.pool['ir.module.module'].browse(cr, uid, module_ids)
     modules = [
         m.name for m in module_rcs
         if m.state in ('installed', 'to install', 'to upgrade')
     ]
     for module_name in modules:
         trans_file = openerp.modules.get_module_resource(
             'ocv_translation_vietnam', 'i18n', module_name + '.po')
         if trans_file:
             _logger.info(
                 'module %s: loading translation file (%s) for language %s',
                 module_name, 'vi_VN', 'vi_VN')
             tools.trans_load(cr,
                              trans_file,
                              'vi_VN',
                              verbose=False,
                              module_name=module_name)
     return True
示例#6
0
    def load_module_terms(self, cr, modules, langs, context=None):
        context_template = dict(context or {}) # local copy
        # make sure the given languages are active
        lang_obj = self.pool['res.lang']
        for lang in langs:
            lang_obj.load_lang(cr, SUPERUSER_ID, lang)
        # load i18n files
        for module_name in modules:
            modpath = openerp.modules.get_module_path(module_name)
            if not modpath:
                continue
            for lang in langs:
                context = dict(context_template)
                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

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = openerp.modules.get_module_resource(module_name, 'i18n_extra', base_lang_code + '.po')
                    if base_trans_extra_file:
                        _logger.info('module %s: loading extra base translation file %s for language %s', module_name, base_lang_code, lang)
                        tools.trans_load(cr, base_trans_extra_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.info('module %s: no translation for language %s', module_name, lang_code)

                trans_extra_file = openerp.modules.get_module_resource(module_name, 'i18n_extra', lang_code + '.po')
                if trans_extra_file:
                    _logger.info('module %s: loading extra translation file (%s) for language %s', module_name, lang_code, lang)
                    tools.trans_load(cr, trans_extra_file, lang, verbose=False, module_name=module_name, context=context)
        return True
示例#7
0
    def load_module_terms(self, cr, modules, langs, context=None):
        context_template = dict(context or {}) # local copy
        # make sure the given languages are active
        lang_obj = self.pool['res.lang']
        for lang in langs:
            lang_obj.load_lang(cr, SUPERUSER_ID, lang)
        # load i18n files
        for module_name in modules:
            modpath = openerp.modules.get_module_path(module_name)
            if not modpath:
                continue
            for lang in langs:
                context = dict(context_template)
                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

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = openerp.modules.get_module_resource(module_name, 'i18n_extra', base_lang_code + '.po')
                    if base_trans_extra_file:
                        _logger.info('module %s: loading extra base translation file %s for language %s', module_name, base_lang_code, lang)
                        tools.trans_load(cr, base_trans_extra_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.info('module %s: no translation for language %s', module_name, lang_code)

                trans_extra_file = openerp.modules.get_module_resource(module_name, 'i18n_extra', lang_code + '.po')
                if trans_extra_file:
                    _logger.info('module %s: loading extra translation file (%s) for language %s', module_name, lang_code, lang)
                    tools.trans_load(cr, trans_extra_file, lang, verbose=False, module_name=module_name, context=context)
        return True
示例#8
0
    def load_module_terms(self, cr, modules, langs, context=None):
        context_template = 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:
                context = dict(context_template)
                lang_code = tools.get_iso_codes(lang)
                # funkring.net begin
                base_lang_code = '_' in lang_code and lang_code.split(
                    '_')[0] or lang_code
                context = dict(context or {})  # local copy
                # funkring.net end

                # 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

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = openerp.modules.get_module_resource(
                        module_name, 'i18n_extra', base_lang_code + '.po')
                    if base_trans_extra_file:
                        _logger.info(
                            'module %s: loading extra base translation file %s for language %s',
                            module_name, base_lang_code, lang)
                        tools.trans_load(cr,
                                         base_trans_extra_file,
                                         lang,
                                         verbose=False,
                                         module_name=module_name,
                                         context=context)
                        context[
                            'overwrite'] = True  # make sure the requested translation will override the base terms later

                # funkring.net - begin
                # Step 2: then load the main translation file, possibly overriding the terms coming from the base language
                # check if a sub lang exist
                if lang_code != base_lang_code:
                    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 != openerp.tools.config.baseLang:
                        _logger.warning(
                            'module %s: no translation for language %s',
                            module_name, lang_code)

                    trans_extra_file = openerp.modules.get_module_resource(
                        module_name, 'i18n_extra', lang_code + '.po')
                    if trans_extra_file:
                        _logger.info(
                            'module %s: loading extra translation file (%s) for language %s',
                            module_name, lang_code, lang)
                        tools.trans_load(cr,
                                         trans_extra_file,
                                         lang,
                                         verbose=False,
                                         module_name=module_name,
                                         context=context)
                # funkring.net - end
        return True
示例#9
0
    def load_module_terms(self, cr, modules, langs, context=None):
        context_template = 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:
                context = dict(context_template)
                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

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = openerp.modules.get_module_resource(
                        module_name, "i18n_extra", base_lang_code + ".po"
                    )
                    if base_trans_extra_file:
                        _logger.info(
                            "module %s: loading extra base translation file %s for language %s",
                            module_name,
                            base_lang_code,
                            lang,
                        )
                        tools.trans_load(
                            cr, base_trans_extra_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)

                trans_extra_file = openerp.modules.get_module_resource(module_name, "i18n_extra", lang_code + ".po")
                if trans_extra_file:
                    _logger.info(
                        "module %s: loading extra translation file (%s) for language %s", module_name, lang_code, lang
                    )
                    tools.trans_load(
                        cr, trans_extra_file, lang, verbose=False, module_name=module_name, context=context
                    )
        return True
示例#10
0
    def load_module_terms(self, cr, modules, langs, context=None):
        context = dict(context or {})  # local copy
        ir_module = self.pool.get('ir.module.module')
        for module_name in modules:
            modpath = openerp.modules.get_module_path(module_name)
            if not modpath:
                continue

            #THANH: Check module allows overwrite translation
            module_ids = ir_module.search(cr, SUPERUSER_ID,
                                          [('name', '=', module_name)])
            if len(module_ids):
                this_module = ir_module.browse(cr, SUPERUSER_ID, module_ids[0])
                if this_module.overwrite:
                    context.update({'overwrite': True})
            #THANH: Check module allows overwrite translation

            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

                    # i18n_extra folder is for additional translations handle manually (eg: for l10n_be)
                    base_trans_extra_file = openerp.modules.get_module_resource(
                        module_name, 'i18n_extra', base_lang_code + '.po')
                    if base_trans_extra_file:
                        _logger.info(
                            'module %s: loading extra base translation file %s for language %s',
                            module_name, base_lang_code, lang)
                        tools.trans_load(cr,
                                         base_trans_extra_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.info('module %s: no translation for language %s',
                                 module_name, lang_code)

                trans_extra_file = openerp.modules.get_module_resource(
                    module_name, 'i18n_extra', lang_code + '.po')
                if trans_extra_file:
                    _logger.info(
                        'module %s: loading extra translation file (%s) for language %s',
                        module_name, lang_code, lang)
                    tools.trans_load(cr,
                                     trans_extra_file,
                                     lang,
                                     verbose=False,
                                     module_name=module_name,
                                     context=context)
        return True
示例#11
0
    def update_translations(self,
                            cr,
                            uid,
                            ids,
                            custom_location,
                            filter_lang=None,
                            context=None):
        if context is None:
            context = {}
        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]

        # always overwrite
        context['overwrite'] = True

        module_obj = self.pool.get('ir.module.module')
        module_ids = module_obj.search(cr, uid, [('state', '=', 'installed')])

        for mod in module_obj.browse(cr, uid, module_ids):
            if mod.state != 'installed':
                continue
            modpath = addons.get_module_path(mod.name)

            if not modpath:
                continue
            # only overwrite modules within this path location
            if not custom_location in modpath:
                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)