[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4467] trunk/py/scripts/addons/ ui_translate: More fixes for addon i18n messages management.
Bastien Montagne
montagne29 at wanadoo.fr
Fri Apr 12 14:21:16 CEST 2013
Revision: 4467
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4467
Author: mont29
Date: 2013-04-12 12:21:16 +0000 (Fri, 12 Apr 2013)
Log Message:
-----------
More fixes for addon i18n messages management.
Modified Paths:
--------------
trunk/py/scripts/addons/ui_translate/__init__.py
trunk/py/scripts/addons/ui_translate/update_addon.py
trunk/py/scripts/addons/ui_translate/update_svn.py
Added Paths:
-----------
trunk/py/scripts/addons/ui_translate/update_ui.py
Modified: trunk/py/scripts/addons/ui_translate/__init__.py
===================================================================
--- trunk/py/scripts/addons/ui_translate/__init__.py 2013-04-11 19:26:33 UTC (rev 4466)
+++ trunk/py/scripts/addons/ui_translate/__init__.py 2013-04-12 12:21:16 UTC (rev 4467)
@@ -39,12 +39,15 @@
imp.reload(edit_translation)
imp.reload(update_svn)
imp.reload(update_addon)
+ imp.reload(update_ui)
else:
import bpy
- from . import settings
- from . import edit_translation
- from . import update_svn
- from . import update_addon
+ from . import (settings,
+ edit_translation,
+ update_svn,
+ update_addon,
+ update_ui,
+ )
import os
@@ -53,7 +56,7 @@
def register():
bpy.utils.register_module(__name__)
bpy.types.WindowManager.i18n_update_svn_settings = \
- bpy.props.PointerProperty(type=update_svn.I18nUpdateTranslationSettings)
+ bpy.props.PointerProperty(type=update_ui.I18nUpdateTranslationSettings)
# Init addon's preferences (unfortunately, as we are using an external storage for the properties,
# the load/save user preferences process has no effect on them :( ).
Modified: trunk/py/scripts/addons/ui_translate/update_addon.py
===================================================================
--- trunk/py/scripts/addons/ui_translate/update_addon.py 2013-04-11 19:26:33 UTC (rev 4466)
+++ trunk/py/scripts/addons/ui_translate/update_addon.py 2013-04-12 12:21:16 UTC (rev 4467)
@@ -66,29 +66,26 @@
return module_name, mod[0]
-# As it's a bit time heavy, we cache that enum, operators using this should invalidate the cache in Invoke func
-# at least.
+# As it's a bit time heavy, I'd like to cache that enum, but this does not seem easy to do! :/
+# That "self" is not the same thing as the "self" that operators get in their invoke/execute/etc. funcs... :(
def enum_addons(self, context):
- items = getattr(self.__class__, "__enum_addons_cache", [])
- print(items)
- if not items:
- setts = getattr(self, "settings", settings.settings)
- for mod in addon_utils.modules(addon_utils.addons_fake_modules):
- mod_info = addon_utils.module_bl_info(mod)
- # Skip OFFICIAL addons, they are already translated in main i18n system (together with Blender itself).
- if mod_info["support"] in {'OFFICIAL'}:
- continue
- src = mod.__file__
- if src.endswith("__init__.py"):
- src = os.path.dirname(src)
- has_translation, _ = utils_i18n.I18n.check_py_module_has_translations(src, setts)
- name = mod_info["name"]
- #if has_translation:
- #name = name + " *"
- items.append((mod.__name__, name, mod_info["description"]))
- items.sort(key=lambda i: i[1])
- if hasattr(self.__class__, "__enum_addons_cache"):
- self.__class__.__enum_addons_cache = items
+ setts = getattr(self, "settings", settings.settings)
+ items = []
+ for mod in addon_utils.modules(addon_utils.addons_fake_modules):
+ mod_info = addon_utils.module_bl_info(mod)
+ # Skip OFFICIAL addons, they are already translated in main i18n system (together with Blender itself).
+ if mod_info["support"] in {'OFFICIAL'}:
+ continue
+ src = mod.__file__
+ if src.endswith("__init__.py"):
+ src = os.path.dirname(src)
+ has_translation, _ = utils_i18n.I18n.check_py_module_has_translations(src, setts)
+ name = mod_info["name"]
+ # XXX Gives ugly UUUUUUUUUUUUUUUUUUU in search list!
+ #if has_translation:
+ #name = name + " *"
+ items.append((mod.__name__, name, mod_info["description"]))
+ items.sort(key=lambda i: i[1])
return items
@@ -151,24 +148,31 @@
module_name = EnumProperty(items=enum_addons, name="Addon", description="Addon to process", options=set())
op_id = StringProperty(name="Operator Name", description="Name (id) of the operator to invoke")
+ # XXX Ugly hack! invoke_search_popup does not preserve ops' properties :(
+ _op_id = ""
- __enum_addons_cache = []
-
def invoke(self, context, event):
print("op_id:", self.op_id)
- self.__enum_addons_cache.clear()
+ # XXX Ugly hack! invoke_search_popup does not preserve ops' properties :(
+ self.__class__._op_id = self.op_id
context.window_manager.invoke_search_popup(self)
return {'RUNNING_MODAL'}
def execute(self, context):
- print("op_id:", self.op_id)
+ print("op_id:", self.op_id, self.__class__._op_id)
+ if not self.op_id:
+ # XXX Ugly hack! invoke_search_popup does not preserve ops' properties :(
+ if not self.__class__._op_id:
+ return {'CANCELLED'}
+ self.op_id = self.__class__._op_id
+ self.__class__._op_id = ""
op = bpy.ops
for item in self.op_id.split('.'):
op = getattr(op, item, None)
print(self.op_id, item, op)
if op is None:
return {'CANCELLED'}
- op('INVOKE_DEFAULT', module_name=self.module_name)
+ return op('INVOKE_DEFAULT', module_name=self.module_name)
class UI_OT_i18n_addon_translation_update(bpy.types.Operator):
"""Update given addon's translation data (found as a py tuple in the addon's source code)"""
@@ -177,8 +181,6 @@
module_name = EnumProperty(items=enum_addons, name="Addon", description="Addon to process", options=set())
- __enum_addons_cache = []
-
def execute(self, context):
if not hasattr(self, "settings"):
self.settings = settings.settings
@@ -212,8 +214,9 @@
# And merge!
for uid in uids:
- if uid in trans.trans:
- trans.trans[uid].update(pot, keep_old_commented=False)
+ 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!
@@ -233,8 +236,6 @@
description="Update existing po files, if any, instead of overwriting them")
directory = StringProperty(maxlen=1024, subtype='FILE_PATH', options={'HIDDEN', 'SKIP_SAVE'})
- __enum_addons_cache = []
-
def _dst(self, trans, path, uid, kind):
if kind == 'PO':
if uid == self.settings.PARSER_TEMPLATE_ID:
@@ -250,7 +251,6 @@
def invoke(self, context, event):
if not hasattr(self, "settings"):
self.settings = settings.settings
- self.__enum_addons_cache.clear()
module_name, mod = validate_module(self, context)
if mod:
self.directory = os.path.dirname(mod.__file__)
@@ -291,7 +291,7 @@
for uid in uids:
if uid == self.settings.PARSER_TEMPLATE_ID:
continue
- path = trans.dst(trans.src[uid], uid, 'PO')
+ 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)
Modified: trunk/py/scripts/addons/ui_translate/update_svn.py
===================================================================
--- trunk/py/scripts/addons/ui_translate/update_svn.py 2013-04-11 19:26:33 UTC (rev 4466)
+++ trunk/py/scripts/addons/ui_translate/update_svn.py 2013-04-12 12:21:16 UTC (rev 4467)
@@ -38,8 +38,6 @@
from bl_i18n_utils import utils as utils_i18n
from bl_i18n_utils import utils_languages_menu
-from bpy.app.translations import pgettext_iface as iface_
-
import io
import os
import shutil
@@ -47,176 +45,7 @@
import tempfile
-##### Data #####
-class I18nUpdateTranslationLanguage(bpy.types.PropertyGroup):
- """Settings/info about a language"""
- uid = StringProperty(name="Language ID", default="", description="ISO code, like fr_FR")
- num_id = IntProperty(name="Numeric ID", default=0, min=0, description="Numeric ID (readonly!)")
- name = StringProperty(name="Language Name", default="",
- description="English language name/label (like \"French (Français)\")")
- use = BoolProperty(name="Use", default=True, description="Use this language in current operator")
- po_path = StringProperty(name="PO File Path", default="", subtype='FILE_PATH',
- description="Path to the relevant po file in branches")
- po_path_trunk = StringProperty(name="PO Trunk File Path", default="", subtype='FILE_PATH',
- description="Path to the relevant po file in trunk")
- mo_path_trunk = StringProperty(name="MO File Path", default="", subtype='FILE_PATH',
- description="Path to the relevant mo file")
-
-
-class I18nUpdateTranslationSettings(bpy.types.PropertyGroup):
- """Settings/info about a language"""
- langs = CollectionProperty(name="Languages", type=I18nUpdateTranslationLanguage,
- description="Languages to update in branches")
- active_lang = IntProperty(name="Active Language", default=0,
- description="Index of active language in langs collection")
- pot_path = StringProperty(name="POT File Path", default="", subtype='FILE_PATH',
- description="Path to the pot template file")
- is_init = BoolProperty(default=False, options={'HIDDEN'},
- description="Whether these settings have already been auto-set or not")
-
-
-##### UI #####
-class UI_UL_i18n_languages(bpy.types.UIList):
- def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
- #assert(isinstance(item, bpy.types.I18nUpdateTranslationLanguage))
- if self.layout_type in {'DEFAULT', 'COMPACT'}:
- layout.label(item.name, icon_value=icon)
- layout.prop(item, "use", text="")
- elif self.layout_type in {'GRID'}:
- layout.alignment = 'CENTER'
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list