1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#!/usr/bin/env python3
# Lazygal, a static web gallery generator.
# Copyright (C) 2007-2010 Mickael Royer <mickael.royer@gmail.com>
# Alexandre Rossi <alexandre.rossi@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import glob,os
from distutils.dep_util import newer
from distutils.spawn import spawn
def update_translation(po_dir, po_package, po):
# Update runtime translations
os.chdir(po_dir)
spawn(["intltool-update", "--dist", "--gettext-package", po_package,
os.path.basename(po[:-3])])
def update_template(po_dir, po_package):
os.chdir(po_dir)
# We force here the python language for gettext strings extraction because
# xgettext (which is called by intltool-update) reverts to C for
# templates, as they do not have a .py extension, and this does not work
# and translatable strings are not extracted.
os.environ['XGETTEXT_ARGS'] = "-L Python"
spawn(["intltool-update", "--pot", "--gettext-package", po_package])
def update_po():
po_package = "lazygal"
po_dir = os.path.abspath("locale")
pot_file = os.path.join(po_dir, po_package + ".pot")
po_files = glob.glob(os.path.join(po_dir, "*.po"))
infilename = os.path.join(po_dir, "POTFILES.in")
with open(infilename, 'r') as f:
infiles = f.read().splitlines()
oldpath = os.getcwd()
need_tpl_update = False
if newer(infilename, pot_file):
need_tpl_update = True
else:
for filename in infiles:
if newer(filename, pot_file):
need_tpl_update = True
if need_tpl_update:
update_template(po_dir, po_package)
for po in po_files:
update_translation(po_dir, po_package, po)
os.chdir(oldpath)
if __name__ == "__main__":
update_po()
# vim: ts=4 sw=4 expandtab
|