Cycles: svn merge -r41266:41467 ^/trunk/blender
[blender-staging.git] / po / update_pot.py
index b34b75f9740b477b0f69e4794a899321c30514eb..c5f9acb9f428f2ca65f7b2f22b3ac3d9c6cc03a7 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/env python
 
-# $Id:
 # ***** BEGIN GPL LICENSE BLOCK *****
 #
 # This program is free software; you can redistribute it and/or
 
 import subprocess
 import os
+from codecs import open
 
 GETTEXT_XGETTEXT_EXECUTABLE = "xgettext"
-CURRENT_DIR = os.path.dirname(__file__)
+CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
 SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.join(CURRENT_DIR, "..")))
 DOMAIN = "blender"
+COMMENT_PREFIX = "#~ "  # from update_msg.py
 
 FILE_NAME_POT = os.path.join(CURRENT_DIR, "blender.pot")
 FILE_NAME_MESSAGES = os.path.join(CURRENT_DIR, "messages.txt")
@@ -55,7 +56,7 @@ def main():
     pot_messages = {}
     reading_message = False
     message = ""
-    with open(FILE_NAME_POT, 'r') as handle:
+    with open(FILE_NAME_POT, 'r', "utf-8") as handle:
         while True:
             line = handle.readline()
 
@@ -73,8 +74,9 @@ def main():
                 message += line[1:-1]
 
     # add messages collected automatically from RNA
-    with open(FILE_NAME_POT, "a") as pot_handle:
-        with open(FILE_NAME_MESSAGES, 'r') as handle:
+    with open(FILE_NAME_POT, "a", "utf-8") as pot_handle:
+        with open(FILE_NAME_MESSAGES, 'r', "utf-8") as handle:
+            msgsrc_ls = []
             while True:
                 line = handle.readline()
 
@@ -82,13 +84,21 @@ def main():
                     break
 
                 line = stripeol(line)
-                line = line.replace("\\", "\\\\")
-                line = line.replace("\"", "\\\"")
 
-                if not pot_messages.get(line):
-                    pot_handle.write("\n#: Automatically collected from RNA\n")
-                    pot_handle.write("msgid \"%s\"\n" % (line))
-                    pot_handle.write("msgstr \"\"\n")
+                # COMMENT_PREFIX
+                if line.startswith(COMMENT_PREFIX):
+                    msgsrc_ls.append(line[len(COMMENT_PREFIX):].strip())
+                else:
+                    line = line.replace("\\", "\\\\")
+                    line = line.replace("\"", "\\\"")
+                    line = line.replace("\t", "\\t")
+
+                    if not pot_messages.get(line):
+                        for msgsrc in msgsrc_ls:
+                            pot_handle.write("#: %s\n" % msgsrc)
+                        pot_handle.write("msgid \"%s\"\n" % line)
+                        pot_handle.write("msgstr \"\"\n\n")
+                    msgsrc_ls[:] = []
 
 
 if __name__ == "__main__":