3
# GCompris - l10n-fetch-po-files.py
5
# Copyright (C) 2015 Trijita org <jktjkt@trojita.org>
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, see <https://www.gnu.org/licenses/>.
24
"""Fetch the .po files from KDE's SVN for GCompris
26
Run me from GCompris's top-level directory.
30
SVN_PATH = "svn://anonsvn.kde.org/home/kde/branches/stable/l10n-kf5/"
31
SOURCE_PO_PATH = "/messages/gcompris/gcompris_qt.po"
32
OUTPUT_PO_PATH = "./po/"
33
OUTPUT_PO_PATTERN = "gcompris_%s.po"
35
fixer = re.compile(r'^#~\| ', re.MULTILINE)
36
re_empty_msgid = re.compile('^msgid ""$', re.MULTILINE)
37
re_empty_line = re.compile('^$', re.MULTILINE)
38
re_has_qt_contexts = re.compile('X-Qt-Contexts: true\\n')
40
if not os.path.exists(OUTPUT_PO_PATH):
41
os.mkdir(OUTPUT_PO_PATH)
43
all_languages = subprocess.check_output(['svn', 'cat', SVN_PATH + 'subdirs'],
44
stderr=subprocess.STDOUT)
46
all_languages = [x.strip() for x in all_languages.decode().split("\n") if len(x)]
47
all_languages.remove("x-test")
48
for lang in all_languages:
50
raw_data = subprocess.check_output(['svn', 'cat', SVN_PATH + lang + SOURCE_PO_PATH],
51
stderr=subprocess.PIPE)
52
(transformed, subs) = fixer.subn('# ~| ', raw_data.decode())
53
pos1 = re_empty_msgid.search(transformed).start()
54
pos2 = re_empty_line.search(transformed).start()
55
if re_has_qt_contexts.search(transformed, pos1, pos2) is None:
56
transformed = transformed[:pos2] + \
57
'"X-Qt-Contexts: true\\n"\n' + \
61
print("Fetched %s (and performed %d cleanups)" % (lang, subs))
63
print("Fetched %s" % lang)
64
out_file = open(OUTPUT_PO_PATH + OUTPUT_PO_PATTERN % lang, "wb")
65
out_file.write(transformed.encode())
66
except subprocess.CalledProcessError:
67
print ("No data for %s" % lang)
69
# Inform qmake about the updated file list
70
#os.utime("CMakeLists.txt", None)