3
# ***** BEGIN GPL LICENSE BLOCK *****
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the License, or (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software Foundation,
17
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
# ***** END GPL LICENSE BLOCK *****
23
# Create or update mo’s under /trunk/locale/…
33
from . import (settings, utils)
36
GETTEXT_MSGFMT_EXECUTABLE = settings.GETTEXT_MSGFMT_EXECUTABLE
38
SOURCE_DIR = settings.SOURCE_DIR
39
TRUNK_MO_DIR = settings.TRUNK_MO_DIR
40
TRUNK_PO_DIR = settings.TRUNK_PO_DIR
42
DOMAIN = settings.DOMAIN
45
def process_po(po, lang, mo=None):
47
mo_dir = os.path.join(TRUNK_MO_DIR, lang, "LC_MESSAGES")
48
# Create dirs if not existing!
49
if not os.path.isdir(mo_dir):
50
os.makedirs(mo_dir, exist_ok=True)
53
cmd = (GETTEXT_MSGFMT_EXECUTABLE,
57
mo or os.path.join(mo_dir, ".".join((DOMAIN, "mo"))),
60
print("Running ", " ".join(cmd))
61
ret = subprocess.call(cmd)
68
parser = argparse.ArgumentParser(description="Create or update mo’s " \
69
"under {}.".format(TRUNK_MO_DIR))
70
parser.add_argument('langs', metavar='ISO_code', nargs='*',
71
help="Restrict processed languages to those.")
72
parser.add_argument('--po', help="Only process that po file (implies --mo).",
74
parser.add_argument('--mo', help="Mo file to generate (implies --po).",
76
args = parser.parse_args()
80
if args.po and args.mo:
81
if os.path.exists(args.po):
82
t = process_po(args.po, None, args.mo)
86
for lang in args.langs:
87
po = os.path.join(TRUNK_PO_DIR, ".".join((lang, "po")))
88
if os.path.exists(po):
89
t = process_po(po, lang)
93
for po in os.listdir(TRUNK_PO_DIR):
94
if po.endswith(".po") and not po.endswith("_raw.po"):
95
lang = os.path.basename(po)[:-3]
96
po = os.path.join(TRUNK_PO_DIR, po)
97
t = process_po(po, lang)
104
if __name__ == "__main__":
105
print("\n\n *** Running {} *** \n".format(__file__))