def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings self.settings.FILE_NAME_POT = i18n_sett.pot_path context.window_manager.progress_begin(0, len(i18n_sett.langs) + 1) context.window_manager.progress_update(0) if not self.use_skip_pot_gen: env = os.environ.copy() env["ASAN_OPTIONS"] = "exitcode=0" # Generate base pot from RNA messages (we use another blender instance here, to be able to perfectly # control our environment (factory startup, specific addons enabled/disabled...)). # However, we need to export current user settings about this addon! cmmd = ( bpy.app.binary_path, "--background", "--factory-startup", "--python", os.path.join(os.path.dirname(utils_i18n.__file__), "bl_extract_messages.py"), "--", "--settings", self.settings.to_json(), ) # Not working (UI is not refreshed...). #self.report({'INFO'}, "Extracting messages, this will take some time...") context.window_manager.progress_update(1) ret = subprocess.run(cmmd, env=env) if ret.returncode != 0: self.report({'ERROR'}, "Message extraction process failed!") context.window_manager.progress_end() return {'CANCELLED'} # Now we should have a valid POT file, we have to merge it in all languages po's... pot = utils_i18n.I18nMessages(kind='PO', src=self.settings.FILE_NAME_POT, settings=self.settings) for progress, lng in enumerate(i18n_sett.langs): context.window_manager.progress_update(progress + 2) if not lng.use: continue if os.path.isfile(lng.po_path): po = utils_i18n.I18nMessages(uid=lng.uid, kind='PO', src=lng.po_path, settings=self.settings) po.update(pot) else: po = pot po.write(kind="PO", dest=lng.po_path) print("{} PO written!".format(lng.uid)) context.window_manager.progress_end() return {'FINISHED'}
def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings # 'DEFAULT' and en_US are always valid, fully-translated "languages"! stats = {"DEFAULT": 1.0, "en_US": 1.0} context.window_manager.progress_begin(0, len(i18n_sett.langs) + 1) context.window_manager.progress_update(0) for progress, lng in enumerate(i18n_sett.langs): context.window_manager.progress_update(progress + 1) 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 print("Processing {} language ({}).".format(lng.name, lng.uid)) po = utils_i18n.I18nMessages(uid=lng.uid, kind='PO', src=lng.po_path, settings=self.settings) print("Cleaned up {} commented messages.".format(po.clean_commented())) errs = po.check(fix=True) if errs: print("Errors in this po, solved as best as possible!") print("\t" + "\n\t".join(errs)) if lng.uid in self.settings.IMPORT_LANGUAGES_RTL: po.write(kind="PO", dest=lng.po_path_trunk[:-3] + "_raw.po") po.rtl_process() po.write(kind="PO", dest=lng.po_path_trunk) po.write(kind="PO_COMPACT", dest=lng.po_path_git) po.write(kind="MO", dest=lng.mo_path_trunk) po.update_info() stats[lng.uid] = po.nbr_trans_msgs / po.nbr_msgs print("\n") # Copy pot file from branches to trunk. shutil.copy2(self.settings.FILE_NAME_POT, self.settings.TRUNK_PO_DIR) print("Generating languages' menu...") context.window_manager.progress_update(progress + 2) # First complete our statistics by checking po files we did not touch this time! po_to_uid = {os.path.basename(lng.po_path): lng.uid for lng in i18n_sett.langs} for po_path in os.listdir(self.settings.TRUNK_PO_DIR): uid = po_to_uid.get(po_path, None) po_path = os.path.join(self.settings.TRUNK_PO_DIR, po_path) if uid and uid not in stats: po = utils_i18n.I18nMessages(uid=uid, kind='PO', src=po_path, settings=self.settings) stats[uid] = po.nbr_trans_msgs / po.nbr_msgs utils_languages_menu.gen_menu_file(stats, self.settings) context.window_manager.progress_end() return {'FINISHED'}
def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings # 'DEFAULT' and en_US are always valid, fully-translated "languages"! stats = {"DEFAULT": 1.0, "en_US": 1.0} context.window_manager.progress_begin(0, len(i18n_sett.langs) + 1) context.window_manager.progress_update(0) for progress, lng in enumerate(i18n_sett.langs): context.window_manager.progress_update(progress + 1) if not lng.use: print("Skipping {} language ({}).".format(lng.name, lng.uid)) continue print("Processing {} language ({}).".format(lng.name, lng.uid)) po = utils_i18n.I18nMessages(uid=lng.uid, kind='PO', src=lng.po_path, settings=self.settings) print("Cleaned up {} commented messages.".format(po.clean_commented())) errs = po.check(fix=True) if errs: print("Errors in this po, solved as best as possible!") print("\t" + "\n\t".join(errs)) po.write(kind="PO", dest=lng.po_path) print("\n") context.window_manager.progress_end() return {'FINISHED'}
def i18n_updatetranslation_svn_trunk_callback(lng, settings): if lng['uid'] in settings.IMPORT_LANGUAGES_SKIP: print( "Skipping {} language ({}), edit settings if you want to enable it.\n" .format(lng['name'], lng['uid'])) return lng['uid'], 0.0 if not lng['use']: print("Skipping {} language ({}).\n".format(lng['name'], lng['uid'])) return lng['uid'], 0.0 po = utils_i18n.I18nMessages(uid=lng['uid'], kind='PO', src=lng['po_path'], settings=settings) errs = po.check(fix=True) print("Processing {} language ({}).\n" "Cleaned up {} commented messages.\n".format(lng['name'], lng['uid'], po.clean_commented()) + ("Errors in this po, solved as best as possible!\n\t" + "\n\t".join(errs) if errs else "") + "\n") if lng['uid'] in settings.IMPORT_LANGUAGES_RTL: po.write(kind="PO", dest=lng['po_path_trunk'][:-3] + "_raw.po") po.rtl_process() po.write(kind="PO", dest=lng['po_path_trunk']) po.write(kind="PO_COMPACT", dest=lng['po_path_git']) po.write(kind="MO", dest=lng['mo_path_trunk']) po.update_info() return lng['uid'], po.nbr_trans_msgs / po.nbr_msgs
def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings # 'DEFAULT' and en_US are always valid, fully-translated "languages"! stats = {"DEFAULT": 1.0, "en_US": 1.0} context.window_manager.progress_begin(0, len(i18n_sett.langs) + 1) context.window_manager.progress_update(0) with concurrent.futures.ProcessPoolExecutor() as exctr: num_langs = len(i18n_sett.langs) for progress, (lng_uid, stats_val) in enumerate(exctr.map(i18n_updatetranslation_svn_trunk_callback, [dict(lng.items()) for lng in i18n_sett.langs], (self.settings,) * num_langs, chunksize=4)): context.window_manager.progress_update(progress + 1) stats[lng_uid] = stats_val # Copy pot file from branches to trunk. shutil.copy2(self.settings.FILE_NAME_POT, self.settings.TRUNK_PO_DIR) print("Generating languages' menu...") context.window_manager.progress_update(progress + 2) # First complete our statistics by checking po files we did not touch this time! po_to_uid = {os.path.basename(lng.po_path): lng.uid for lng in i18n_sett.langs} for po_path in os.listdir(self.settings.TRUNK_PO_DIR): uid = po_to_uid.get(po_path, None) po_path = os.path.join(self.settings.TRUNK_PO_DIR, po_path) if uid and uid not in stats: po = utils_i18n.I18nMessages(uid=uid, kind='PO', src=po_path, settings=self.settings) stats[uid] = po.nbr_trans_msgs / po.nbr_msgs if po.nbr_msgs > 0 else 0 utils_languages_menu.gen_menu_file(stats, self.settings) context.window_manager.progress_end() return {'FINISHED'}
def _get_messages(lang, fname): if fname not in PO_CACHE: PO_CACHE[fname] = utils_i18n.I18nMessages(uid=lang, kind='PO', key=fname, src=fname, settings=settings.settings) return PO_CACHE[fname]
def i18n_updatetranslation_svn_branches_callback(pot, lng, settings): if not lng['use']: return if os.path.isfile(lng['po_path']): po = utils_i18n.I18nMessages(uid=lng['uid'], kind='PO', src=lng['po_path'], settings=settings) po.update(pot) else: po = pot po.write(kind="PO", dest=lng['po_path']) print("{} PO written!".format(lng['uid']))
def i18n_cleanuptranslation_svn_branches_callback(lng, settings): if not lng['use']: print("Skipping {} language ({}).".format(lng['name'], lng['uid'])) return po = utils_i18n.I18nMessages(uid=lng['uid'], kind='PO', src=lng['po_path'], settings=settings) errs = po.check(fix=True) cleanedup_commented = po.clean_commented() po.write(kind="PO", dest=lng['po_path']) print("Processing {} language ({}).\n" "Cleaned up {} commented messages.\n".format(lng['name'], lng['uid'], cleanedup_commented) + ("Errors in this po, solved as best as possible!\n\t" + "\n\t".join(errs) if errs else "") + "\n")
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): 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) # Generate addon-specific messages (no need for another blender instance here, this should not have any # influence over the final result). pot = bl_extract_messages.dump_addon_messages(module_name, True, self.settings) # Now (try to) get current i18n data from the addon... path = mod.__file__ if path.endswith("__init__.py"): path = os.path.dirname(path) trans = utils_i18n.I18n(kind='PY', src=path, settings=self.settings) uids = set() 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 uids.add(lng.uid) # For now, add to processed uids all those not found in "official" list, minus "tech" ones. uids |= ( trans.trans.keys() - {lng.uid for lng in i18n_sett.langs} - {self.settings.PARSER_TEMPLATE_ID, self.settings.PARSER_PY_ID}) # And merge! for uid in uids: if uid not in trans.trans: trans.trans[uid] = utils_i18n.I18nMessages( uid=uid, settings=self.settings) trans.trans[uid].update(pot, keep_old_commented=False) trans.trans[self.settings.PARSER_TEMPLATE_ID] = pot # For now we write all languages found in this trans! trans.write(kind='PY') return {'FINISHED'}
def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings self.settings.FILE_NAME_POT = i18n_sett.pot_path context.window_manager.progress_begin(0, len(i18n_sett.langs) + 1) context.window_manager.progress_update(0) if not self.use_skip_pot_gen: env = os.environ.copy() env["ASAN_OPTIONS"] = "exitcode=0:" + os.environ.get( "ASAN_OPTIONS", "") # Generate base pot from RNA messages (we use another blender instance here, to be able to perfectly # control our environment (factory startup, specific addons enabled/disabled...)). # However, we need to export current user settings about this addon! cmmd = ( bpy.app.binary_path, "--background", "--factory-startup", "--python", os.path.join(os.path.dirname(utils_i18n.__file__), "bl_extract_messages.py"), "--", "--settings", self.settings.to_json(), ) # Not working (UI is not refreshed...). #self.report({'INFO'}, "Extracting messages, this will take some time...") context.window_manager.progress_update(1) ret = subprocess.run(cmmd, env=env) if ret.returncode != 0: self.report({'ERROR'}, "Message extraction process failed!") context.window_manager.progress_end() return {'CANCELLED'} # Now we should have a valid POT file, we have to merge it in all languages po's... with concurrent.futures.ProcessPoolExecutor() as exctr: pot = utils_i18n.I18nMessages(kind='PO', src=self.settings.FILE_NAME_POT, settings=self.settings) num_langs = len(i18n_sett.langs) for progress, _ in enumerate( exctr.map(i18n_updatetranslation_svn_branches_callback, (pot, ) * num_langs, [dict(lng.items()) for lng in i18n_sett.langs], (self.settings, ) * num_langs, chunksize=4)): context.window_manager.progress_update(progress + 2) context.window_manager.progress_end() return {'FINISHED'}
def execute(self, context): if not hasattr(self, "settings"): self.settings = settings.settings i18n_sett = context.window_manager.i18n_update_svn_settings buff = io.StringIO() lst = [] if self.use_branches: lst += [(lng, lng.po_path) for lng in i18n_sett.langs] if self.use_trunk: lst += [(lng, lng.po_path_trunk) for lng in i18n_sett.langs if lng.uid not in self.settings.IMPORT_LANGUAGES_SKIP] context.window_manager.progress_begin(0, len(lst)) context.window_manager.progress_update(0) for progress, (lng, path) in enumerate(lst): context.window_manager.progress_update(progress + 1) if not lng.use: print("Skipping {} language ({}).".format(lng.name, lng.uid)) continue buff.write("Processing {} language ({}, {}).\n".format( lng.name, lng.uid, path)) po = utils_i18n.I18nMessages(uid=lng.uid, kind='PO', src=path, settings=self.settings) po.print_info(prefix=" ", output=buff.write) errs = po.check(fix=False) if errs: buff.write(" WARNING! Po contains following errors:\n") buff.write(" " + "\n ".join(errs)) buff.write("\n") buff.write("\n\n") text = None if self.report_name not in bpy.data.texts: text = bpy.data.texts.new(self.report_name) else: text = bpy.data.texts[self.report_name] data = text.as_string() data = data + "\n" + buff.getvalue() text.from_string(data) self.report({'INFO'}, "Info written to {} text datablock!".format( self.report_name)) context.window_manager.progress_end() return {'FINISHED'}