]> git.evergreen-ils.org Git - Evergreen.git/blob - build/i18n/convert2po.py
First step towards a saner translation framework for Evergreen.
[Evergreen.git] / build / i18n / convert2po.py
1 #!/usr/bin/env python
2 # -----------------------------------------------------------------------
3 # Copyright (C) 2007  Laurentian University
4 # Dan Scott <dscott@laurentian.ca>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # --------------------------------------------------------------------
16 #
17 # Generates a complete set of PO files from DTD and JavaScript property
18 # files for use in translation.
19 #
20 # DTD files are placed in a /dtd/ subdirectory and property files are
21 # placed in a /property/ subdirectory so that we can round-trip the
22 # files back into DTD and property file format once they have been
23 # translated.
24 #
25 # Prerequisite: Translate Toolkit from http://translate.sourceforge.net/
26
27 import glob
28 import os.path
29 from translate.convert import moz2po
30
31 def convert2po(dir, extension):
32     """
33     Run moz2po on property and entity files to generate PO files.
34
35     For each property or entity file:
36         moz2po.main(["-i", "(name).ext", "-o", "(name).po"])
37     """
38     files = os.path.abspath(dir)
39     for file in glob.glob(os.path.join(files , '*.' + extension)):
40         base = os.path.basename(file)
41         sep = base.find(".")
42         root = base[:sep]
43         target = os.path.join(os.path.abspath('.'), extension);
44         if os.access(target, os.F_OK) is False:
45             os.mkdir(target)
46         moz2po.main(["-i", file, "-o", os.path.join(target, root + ".po"), "--progress", "none"])
47
48 if __name__=='__main__':
49     convert2po('../../Open-ILS/web/opac/locale/en-US/', 'dtd')
50     convert2po('../../Open-ILS/xul/staff_client/chrome/locale/en-US/', 'properties')