Translations utils: add needed bits to update git repo together with svn trunk.
authorBastien Montagne <montagne29@wanadoo.fr>
Sat, 13 Jun 2015 09:42:54 +0000 (11:42 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Sat, 13 Jun 2015 09:42:54 +0000 (11:42 +0200)
release/scripts/modules/bl_i18n_utils/settings.py
release/scripts/modules/bl_i18n_utils/utils.py
release/scripts/modules/bl_i18n_utils/utils_languages_menu.py

index 30ee3cdc7d89976c771bfdca554f2ebe24b20d43..1c960a217defdf14f198aa3bcf7c08ce15b7df58 100644 (file)
@@ -416,6 +416,15 @@ REL_TRUNK_PO_DIR = os.path.join(REL_TRUNK_DIR, "po")
 # The /trunk/mo path (relative to I18N_DIR).
 REL_TRUNK_MO_DIR = os.path.join(REL_TRUNK_DIR, "locale")
 
+
+# The path to the *git* translation repository (relative to SOURCE_DIR).
+REL_GIT_I18N_DIR = os.path.join("release/datafiles/locale")
+
+
+# The /po path of the *git* translation repository (relative to REL_GIT_I18N_DIR).
+REL_GIT_I18N_PO_DIR = os.path.join("po")
+
+
 # The Blender source path to check for i18n macros (relative to SOURCE_DIR).
 REL_POTFILES_SOURCE_DIR = os.path.join("source")
 
@@ -497,14 +506,6 @@ def _gen_get_set_path(ref, name):
     return _get, _set
 
 
-def _gen_get_set_paths(ref, name):
-    def _get(self):
-        return [_do_get(getattr(self, ref), p) for p in getattr(self, name)]
-    def _set(self, value):
-        setattr(self, name, [_do_set(getattr(self, ref), p) for p in value])
-    return _get, _set
-
-
 class I18nSettings:
     """
     Class allowing persistence of our settings!
@@ -556,6 +557,8 @@ class I18nSettings:
     TRUNK_DIR = property(*(_gen_get_set_path("I18N_DIR", "REL_TRUNK_DIR")))
     TRUNK_PO_DIR = property(*(_gen_get_set_path("I18N_DIR", "REL_TRUNK_PO_DIR")))
     TRUNK_MO_DIR = property(*(_gen_get_set_path("I18N_DIR", "REL_TRUNK_MO_DIR")))
+    GIT_I18N_ROOT = property(*(_gen_get_set_path("SOURCE_DIR", "REL_GIT_I18N_DIR")))
+    GIT_I18N_PO_DIR = property(*(_gen_get_set_path("GIT_I18N_ROOT", "REL_GIT_I18N_PO_DIR")))
     POTFILES_SOURCE_DIR = property(*(_gen_get_set_path("SOURCE_DIR", "REL_POTFILES_SOURCE_DIR")))
     FILE_NAME_POT = property(*(_gen_get_set_path("I18N_DIR", "REL_FILE_NAME_POT")))
     MO_PATH_ROOT = property(*(_gen_get_set_path("I18N_DIR", "REL_MO_PATH_ROOT")))
index d472621029e083233e0f10cb7b6dbd65255d2b0e..5fdb6b88cbf94d0a07297d15e691c73f2847c0cf 100644 (file)
@@ -981,13 +981,13 @@ class I18nMessages:
     def write(self, kind, dest):
         self.writers[kind](self, dest)
 
-    def write_messages_to_po(self, fname):
+    def write_messages_to_po(self, fname, compact=False):
         """
         Write messages in fname po file.
         """
         default_context = self.settings.DEFAULT_CONTEXT
 
-        def _write(self, f):
+        def _write(self, f, compact):
             _msgctxt = self.settings.PO_MSGCTXT
             _msgid = self.settings.PO_MSGID
             _msgstr = self.settings.PO_MSGSTR
@@ -996,9 +996,12 @@ class I18nMessages:
             self.escape()
 
             for num, msg in enumerate(self.msgs.values()):
-                f.write("\n".join(msg.comment_lines))
+                if compact and (msg.is_commented or msg.is_fuzzy or not msg.msgstr_lines):
+                    continue
+                if not compact:
+                    f.write("\n".join(msg.comment_lines))
                 # Only mark as fuzzy if msgstr is not empty!
-                if msg.is_fuzzy and msg.msgstr:
+                if msg.is_fuzzy and msg.msgstr_lines:
                     f.write("\n" + self.settings.PO_COMMENT_FUZZY)
                 _p = _comm if msg.is_commented else ""
                 chunks = []
@@ -1035,10 +1038,10 @@ class I18nMessages:
         self.normalize(max_len=0)  # No wrapping for now...
         if isinstance(fname, str):
             with open(fname, 'w', encoding="utf-8") as f:
-                _write(self, f)
+                _write(self, f, compact)
         # Else assume fname is already a file(like) object!
         else:
-            _write(self, fname)
+            _write(self, fname, compact)
 
     def write_messages_to_mo(self, fname):
         """
@@ -1117,6 +1120,7 @@ class I18nMessages:
 
     writers = {
         "PO": write_messages_to_po,
+        "PO_COMPACT": lambda s, fn: s.write_messages_to_po(fn, True),
         "MO": write_messages_to_mo,
     }
 
index 24255d9be61085fa42a9e7e8a8d6ff6a27da3b5a..4f499476ad9a295a441f20db1d16d02109716943 100755 (executable)
@@ -95,3 +95,5 @@ def gen_menu_file(stats, settings):
                 data_lines.append("# {} #{}:{}:{}".format(FLAG_MESSAGES[flag], uid_num, label, uid))
     with open(os.path.join(settings.TRUNK_MO_DIR, settings.LANGUAGES_FILE), 'w') as f:
         f.write("\n".join(data_lines))
+    with open(os.path.join(settings.GIT_I18N_ROOT, settings.LANGUAGES_FILE), 'w') as f:
+        f.write("\n".join(data_lines))