[Bf-translations-svn] SVN commit: /data/svn/bf-translations [276] trunk/po/tools: First commit to match new context-enabled strings in Blender.

bf-translations at blender.org bf-translations at blender.org
Thu Dec 22 21:35:17 CET 2011


Revision: 276
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-translations&revision=276
Author:   mont29
Date:     2011-12-22 20:35:14 +0000 (Thu, 22 Dec 2011)
Log Message:
-----------
First commit to match new context-enabled strings in Blender. Based on patch by Sergey Sharybin.

Generating code should be ok. Also updated the "stat" part of the code, but yet have to check the other files?\226?\128?\166

Also changed format of source comment strings for enums: instead of "py.path, 'ENUM'", now using "py.path:'ENUM'" (former format was giving some minor problems with msgmerge...).

NOTE: If you are using tools under /trunk/po/tools, you need to update your settings.py file, to add the new CONTEXT_PREFIX one.

Instructions on how to use/request a new context will follow on bf-translations-dev ML.

Modified Paths:
--------------
    trunk/po/tools/_update_msg.py
    trunk/po/tools/check_po.py
    trunk/po/tools/settings_template.py
    trunk/po/tools/update_pot.py
    trunk/po/tools/utils.py

Modified: trunk/po/tools/_update_msg.py
===================================================================
--- trunk/po/tools/_update_msg.py	2011-12-22 15:12:23 UTC (rev 275)
+++ trunk/po/tools/_update_msg.py	2011-12-22 20:35:14 UTC (rev 276)
@@ -33,7 +33,8 @@
 SOURCE_DIR = settings.SOURCE_DIR
 
 FILE_NAME_MESSAGES = settings.FILE_NAME_MESSAGES
-COMMENT_PREFIX = settings.COMMENT_PREFIX
+COMMENT_PREFIX     = settings.COMMENT_PREFIX
+CONTEXT_PREFIX     = settings.CONTEXT_PREFIX
 
 
 def dump_messages_rna(messages):
@@ -125,20 +126,30 @@
             if prop.identifier == "rna_type":
                 continue
 
-            msgsrc = "bpy.types.%s.%s" % (bl_rna.identifier, prop.identifier)
+            msgsrc = "bpy.types.{}.{}".format(bl_rna.identifier, prop.identifier)
             if prop.name and prop.name != prop.identifier:
-                messages.setdefault(prop.name, []).append(msgsrc)
+                if prop.translation_context:
+                    fullname = "{}{} {}".format(CONTEXT_PREFIX,
+                                                prop.translation_context,
+                                                prop.name)
+                else:
+                    fullname = prop.name
+                messages.setdefault(fullname, []).append(msgsrc)
             if prop.description:
                 messages.setdefault(prop.description, []).append(msgsrc)
-
             if isinstance(prop, bpy.types.EnumProperty):
                 for item in prop.enum_items:
-                    msgsrc = "bpy.types.%s.%s, '%s'" % (bl_rna.identifier,
-                                                        prop.identifier,
-                                                        item.identifier,
-                                                        )
+                    msgsrc = "bpy.types.{}.{}:'{}'".format(bl_rna.identifier,
+                                                            prop.identifier,
+                                                            item.identifier)
                     if item.name and item.name != item.identifier:
-                        messages.setdefault(item.name, []).append(msgsrc)
+                        if prop.translation_context:
+                            fullname = "{}{} {}".format(CONTEXT_PREFIX,
+                                                        prop.translation_context,
+                                                        item.name)
+                        else:
+                            fullname = item.name
+                        messages.setdefault(fullname, []).append(msgsrc)
                     if item.description:
                         messages.setdefault(item.description, []).append(msgsrc)
 
@@ -164,7 +175,7 @@
 
     def walk_keymap_hierarchy(hier, msgsrc_prev):
         for lvl in hier:
-            msgsrc = "%s.%s" % (msgsrc_prev, lvl[1])
+            msgsrc = "{}.{}".format(msgsrc_prev, lvl[1])
             messages.setdefault(lvl[0], []).append(msgsrc)
 
             if lvl[3]:
@@ -183,7 +194,7 @@
             cls_id = ""
             bl_rna = cls.bl_rna
             while bl_rna:
-                cls_id = "%s.%s" % (bl_rna.identifier, cls_id)
+                cls_id = "{}.{}".format(bl_rna.identifier, cls_id)
                 bl_rna = bl_rna.base
             return cls_id
 
@@ -247,7 +258,7 @@
         if type(node) == ast.Str:
             eval_str = ast.literal_eval(node)
             if eval_str:
-                msgsrc = "%s:%s" % (fp_rel, node.lineno)
+                msgsrc = "{}:{}".format(fp_rel, node.lineno)
                 messages.setdefault(eval_str, []).append(msgsrc)
             return
 

Modified: trunk/po/tools/check_po.py
===================================================================
--- trunk/po/tools/check_po.py	2011-12-22 15:12:23 UTC (rev 275)
+++ trunk/po/tools/check_po.py	2011-12-22 20:35:14 UTC (rev 276)
@@ -102,7 +102,8 @@
                   "lvl_ttips_in_trans": 0.0,
                   "lvl_comm"          : 0.0,
                   "nbr_signs"         : 0,
-                  "nbr_trans_signs"   : 0}
+                  "nbr_trans_signs"   : 0,
+                  "contexts"          : set()}
     ret = 0
 
     pot_messages = None
@@ -149,12 +150,14 @@
               "    {:>6.1%} of messages are commented.\n" \
               "    The org msgids are currently made of {} signs.\n" \
               "    All processed translations are currently made of {} signs.\n" \
+              "    {} specific contexts are present:\n            {}" \
               "".format(glob_stats["nbr"], glob_stats["lvl"]/glob_stats["nbr"],
                         glob_stats["lvl_ttips"]/glob_stats["nbr"],
                         glob_stats["lvl_trans_ttips"]/glob_stats["nbr"],
                         glob_stats["lvl_ttips_in_trans"]/glob_stats["nbr"],
                         glob_stats["lvl_comm"]/glob_stats["nbr"], glob_stats["nbr_signs"],
-                        glob_stats["nbr_trans_signs"]))
+                        glob_stats["nbr_trans_signs"], len(glob_stats["contexts"]-{""}),
+                        "\n            ".join(glob_stats["contexts"]-{""})))
 
     return ret
 

Modified: trunk/po/tools/settings_template.py
===================================================================
--- trunk/po/tools/settings_template.py	2011-12-22 15:12:23 UTC (rev 275)
+++ trunk/po/tools/settings_template.py	2011-12-22 20:35:14 UTC (rev 276)
@@ -38,6 +38,9 @@
 # The comment prefix used in generated messages.txt file.
 COMMENT_PREFIX = "#~ "
 
+# The comment prefix used in generated messages.txt file.
+CONTEXT_PREFIX = "MSGCTXT:"
+
 # The gettext domain.
 DOMAIN = "blender"
 

Modified: trunk/po/tools/update_pot.py
===================================================================
--- trunk/po/tools/update_pot.py	2011-12-22 15:12:23 UTC (rev 275)
+++ trunk/po/tools/update_pot.py	2011-12-22 20:35:14 UTC (rev 276)
@@ -34,6 +34,7 @@
 
 
 COMMENT_PREFIX     = settings.COMMENT_PREFIX
+CONTEXT_PREFIX     = settings.CONTEXT_PREFIX
 FILE_NAME_MESSAGES = settings.FILE_NAME_MESSAGES
 FILE_NAME_POTFILES = settings.FILE_NAME_POTFILES
 FILE_NAME_POT      = settings.FILE_NAME_POT
@@ -98,9 +99,9 @@
     # XXX That !%$¿@# xgettext generates an non-encoded pot file!
     #     So we have to add utf-8 code in header ourself (needed when
     #     adding new languages...)!
-    for i, l in enumerate(pot_messages[""]["msgstr_lines"]):
+    for i, l in enumerate(pot_messages[("", "")]["msgstr_lines"]):
         if l == r"Content-Type: text/plain; charset=CHARSET\n":
-            pot_messages[""]["msgstr_lines"][i] = r"Content-Type: text/plain; charset=UTF-8\n"
+            pot_messages[("", "")]["msgstr_lines"][i] = r"Content-Type: text/plain; charset=UTF-8\n"
     print("Finished, {} messages found.".format(stats["tot_msg"]))
 
     # add messages collected automatically from RNA
@@ -120,14 +121,20 @@
                 line = line.replace("\\", "\\\\")
                 line = line.replace("\"", "\\\"")
                 line = line.replace("\t", "\\t")
-                if not line in pot_messages:
-                    pot_messages[line] = {"msgid_lines": [line],
-                                          "msgstr_lines": [""],
-                                          "comment_lines": msgsrc_ls}
+                context = ""
+                if line.startswith(CONTEXT_PREFIX):
+                    context = line[len(CONTEXT_PREFIX):].split()[0]
+                    line = line[len(CONTEXT_PREFIX)+len(context)+1:]
+                key = (line, context)
+                if key not in pot_messages:
+                    pot_messages[key] = {"msgid_lines": [line],
+                                         "msgstr_lines": [""],
+                                         "comment_lines": msgsrc_ls,
+                                         "msgctxt_lines": [context]}
                     num_added += 1
                 else:
                     # We need to merge comments!
-                    pot_messages[line]["comment_lines"].extend(msgsrc_ls)
+                    pot_messages[key]["comment_lines"].extend(msgsrc_ls)
                     num_present += 1
                     if args.warning:
                         print("    WARNING: Following message was found in " \

Modified: trunk/po/tools/utils.py
===================================================================
--- trunk/po/tools/utils.py	2011-12-22 15:12:23 UTC (rev 275)
+++ trunk/po/tools/utils.py	2011-12-22 20:35:14 UTC (rev 276)
@@ -37,11 +37,10 @@
 def is_tooltip(msgid):
     return len(msgid) > 30
 
-
 def parse_messages(fname):
     """
     Returns a tupple (messages, states, stats).
-    messages is an odereddict of dicts {msgid: {msgid_lines:, msgstr_lines:, comment_lines:}}.
+    messages is an odereddict of dicts {ctxt: {msgid: {msgid_lines:, msgstr_lines:, comment_lines:}}}.
     states is a dict of three sets of msgid, and a boolean flag indicating the .po is somewhat
            broken {trans_msg:, fuzzy_msg:, comm_msg:, is_broken:}.
     stats is a dict of values {tot_msg:, trans_msg:, tot_ttips:, trans_ttips:, comm_msg:,
@@ -56,8 +55,10 @@
     comm_messages = 0
     nbr_signs = 0
     nbr_trans_signs = 0
+    contexts = set()
     reading_msgid = False
     reading_msgstr = False
+    reading_msgctxt = False
     reading_comment = False
     is_translated = False
     is_fuzzy = False
@@ -65,6 +66,7 @@
     is_broken = False
     msgid_lines = []
     msgstr_lines = []
+    msgctxt_lines = []
     comment_lines = []
 
     if hasattr(collections, 'OrderedDict'):
@@ -77,43 +79,48 @@
 
 
     def clean_vars():
-        nonlocal reading_msgid, reading_msgstr, reading_comment, \
+        nonlocal reading_msgid, reading_msgstr, reading_msgctxt, reading_comment, \
                  is_fuzzy, is_translated, is_commented, \
-                 msgid_lines, msgstr_lines, comment_lines
-        reading_msgid = reading_msgstr = reading_comment = False
+                 msgid_lines, msgstr_lines, msgctxt_lines, comment_lines
+        reading_msgid = reading_msgstr = reading_msgctxt = reading_comment = False
         is_tooltip = is_fuzzy = is_translated = is_commented = False
         msgid_lines = []
         msgstr_lines = []
+        msgctxt_lines = []
         comment_lines = []
 
 
     def finalize_message():
-        nonlocal reading_msgid, reading_msgstr, reading_comment, \

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-translations-svn mailing list