M SConstruct => SConstruct +3 -17
@@ 1,6 1,6 @@
# -*- Python -*-
-import os
+import tools.Gettext
def CheckPkgConfig(context, min_version='0'):
context.Message('Checking for pkgconfig... ')
@@ 15,7 15,7 @@ def PkgConfig(context, pkg, version, version_op='>='):
context.Result(True)
return True
-env = Environment()
+env = Environment(BUILDERS={'MO': tools.Gettext.GettextMOBuilder})
opts = Options('elfelli.conf')
opts.Add(BoolOption('debug', 'Set to build debug version', 1))
@@ 54,20 54,6 @@ paths = {
"datadir": env['prefix']+'/share/elfelli',
"localedir": env['prefix']+'/share/locale'}
-if 'install' in targets:
- try:
- for path in paths.values():
- if not os.path.lexists(path):
- os.makedirs(path, 0755)
- elif not (os.path.isdir(path) and os.access(path, os.W_OK or os.X_OK)):
- print 'Error: \'%s\' is not writable!' % path
- Exit(1)
- except OSError,e:
- print 'Error %d: %s' % (e[0],e[1])
- Exit(1)
- os.system('./i18n.py install %s' % paths['localedir'])
-
-
env.AppendUnique(CPPFLAGS=r'-DDATADIR=\"%s\" '%paths['datadir'])
env.AppendUnique(CPPFLAGS=r'-DLOCALEDIR=\"%s\" '%paths['localedir'])
env.Alias("install", paths.values())
@@ 80,4 66,4 @@ scons -h Show this help.
Options:""" + opts.GenerateHelpText(env))
Export('env paths targets')
-SConscript(['src/SConscript', 'data/SConscript'])
+SConscript(['src/SConscript', 'data/SConscript', 'po/SConscript'])
M i18n.py => i18n.py +8 -29
@@ 1,27 1,20 @@
#!/usr/bin/env python
-import os, sys
-from glob import glob
-
-usage = """This is the i18n helper script for Elfelli
+"""This is the i18n helper script for Elfelli
Usage:
-./i18n.py [update] Update po files, generate mo files.
-./i18n.py install /path/locale Install mo files in this path.
+./i18n.py update Update po and pot files.
./i18n.py init <locale> ... Initialise translations.
"""
+import os, sys
+from glob import glob
+
def find_locales():
po_files = glob('po/*.po')
locales = [file[3:-3] for file in po_files]
return locales
-def make_mo(locale):
- print 'Generating binary %s message catalog...' % locale
- if not os.path.isdir('po/locale/%s/LC_MESSAGES' % locale):
- os.makedirs('po/locale/%s/LC_MESSAGES' % locale, 0755)
- os.system('msgfmt -o po/locale/%s/LC_MESSAGES/elfelli.mo po/%s.po' % (locale,locale))
-
def update_pot():
print 'Updating po/elfelli.pot...'
os.system('xgettext -o po/elfelli.pot -kN_ -k_ --c++ src/*.cpp src/*.h')
@@ 31,32 24,18 @@ def update_po_files(locales):
for lang in locales:
os.system('msgmerge --update po/%s.po po/elfelli.pot' % lang)
-def compile_po_files(locales):
- for locale in locales:
- make_mo(locale)
-
-def install_mo_files(locales, dest):
- for locale in locales:
- o = ''
- if os.geteuid() == 0:
- o = '-oroot -groot '
- os.system('install -v -m644 %s -D po/locale/%s/LC_MESSAGES/elfelli.mo %s/%s/LC_MESSAGES/elfelli.mo' % (o, locale, dest, locale))
-
def init_translation(locale):
print 'Initialising %s locale...' % locale
os.system('msginit -i po/elfelli.pot -o po/%s.po' % locale)
if __name__ == '__main__':
locales = find_locales()
- if len(sys.argv) == 1 or sys.argv[1] == 'update':
+ if (len(sys.argv) >= 2) and (sys.argv[1] == 'update'):
update_pot()
update_po_files(locales)
compile_po_files(locales)
- elif (sys.argv[1] == 'install') and (len(sys.argv) == 3):
- install_mo_files(locales, sys.argv[2]);
-
- elif (sys.argv[1] == 'init') and (len(sys.argv) >= 3):
+ elif (len(sys.argv) >= 3) and (sys.argv[1] == 'init'):
update_pot()
for locale in sys.argv[2:]:
if not (locale in locales):
@@ 66,4 45,4 @@ if __name__ == '__main__':
locales = find_locales()
else:
- print usage
+ print __doc__
A po/SConscript => po/SConscript +14 -0
@@ 0,0 1,14 @@
+# -*- Python -*-
+
+from glob import glob
+
+Import('env paths targets')
+
+locales = map(lambda str: str[:-3], glob('*.po'))
+for locale in locales:
+ env.MO('locale/%s/LC_MESSAGES/elfelli' % locale, locale)
+
+if 'install' in targets:
+ for locale in locales:
+ env.InstallAs('%s/%s/LC_MESSAGES/elfelli.mo' % (paths['localedir'], locale),
+ 'locale/%s/LC_MESSAGES/elfelli.mo' % locale)
M po/elfelli.pot => po/elfelli.pot +1 -1
@@ 8,7 8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2006-12-01 19:08+0100\n"
+"POT-Creation-Date: 2006-12-10 11:08+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
A tools/Gettext.py => tools/Gettext.py +6 -0
@@ 0,0 1,6 @@
+import SCons.Builder
+
+Builder = SCons.Builder.Builder
+
+GettextMOBuilder = Builder(action='msgfmt -o $TARGET $SOURCE',
+ suffix='.mo', src_suffix='.po')
A tools/__init__.py => tools/__init__.py +0 -0