OSDN Git Service

Move gettext mo file generation out of source/generate.py and in to scons:
authorMichael Curran <mick@kulgan.net>
Sat, 13 Nov 2010 07:56:19 +0000 (17:56 +1000)
committerMichael Curran <mick@kulgan.net>
Sat, 13 Nov 2010 07:56:19 +0000 (17:56 +1000)
*Added a gettext scons tool to site_scons/site_tools. This tool provides a gettextMoFile builder, which takes a gettext template file (.po) and compiles it using msgfmt to a .mo.
*NVDA root sconstruct: cause all of NVDA's po files to be compiled to mo files if source is being built.
*Removed locale compilation code from source/generate.py as its now redundant.

sconstruct
site_scons/site_tools/gettext.py [new file with mode: 0644]
source/generate.py

index 056c858..45b4e0e 100755 (executable)
@@ -69,7 +69,7 @@ if len(unknown)>0:
        print "Unknown commandline variables: %s"%unknown\r
        Exit(1)\r
 \r
-env = Environment(variables=vars,tools=["textfile"])\r
+env = Environment(variables=vars,tools=["textfile","gettext"])\r
 version = env["version"]\r
 release = env["release"]\r
 certFile = env["certFile"]\r
@@ -81,13 +81,17 @@ sourceLibDir=sourceDir.Dir('lib')
 Export('sourceLibDir')\r
 sourceLibDir64=sourceDir.Dir('lib64')\r
 Export('sourceLibDir64')\r
-\r
 buildDir = Dir("build")\r
 outFilePrefix = "nvda{type}_{version}".format(type="" if release else "_snapshot", version=version)\r
 \r
 #Process nvdaHelper scons files\r
 env.SConscript('nvdaHelper/sconscript',exports=['env'])\r
 \r
+#Allow all NVDA's gettext po files to be compiled in source/locale\r
+print sourceDir.path\r
+for po in env.Glob(sourceDir.path+'/locale/*/lc_messages/*.po'):\r
+       m=env.gettextMoFile(po)\r
+\r
 # A builder to generate an NVDA distribution.\r
 def NVDADistGenerator(target, source, env, for_signature):\r
        buildCmd = ["cd", source[0].path, "&&",\r
diff --git a/site_scons/site_tools/gettext.py b/site_scons/site_tools/gettext.py
new file mode 100644 (file)
index 0000000..2697199
--- /dev/null
@@ -0,0 +1,43 @@
+###\r
+#This file is a part of the NVDA project.\r
+#URL: http://www.nvda-project.org/\r
+#Copyright 2010 James Teh <jamie@jantrid.net>.\r
+#This program is free software: you can redistribute it and/or modify\r
+#it under the terms of the GNU General Public License version 2.0, as published by\r
+#the Free Software Foundation.\r
+#This program is distributed in the hope that it will be useful,\r
+#but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
+#This license can be found at:\r
+#http://www.gnu.org/licenses/old-licenses/gpl-2.0.html\r
+###\r
+\r
+import os\r
+import sys\r
+import imp\r
+import glob\r
+\r
+_msgfmt=None\r
+def loadMsgfmt():\r
+       global _msgfmt\r
+       if not _msgfmt:\r
+               modInfo=imp.find_module('msgfmt',[os.path.join(sys.prefix,'tools/i18n')])\r
+               _msgfmt=imp.load_module('msgfmt',*modInfo)\r
+       else:\r
+               _msgfmt.MESSAGES={}\r
+       return _msgfmt\r
+\r
+def gettextMoFile_actionFunc(target,source,env):\r
+       msgfmt=loadMsgfmt()\r
+       msgfmt.make(source[0].abspath,target[0].abspath)\r
+       return 0\r
+\r
+def exists(env):\r
+       return bool(loadMsgfmt())\r
+\r
+def generate(env):\r
+       env['BUILDERS']['gettextMoFile']=env.Builder(\r
+               action=env.Action(gettextMoFile_actionFunc,lambda t,s,e: 'Compiling gettext template %s'%s[0].path),\r
+               suffix='.mo',\r
+               src_suffix='.po'\r
+       )\r
index 7e307a9..b1e8a55 100755 (executable)
@@ -21,9 +21,6 @@ sys.modules['comtypes.gen']=comtypes.gen=__import__("comInterfaces",globals(),lo
 import os\r
 from glob import glob\r
 import txt2tags\r
-__path__ = [os.path.join(sys.exec_prefix, "Tools", "i18n")]\r
-import msgfmt\r
-del __path__\r
 import keyCommandsDoc\r
 \r
 COM_INTERFACES = (\r
@@ -47,15 +44,6 @@ def main():
                        print "not found."\r
        print\r
 \r
-       print "Language files:"\r
-       poFiles=glob('locale/*/LC_MESSAGES/nvda.po')\r
-       for f in poFiles:\r
-               print f\r
-               msgfmt.make(f, None)\r
-               #Clear msgfmt.MESSAGES so that msgfmt.make can safely be called again in the next iteration\r
-               msgfmt.MESSAGES.clear()\r
-       print\r
-\r
        print "HTML documentation (except Key Commands):"\r
        files = glob(r"..\user_docs\*\*.t2t")\r
        # Using txt2tags as a module to handle files is a bit weird.\r