def execute(self, context): global _cached_enum_addons _cached_enum_addons[:] = [] if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings module_name, mod = validate_module(self, context) if not (module_name and mod): return {'CANCELLED'} path = mod.__file__ if path.endswith("__init__.py"): path = os.path.dirname(path) trans = utils_i18n.I18n(kind='PY', src=path, settings=self.settings) # Now search given dir, to find po's matching given languages... # Mapping po_uid: po_file. po_files = dict(utils_i18n.get_po_files_from_dir(self.directory)) # Note: uids in i18n_sett.langs and addon's py code should be the same (both taken from the locale's languages # file). So we just try to find the best match in po's for each enabled uid. for lng in i18n_sett.langs: if lng.uid in self.settings.IMPORT_LANGUAGES_SKIP: print( "Skipping {} language ({}), edit settings if you want to enable it." .format(lng.name, lng.uid)) continue if not lng.use: print("Skipping {} language ({}).".format(lng.name, lng.uid)) continue uid = lng.uid po_uid = utils_i18n.find_best_isocode_matches(uid, po_files.keys()) if not po_uid: print("Skipping {} language, no PO file found for it ({}).". format(lng.name, uid)) continue po_uid = po_uid[0] msgs = utils_i18n.I18nMessages(uid=uid, kind='PO', key=uid, src=po_files[po_uid], settings=self.settings) if uid in trans.trans: trans.trans[uid].merge(msgs, replace=True) else: trans.trans[uid] = msgs trans.write(kind='PY') return {'FINISHED'}
def execute(self, context): global _cached_enum_addons _cached_enum_addons[:] = [] if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings module_name, mod = validate_module(self, context) if not (module_name and mod): return {'CANCELLED'} path = mod.__file__ if path.endswith("__init__.py"): path = os.path.dirname(path) trans = utils_i18n.I18n(kind='PY', src=path, settings=self.settings) # Now search given dir, to find po's matching given languages... # Mapping po_uid: po_file. po_files = dict(utils_i18n.get_po_files_from_dir(self.directory)) # Note: uids in i18n_sett.langs and addon's py code should be the same (both taken from the locale's languages # file). So we just try to find the best match in po's for each enabled uid. for lng in i18n_sett.langs: if lng.uid in self.settings.IMPORT_LANGUAGES_SKIP: print("Skipping {} language ({}), edit settings if you want to enable it.".format(lng.name, lng.uid)) continue if not lng.use: print("Skipping {} language ({}).".format(lng.name, lng.uid)) continue uid = lng.uid po_uid = utils_i18n.find_best_isocode_matches(uid, po_files.keys()) if not po_uid: print("Skipping {} language, no PO file found for it ({}).".format(lng.name, uid)) continue po_uid = po_uid[0] msgs = utils_i18n.I18nMessages(uid=uid, kind='PO', key=uid, src=po_files[po_uid], settings=self.settings) if uid in trans.trans: trans.trans[uid].merge(msgs, replace=True) else: trans.trans[uid] = msgs trans.write(kind='PY') return {'FINISHED'}