File indexing completed on 2023-05-30 10:41:17
0001 #!/usr/bin/python3 0002 # 0003 # GCompris - l10n-fetch-po-files.py 0004 # 0005 # SPDX-FileCopyrightText: 2015 Trijita org <jktjkt@trojita.org> 0006 # 0007 # SPDX-License-Identifier: GPL-3.0-or-later 0008 import os 0009 import re 0010 import subprocess 0011 0012 # Copied from Trojita 0013 """Fetch the .po files from KDE's SVN for GCompris 0014 0015 Run me from GCompris's top-level directory. 0016 """ 0017 0018 0019 SVN_PATH = "svn://anonsvn.kde.org/home/kde/branches/stable/l10n-kf5/" 0020 SOURCE_PO_PATH = "/messages/gcompris/gcompris_qt.po" 0021 OUTPUT_PO_PATH = "./po/%s/" 0022 OUTPUT_PO_FILE = "gcompris_qt.po" 0023 0024 fixer = re.compile(r'^#~\| ', re.MULTILINE) 0025 re_empty_msgid = re.compile('^msgid ""$', re.MULTILINE) 0026 re_empty_line = re.compile('^$', re.MULTILINE) 0027 re_has_qt_contexts = re.compile('X-Qt-Contexts: true\\n') 0028 0029 all_languages = subprocess.check_output(['svn', 'cat', SVN_PATH + 'subdirs'], 0030 stderr=subprocess.STDOUT) 0031 0032 all_languages = [x.strip() for x in all_languages.decode().split("\n") if len(x)] 0033 all_languages.remove("x-test") 0034 for lang in all_languages: 0035 try: 0036 raw_data = subprocess.check_output(['svn', 'cat', SVN_PATH + lang + SOURCE_PO_PATH], 0037 stderr=subprocess.PIPE) 0038 (transformed, subs) = fixer.subn('# ~| ', raw_data.decode()) 0039 pos1 = re_empty_msgid.search(transformed).start() 0040 pos2 = re_empty_line.search(transformed).start() 0041 if re_has_qt_contexts.search(transformed, pos1, pos2) is None: 0042 transformed = transformed[:pos2] + \ 0043 '"X-Qt-Contexts: true\\n"\n' + \ 0044 transformed[pos2:] 0045 subs = subs + 1 0046 if (subs > 0): 0047 print("Fetched %s (and performed %d cleanups)" % (lang, subs)) 0048 else: 0049 print("Fetched %s" % lang) 0050 0051 output_path = OUTPUT_PO_PATH % lang; 0052 if not os.path.exists(output_path): 0053 os.makedirs(output_path) 0054 0055 out_file = open(output_path + OUTPUT_PO_FILE, "wb") 0056 out_file.write(transformed.encode()) 0057 except subprocess.CalledProcessError: 0058 print ("No data for %s" % lang) 0059 0060 # Inform qmake about the updated file list 0061 #os.utime("CMakeLists.txt", None) 0062