[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48503] trunk/blender/release/scripts/ modules: Adding (moving from bf-translation) the i18n python module.

Bastien Montagne montagne29 at wanadoo.fr
Mon Jul 2 21:51:20 CEST 2012


Revision: 48503
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48503
Author:   mont29
Date:     2012-07-02 19:51:06 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
Adding (moving from bf-translation) the i18n python module. This will make it available for future "UI Translation" addon, and probably other UI-related tools as well.

Notes:
* This is a somewhat reworked version of what is currently in bf-translation's trunk/po/tools, not yet fully functionnal (well, 95% is ;) ) nor fully tested. ultimately, it will replace it (being "svn-linked" in bf-translation).
* Added feature: more complete/strict tests (yet some work to be done here).
* Added spell checking (huge spellcheck commit incomming...).
* Trying to get rid of xgettext itself (should e.g. allow us to use #defines as contexts, among other things...). But currently captures less strings, work needed here too.

Please note this includes libfribidi.dll, as it is hard to find it for windows (unixes should have no problems here).

Added Paths:
-----------
    trunk/blender/release/scripts/modules/i18n/
    trunk/blender/release/scripts/modules/i18n/__init__.py
    trunk/blender/release/scripts/modules/i18n/bl_process_msg.py
    trunk/blender/release/scripts/modules/i18n/check_po.py
    trunk/blender/release/scripts/modules/i18n/clean_po.py
    trunk/blender/release/scripts/modules/i18n/import_po_from_branches.py
    trunk/blender/release/scripts/modules/i18n/libfribidi.dll
    trunk/blender/release/scripts/modules/i18n/merge_po.py
    trunk/blender/release/scripts/modules/i18n/rtl_preprocess.py
    trunk/blender/release/scripts/modules/i18n/settings.py
    trunk/blender/release/scripts/modules/i18n/spell_check_utils.py
    trunk/blender/release/scripts/modules/i18n/update_branches.py
    trunk/blender/release/scripts/modules/i18n/update_mo.py
    trunk/blender/release/scripts/modules/i18n/update_msg.py
    trunk/blender/release/scripts/modules/i18n/update_po.py
    trunk/blender/release/scripts/modules/i18n/update_pot.py
    trunk/blender/release/scripts/modules/i18n/update_trunk.py
    trunk/blender/release/scripts/modules/i18n/user_settings.py
    trunk/blender/release/scripts/modules/i18n/utils.py

Added: trunk/blender/release/scripts/modules/i18n/__init__.py
===================================================================
--- trunk/blender/release/scripts/modules/i18n/__init__.py	                        (rev 0)
+++ trunk/blender/release/scripts/modules/i18n/__init__.py	2012-07-02 19:51:06 UTC (rev 48503)
@@ -0,0 +1,21 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+"""Package for translation (i18n) tools."""


Property changes on: trunk/blender/release/scripts/modules/i18n/__init__.py
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/blender/release/scripts/modules/i18n/bl_process_msg.py
===================================================================
--- trunk/blender/release/scripts/modules/i18n/bl_process_msg.py	                        (rev 0)
+++ trunk/blender/release/scripts/modules/i18n/bl_process_msg.py	2012-07-02 19:51:06 UTC (rev 48503)
@@ -0,0 +1,544 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+# <pep8-80 compliant>
+
+# Write out messages.txt from Blender.
+# XXX: This script is meant to be used from inside Blender!
+#      You should not directly use this script, rather use update_msg.py!
+
+import os
+
+# Quite an ugly hack… But the simplest solution for now!
+#import sys
+#sys.path.append(os.path.abspath(os.path.dirname(__file__)))
+import i18n.settings as settings
+
+
+#classes = set()
+
+
+SOURCE_DIR = settings.SOURCE_DIR
+
+CUSTOM_PY_UI_FILES = [os.path.abspath(os.path.join(SOURCE_DIR, p))
+                      for p in settings.CUSTOM_PY_UI_FILES]
+FILE_NAME_MESSAGES = settings.FILE_NAME_MESSAGES
+COMMENT_PREFIX = settings.COMMENT_PREFIX
+CONTEXT_PREFIX = settings.CONTEXT_PREFIX
+CONTEXT_DEFAULT = settings.CONTEXT_DEFAULT
+UNDOC_OPS_STR = settings.UNDOC_OPS_STR
+
+NC_ALLOWED = settings.WARN_MSGID_NOT_CAPITALIZED_ALLOWED
+
+def check(check_ctxt, messages, key, msgsrc):
+    if check_ctxt is None:
+        return
+    multi_rnatip = check_ctxt.get("multi_rnatip")
+    multi_lines = check_ctxt.get("multi_lines")
+    py_in_rna = check_ctxt.get("py_in_rna")
+    not_capitalized = check_ctxt.get("not_capitalized")
+    end_point = check_ctxt.get("end_point")
+    undoc_ops = check_ctxt.get("undoc_ops")
+
+    if multi_rnatip is not None:
+        if key in messages and key not in multi_rnatip:
+            multi_rnatip.add(key)
+    if multi_lines is not None:
+        if '\n' in key[1]:
+            multi_lines.add(key)
+    if py_in_rna is not None:
+        if key in py_in_rna[1]:
+            py_in_rna[0].add(key)
+    if not_capitalized is not None:
+        if(key[1] not in NC_ALLOWED and key[1][0].isalpha() and
+           not key[1][0].isupper()):
+            not_capitalized.add(key)
+    if end_point is not None:
+        if key[1].strip().endswith('.'):
+            end_point.add(key)
+    if undoc_ops is not None:
+        if key[1] == UNDOC_OPS_STR:
+            undoc_ops.add(key)
+
+
+def dump_messages_rna(messages, check_ctxt):
+    import bpy
+
+    def classBlackList():
+        blacklist_rna_class = [# core classes
+                               "Context", "Event", "Function", "UILayout",
+                               "BlendData",
+                               # registerable classes
+                               "Panel", "Menu", "Header", "RenderEngine",
+                               "Operator", "OperatorMacro", "Macro",
+                               "KeyingSetInfo", "UnknownType",
+                               # window classes
+                               "Window",
+                               ]
+
+        # ---------------------------------------------------------------------
+        # Collect internal operators
+
+        # extend with all internal operators
+        # note that this uses internal api introspection functions
+        # all possible operator names
+        op_ids = set(cls.bl_rna.identifier for cls in
+                     bpy.types.OperatorProperties.__subclasses__()) | \
+                 set(cls.bl_rna.identifier for cls in
+                     bpy.types.Operator.__subclasses__()) | \
+                 set(cls.bl_rna.identifier for cls in
+                     bpy.types.OperatorMacro.__subclasses__())
+
+        get_instance = __import__("_bpy").ops.get_instance
+        path_resolve = type(bpy.context).__base__.path_resolve
+        for idname in op_ids:
+            op = get_instance(idname)
+            if 'INTERNAL' in path_resolve(op, "bl_options"):
+                blacklist_rna_class.append(idname)
+
+        # ---------------------------------------------------------------------
+        # Collect builtin classes we don't need to doc
+        blacklist_rna_class.append("Property")
+        blacklist_rna_class.extend(
+                [cls.__name__ for cls in
+                 bpy.types.Property.__subclasses__()])
+
+        # ---------------------------------------------------------------------
+        # Collect classes which are attached to collections, these are api
+        # access only.
+        collection_props = set()
+        for cls_id in dir(bpy.types):
+            cls = getattr(bpy.types, cls_id)
+            for prop in cls.bl_rna.properties:
+                if prop.type == 'COLLECTION':
+                    prop_cls = prop.srna
+                    if prop_cls is not None:
+                        collection_props.add(prop_cls.identifier)
+        blacklist_rna_class.extend(sorted(collection_props))
+
+        return blacklist_rna_class
+
+    blacklist_rna_class = classBlackList()
+
+    def filterRNA(bl_rna):
+        rid = bl_rna.identifier
+        if rid in blacklist_rna_class:
+            print("  skipping", rid)
+            return True
+        return False
+
+    check_ctxt_rna = check_ctxt_rna_tip = None
+    if check_ctxt:
+        check_ctxt_rna = {"multi_lines": check_ctxt.get("multi_lines"),
+                          "not_capitalized": check_ctxt.get("not_capitalized"),
+                          "end_point": check_ctxt.get("end_point"),
+                          "undoc_ops": check_ctxt.get("undoc_ops")}
+        check_ctxt_rna_tip = check_ctxt_rna
+        check_ctxt_rna_tip["multi_rnatip"] = check_ctxt.get("multi_rnatip")
+
+    # -------------------------------------------------------------------------
+    # Function definitions
+
+    def walkProperties(bl_rna):
+        import bpy
+
+        # Get our parents' properties, to not export them multiple times.
+        bl_rna_base = bl_rna.base
+        if bl_rna_base:
+            bl_rna_base_props = bl_rna_base.properties.values()
+        else:
+            bl_rna_base_props = ()
+
+        for prop in bl_rna.properties:
+            # Only write this property if our parent hasn't got it.
+            if prop in bl_rna_base_props:
+                continue
+            if prop.identifier == "rna_type":
+                continue
+
+            msgsrc = "bpy.types.{}.{}".format(bl_rna.identifier, prop.identifier)
+            context = getattr(prop, "translation_context", CONTEXT_DEFAULT)
+            if prop.name and (prop.name != prop.identifier or context):
+                key = (context, prop.name)
+                check(check_ctxt_rna, messages, key, msgsrc)
+                messages.setdefault(key, []).append(msgsrc)
+            if prop.description:
+                key = (CONTEXT_DEFAULT, prop.description)
+                check(check_ctxt_rna_tip, messages, key, msgsrc)
+                messages.setdefault(key, []).append(msgsrc)
+            if isinstance(prop, bpy.types.EnumProperty):
+                for item in prop.enum_items:
+                    msgsrc = "bpy.types.{}.{}:'{}'".format(bl_rna.identifier,
+                                                            prop.identifier,
+                                                            item.identifier)
+                    if item.name and item.name != item.identifier:
+                        key = (CONTEXT_DEFAULT, item.name)
+                        check(check_ctxt_rna, messages, key, msgsrc)
+                        messages.setdefault(key, []).append(msgsrc)
+                    if item.description:
+                        key = (CONTEXT_DEFAULT, item.description)
+                        check(check_ctxt_rna_tip, messages, key, msgsrc)
+                        messages.setdefault(key, []).append(msgsrc)
+
+    def walkRNA(bl_rna):
+        if filterRNA(bl_rna):
+            return
+
+        msgsrc = ".".join(("bpy.types", bl_rna.identifier))
+        context = getattr(bl_rna, "translation_context", CONTEXT_DEFAULT)
+
+        if bl_rna.name and (bl_rna.name != bl_rna.identifier or context):
+            key = (context, bl_rna.name)
+            check(check_ctxt_rna, messages, key, msgsrc)
+            messages.setdefault(key, []).append(msgsrc)
+
+        if bl_rna.description:
+            key = (CONTEXT_DEFAULT, bl_rna.description)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list