[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55646] trunk/blender/release/scripts/ modules/bl_i18n_utils/bl_extract_messages.py: I18n: fix/ enhance how predefined contexts are handled in py code.
Bastien Montagne
montagne29 at wanadoo.fr
Thu Mar 28 16:03:48 CET 2013
Revision: 55646
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55646
Author: mont29
Date: 2013-03-28 15:03:47 +0000 (Thu, 28 Mar 2013)
Log Message:
-----------
I18n: fix/enhance how predefined contexts are handled in py code. Now they should be specified by an attribute with the same name as the one in bpy.app.translations.contexts named tuple (i18n_contexts.default, .id_windowmanager, etc.).
This way, i18n message extracting code is now able to get the right context!
Modified Paths:
--------------
trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
Modified: trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py
===================================================================
--- trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py 2013-03-28 10:32:04 UTC (rev 55645)
+++ trunk/blender/release/scripts/modules/bl_i18n_utils/bl_extract_messages.py 2013-03-28 15:03:47 UTC (rev 55646)
@@ -409,6 +409,7 @@
import ast
bpy_struct = bpy.types.ID.__base__
+ i18n_contexts = bpy.app.translations.contexts
root_paths = tuple(bpy.utils.resource_path(t) for t in ('USER', 'LOCAL', 'SYSTEM'))
def make_rel(path):
@@ -468,20 +469,33 @@
return [_extract_string_merge(estr_ls, nds_ls) for estr_ls, nds_ls in bag]
+ i18n_ctxt_ids = {v for v in bpy.app.translations.contexts_C_to_py.values()}
def _ctxt_to_ctxt(node):
- return extract_strings(node)[0]
+ # We must try, to some extend, to get contexts from vars instead of only literal strings...
+ ctxt = extract_strings(node)[0]
+ if ctxt:
+ return ctxt
+ # Basically, we search for attributes matching py context names, for now.
+ # So non-literal contexts should be used that way:
+ # i18n_ctxt = bpy.app.translations.contexts
+ # foobar(text="Foo", text_ctxt=i18n_ctxt.id_object)
+ if type(node) == ast.Attribute:
+ if node.attr in i18n_ctxt_ids:
+ #print(node, node.attr, getattr(i18n_contexts, node.attr))
+ return getattr(i18n_contexts, node.attr)
+ return i18n_contexts.default
def _op_to_ctxt(node):
opname, _ = extract_strings(node)
if not opname:
- return settings.DEFAULT_CONTEXT
+ return i18n_contexts.default
op = bpy.ops
for n in opname.split('.'):
op = getattr(op, n)
try:
return op.get_rna().bl_rna.translation_context
except Exception as e:
- default_op_context = bpy.app.translations.contexts.operator_default
+ default_op_context = i18n_contexts.operator_default
print("ERROR: ", str(e))
print(" Assuming default operator context '{}'".format(default_op_context))
return default_op_context
@@ -492,7 +506,8 @@
pgettext_variants = (
("pgettext", ("_",)),
("pgettext_iface", ("iface_",)),
- ("pgettext_tip", ("tip_",))
+ ("pgettext_tip", ("tip_",)),
+ ("pgettext_data", ("data_",)),
)
pgettext_variants_args = {"msgid": (0, {"msgctxt": 1})}
@@ -858,9 +873,8 @@
# and make the diff!
for key in minus_msgs:
- if key == settings.PO_HEADER_KEY:
- continue
- del msgs[key]
+ if key != settings.PO_HEADER_KEY:
+ del msgs[key]
if check_ctxt:
for key in check_ctxt:
@@ -873,7 +887,7 @@
# get strings from UI layout definitions text="..." args
reports["check_ctxt"] = check_ctxt
- dump_messages_pytext(msgs, reports, addons, settings, addons_only=True)
+ dump_py_messages(msgs, reports, {addon}, settings, addons_only=True)
print_info(reports, pot)
More information about the Bf-blender-cvs
mailing list