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