4 # ***** BEGIN GPL LICENSE BLOCK *****
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # ***** END GPL LICENSE BLOCK *****
24 # update the pot file according the POTFILES.in
28 from codecs import open
30 GETTEXT_XGETTEXT_EXECUTABLE = "xgettext"
31 CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
32 SOURCE_DIR = os.path.normpath(os.path.abspath(os.path.join(CURRENT_DIR, "..")))
34 COMMENT_PREFIX = "#~ " # from update_msg.py
36 FILE_NAME_POT = os.path.join(CURRENT_DIR, "blender.pot")
37 FILE_NAME_MESSAGES = os.path.join(CURRENT_DIR, "messages.txt")
41 cmd = (GETTEXT_XGETTEXT_EXECUTABLE,
42 "--files-from=%s" % os.path.join(SOURCE_DIR, "po", "POTFILES.in"),
45 "--directory=%s" % SOURCE_DIR,
46 "--output=%s" % os.path.join(SOURCE_DIR, "po", "%s.pot" % DOMAIN),
51 process = subprocess.Popen(cmd)
55 return s.rstrip("\n\r")
58 reading_message = False
60 with open(FILE_NAME_POT, 'r', "utf-8") as handle:
62 line = handle.readline()
68 if line.startswith("msgid"):
69 reading_message = True
71 elif line.startswith("msgstr"):
72 reading_message = False
73 pot_messages[message] = True
77 # add messages collected automatically from RNA
78 with open(FILE_NAME_POT, "a", "utf-8") as pot_handle:
79 with open(FILE_NAME_MESSAGES, 'r', "utf-8") as handle:
82 line = handle.readline()
90 if line.startswith(COMMENT_PREFIX):
91 msgsrc_ls.append(line[len(COMMENT_PREFIX):].strip())
93 line = line.replace("\\", "\\\\")
94 line = line.replace("\"", "\\\"")
95 line = line.replace("\t", "\\t")
97 if not pot_messages.get(line):
98 for msgsrc in msgsrc_ls:
99 pot_handle.write("#: %s\n" % msgsrc)
100 pot_handle.write("msgid \"%s\"\n" % line)
101 pot_handle.write("msgstr \"\"\n\n")
105 if __name__ == "__main__":
106 print("\n\n *** Running %r *** \n" % __file__)