]> git.lyx.org Git - features.git/commitdiff
Scons: update_po target, part one: language_l10n.pot
authorBo Peng <bpeng@lyx.org>
Wed, 21 Mar 2007 03:23:54 +0000 (03:23 +0000)
committerBo Peng <bpeng@lyx.org>
Wed, 21 Mar 2007 03:23:54 +0000 (03:23 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17496 a592a061-630c-0410-9148-cb99ea01b6c8

development/scons/SConstruct
development/scons/scons_utils.py

index caec861c9e614d371374769deb2d6d88bd17d639..8c6e74a83abea2b028ec44d18c5d6e7a256307e7 100644 (file)
@@ -255,7 +255,7 @@ if (not ARGUMENTS.has_key('load_option') or \
         and opt_cache.has_key('qt_dir'):
         opt_cache.pop('qt_dir')
     # and we do not cache some options (dest_dir is obsolete)
-    for arg in ['load_option', 'dest_dir']:
+    for arg in ['load_option', 'dest_dir', 'bundle']:
         if opt_cache.has_key(arg):
             opt_cache.pop(arg)
     # remove obsolete cached keys (well, SConstruct is evolving. :-)
@@ -716,6 +716,8 @@ else:
 #
 # check for msgfmt command
 env['MSGFMT'] = conf.CheckCommand('msgfmt')
+env['MSGMERGE'] = conf.CheckCommand('msgmerge')
+env['XGETTEXT'] = conf.CheckCommand('xgettext')
 
 # if under windows, check the nsis compiler
 if platform_name == 'win32':
@@ -1511,6 +1513,7 @@ build_client = True in ['client' in x for x in targets] \
 build_tex2lyx = True in ['tex2lyx' in x for x in targets] \
     or build_install or 'all' in targets or build_installer
 build_lyxbase = build_lyx or 'lyxbase' in targets
+update_po = 'update_po' in targets
 build_po = 'po' in targets or build_install or 'all' in targets
 build_qt4 = (build_lyx and frontend == 'qt4') or 'qt4' in targets
 build_msvs_projects = use_vc and 'msvs_projects' in targets
@@ -1972,6 +1975,54 @@ if build_msvs_projects:
         full_target = File(env.subst('$BUILDDIR/lyx$PROGSUFFIX')).abspath)
 
 
+if update_po:
+    #
+    # update po files
+    #
+    print 'Updating po/*.po files...'
+
+    import glob
+    # files to translate
+    transfiles = glob.glob(os.path.join(env.subst('$TOP_SRCDIR'), 'po', '*.po'))
+    # possibly *only* handle these languages
+    languages = None
+    if env.has_key('languages'):
+        languages = env.make_list(env['lanauges'])
+    # whether or not update po files
+    if not env['XGETTEXT'] or not env['MSGMERGE']:
+        print 'xgettext or msgmerge does not exist. Can not merge po files'
+        Exit(1)
+    # create a builder that generate 
+    env['XGETTEXT_OPTIONS'] = '--language=C++ --join-existing --keyword=_ --keyword=N_ --keyword=qt_'
+    env['MSGMERGE_OPTIONS'] = '--update'
+    env['COPYRIGHT_HOLDER'] = 'LyX Developers'
+    env['MSGID_BUGS_ADDRESS'] = 'lyx-devel@lists.lyx.org'
+    env['BUILDERS']['xgettext'] = Builder(action='''$XGETTEXT --default-domain=lyx \
+        --output=$TARGET \
+        --directory=$TOP_SRCDIR \
+           --add-comments=TRANSLATORS: $XGETTEXT_OPTIONS \
+           --files-from=$TOP_SRCDIR/po/POTFILES.in \
+           --copyright-holder='$COPYRIGHT_HOLDER' \
+           --msgid-bugs-address='$MSGID_BUGS_ADDRESS' ''')
+    env['BUILDERS']['msgmerge'] = Builder(action='$MSGMERGE $MSGMERGE_OPTIONS $SOURCE $TARGET')
+    #   ==> lyx.pot
+    env.xgettext('$BUILDDIR/common/lyx.pot', '$TOP_SRCDIR/po/POTFILES.in')
+    # for each po file, generate pot
+    for f in transfiles:
+        # get filename
+        fname = os.path.split(f)[1]
+        # country code
+        country = fname.split('.')[0]
+        #
+        if not languages or country in languages:
+            # merge po files
+            env.msgmerge(f, '$BUILDDIR/common/lyx.pot')
+    # build language_l10n.pot
+    env['BUILDERS']['language_l10n'] = Builder(action=utils.env_language_l10n)
+    tar = env.language_l10n('$BUILDDIR/common/language_l10n.pot', '$TOP_SRCDIR/lib/languages')
+    Alias('update_po', tar)
+
+
 if build_po:
     #
     # po/
index 15a892ac951cffcf60ecdf98da6abc1d3ec26aba..e5c995eed96b9246c4f66e16b04d8e79bc07c248 100644 (file)
@@ -113,6 +113,39 @@ def env_toc(target, source, env):
     doc_toc.build_toc(str(target[0]), [file.abspath for file in source])
     
     
+def relativePath(env, path):
+    '''return relative path from top source dir'''
+    # full pathname of path
+    path1 = os.path.normpath(env.File(path).abspath).split(os.sep)
+    path2 = os.path.normpath(env.Dir('$TOP_SRCDIR').abspath).split(os.sep)
+    if path1[:len(path2)] != path2:
+        print "Path %s is not under top source directory" % path
+    return os.path.join(*path1[len(path2):])
+
+
+def env_language_l10n(target, source, env):
+    '''Generate pot file from lib/language'''
+    input = open(env.File(source[0]).abspath)
+    output = open(env.File(target[0]).abspath, 'w')
+    for lineno, line in enumerate(input.readlines()):
+        if line[0] == '#':
+            continue
+        items = line.split('"')
+        # empty lines?
+        if len(items) != 5:
+            print 'Warning: this line looks strange:'
+            print line
+        # From:
+        #   afrikaans   afrikaans      "Afrikaans"     false  iso8859-15 af_ZA  ""
+        # To:
+        #   #: lib/languages:2
+        #   msgid "Afrikaans"
+        #   msgstr ""
+        print >> output, '#: %s:%d\nmsgid "%s"\nmsgstr ""\n' % (relativePath(env, source[0]), lineno+1, items[1])
+    input.close()
+    output.close()
+
+
 def createResFromIcon(env, icon_file, rc_file):
     ''' create a rc file with icon, and return res file (windows only) '''
     if os.name == 'nt':