def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings # First, create the list of languages from settings. i18n_sett.langs.clear() root_br = self.settings.BRANCHES_DIR root_tr_po = self.settings.TRUNK_PO_DIR root_git_po = self.settings.GIT_I18N_PO_DIR root_tr_mo = os.path.join(self.settings.TRUNK_DIR, self.settings.MO_PATH_TEMPLATE, self.settings.MO_FILE_NAME) if not (os.path.isdir(root_br) and os.path.isdir(root_tr_po)): return {'CANCELLED'} isocodes = ((e, os.path.join(root_br, e, e + ".po")) for e in os.listdir(root_br)) isocodes = dict(e for e in isocodes if os.path.isfile(e[1])) for num_id, name, uid in self.settings.LANGUAGES[ 2:]: # Skip "default" and "en" languages! best_po = utils_i18n.find_best_isocode_matches(uid, isocodes) #print(uid, "->", best_po) lng = i18n_sett.langs.add() lng.uid = uid lng.num_id = num_id lng.name = name if best_po: lng.use = True isocode = best_po[0] lng.po_path = isocodes[isocode] lng.po_path_trunk = os.path.join(root_tr_po, isocode + ".po") lng.mo_path_trunk = root_tr_mo.format(isocode) lng.po_path_git = os.path.join(root_git_po, isocode + ".po") else: lng.use = False language, _1, _2, language_country, language_variant = utils_i18n.locale_explode( uid) for isocode in (language, language_variant, language_country, uid): p = os.path.join(root_br, isocode, isocode + ".po") if not os.path.exists(p): lng.use = True lng.po_path = p lng.po_path_trunk = os.path.join( root_tr_po, isocode + ".po") lng.mo_path_trunk = root_tr_mo.format(isocode) lng.po_path_git = os.path.join(root_git_po, isocode + ".po") break i18n_sett.pot_path = self.settings.FILE_NAME_POT i18n_sett.is_init = True 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'}
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) trans.dst = self._dst uids = [self.settings.PARSER_TEMPLATE_ID ] if self.use_export_pot else [] 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 = utils_i18n.find_best_isocode_matches(lng.uid, trans.trans.keys()) if uid: uids.append(uid[0]) # Try to update existing POs instead of overwriting them, if asked to do so! if self.use_update_existing: for uid in uids: if uid == self.settings.PARSER_TEMPLATE_ID: continue path = trans.dst(trans, trans.src[uid], uid, 'PO') if not os.path.isfile(path): continue msgs = utils_i18n.I18nMessages(kind='PO', src=path, settings=self.settings) msgs.update(trans.msgs[self.settings.PARSER_TEMPLATE_ID]) trans.msgs[uid] = msgs trans.write(kind='PO', langs=set(uids)) return {'FINISHED'}
def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings # First, create the list of languages from settings. i18n_sett.langs.clear() root_br = self.settings.BRANCHES_DIR root_tr_po = self.settings.TRUNK_PO_DIR root_git_po = self.settings.GIT_I18N_PO_DIR root_tr_mo = os.path.join(self.settings.TRUNK_DIR, self.settings.MO_PATH_TEMPLATE, self.settings.MO_FILE_NAME) if not (os.path.isdir(root_br) and os.path.isdir(root_tr_po)): return {'CANCELLED'} isocodes = ((e, os.path.join(root_br, e, e + ".po")) for e in os.listdir(root_br)) isocodes = dict(e for e in isocodes if os.path.isfile(e[1])) for num_id, name, uid in self.settings.LANGUAGES[2:]: # Skip "default" and "en" languages! best_po = utils_i18n.find_best_isocode_matches(uid, isocodes) #print(uid, "->", best_po) lng = i18n_sett.langs.add() lng.uid = uid lng.num_id = num_id lng.name = name if best_po: lng.use = True isocode = best_po[0] lng.po_path = isocodes[isocode] lng.po_path_trunk = os.path.join(root_tr_po, isocode + ".po") lng.mo_path_trunk = root_tr_mo.format(isocode) lng.po_path_git = os.path.join(root_git_po, isocode + ".po") else: lng.use = False language, _1, _2, language_country, language_variant = utils_i18n.locale_explode(uid) for isocode in (language, language_variant, language_country, uid): p = os.path.join(root_br, isocode, isocode + ".po") if not os.path.exists(p): lng.use = True lng.po_path = p lng.po_path_trunk = os.path.join(root_tr_po, isocode + ".po") lng.mo_path_trunk = root_tr_mo.format(isocode) lng.po_path_git = os.path.join(root_git_po, isocode + ".po") break i18n_sett.pot_path = self.settings.FILE_NAME_POT i18n_sett.is_init = True 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) trans.dst = self._dst uids = [self.settings.PARSER_TEMPLATE_ID] if self.use_export_pot else [] 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 = utils_i18n.find_best_isocode_matches(lng.uid, trans.trans.keys()) if uid: uids.append(uid[0]) # Try to update existing POs instead of overwriting them, if asked to do so! if self.use_update_existing: for uid in uids: if uid == self.settings.PARSER_TEMPLATE_ID: continue path = trans.dst(trans, trans.src[uid], uid, 'PO') if not os.path.isfile(path): continue msgs = utils_i18n.I18nMessages(kind='PO', src=path, settings=self.settings) msgs.update(trans.msgs[self.settings.PARSER_TEMPLATE_ID]) trans.msgs[uid] = msgs trans.write(kind='PO', langs=set(uids)) 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'}