~baltix/gcompris-qt/0.97.1

« back to all changes in this revision

Viewing changes to tools/l10n-fetch-po-files.py

  • Committer: Mantas Kriaučiūnas
  • Date: 2020-07-06 18:07:11 UTC
  • Revision ID: baltix@gmail.com-20200706180711-g254osu02cn8bc8p
GCompris-QT 0.97.1 with Lithuanian translation

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python3
 
2
#
 
3
# GCompris - l10n-fetch-po-files.py
 
4
#
 
5
# Copyright (C) 2015 Trijita org <jktjkt@trojita.org>
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
import os
 
20
import re
 
21
import subprocess
 
22
 
 
23
# Copied from Trojita
 
24
"""Fetch the .po files from KDE's SVN for GCompris
 
25
 
 
26
Run me from GCompris's top-level directory.
 
27
"""
 
28
 
 
29
 
 
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"
 
34
 
 
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')
 
39
 
 
40
if not os.path.exists(OUTPUT_PO_PATH):
 
41
    os.mkdir(OUTPUT_PO_PATH)
 
42
 
 
43
all_languages = subprocess.check_output(['svn', 'cat', SVN_PATH + 'subdirs'],
 
44
                                       stderr=subprocess.STDOUT)
 
45
 
 
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:
 
49
    try:
 
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' + \
 
58
                    transformed[pos2:]
 
59
            subs = subs + 1
 
60
        if (subs > 0):
 
61
            print("Fetched %s (and performed %d cleanups)" % (lang, subs))
 
62
        else:
 
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)
 
68
 
 
69
# Inform qmake about the updated file list
 
70
#os.utime("CMakeLists.txt", None)
 
71