1#!/usr/local/bin/python3.8
2"""
3 @file
4 @brief Display all available string translations for each translation file
5 @author Jonathan Thomas <jonathan@openshot.org>
6 @author Frank Dana <ferdnyc AT gmail com>
7
8 @section LICENSE
9
10 Copyright (c) 2008-2018 OpenShot Studios, LLC
11 (http://www.openshotstudios.com). This file is part of
12 OpenShot Video Editor (http://www.openshot.org), an open-source project
13 dedicated to delivering high quality video editing and animation solutions
14 to the world.
15
16 OpenShot Video Editor is free software: you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation, either version 3 of the License, or
19 (at your option) any later version.
20
21 OpenShot Video Editor is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with OpenShot Library.  If not, see <http://www.gnu.org/licenses/>.
28 """
29
30import os
31import re
32import fnmatch
33import sys
34from PyQt5.QtCore import QLocale, QLibraryInfo, QTranslator, QCoreApplication
35
36
37# Get the absolute path of this project
38language_path = os.path.dirname(os.path.abspath(__file__))
39
40# Get app instance
41app = QCoreApplication(sys.argv)
42
43# Load POT template (all English strings)
44all_templates = ['OpenShot.pot', 'OpenShot_transitions.pot', 'OpenShot_blender.pot']
45for template_name in all_templates:
46    POT_source = open(os.path.join(language_path, 'OpenShot', template_name)).read()
47    all_strings = re.findall('^msgid \"(.*)\"', POT_source, re.MULTILINE)
48
49    print("Scanning {} strings in all translation files...".format(len(all_strings)))
50
51    # Loop through folders/languages
52    for filename in fnmatch.filter(os.listdir(language_path), 'OpenShot*.qm'):
53        lang_code = filename[:-3]
54        # Install language
55        translator = QTranslator(app)
56
57        # Load translation
58        if translator.load(lang_code, language_path):
59            app.installTranslator(translator)
60
61            print("\n=================================================")
62            print("Showing translations for {}".format(filename))
63            print("=================================================")
64            # Loop through all test strings
65            for source_string in all_strings:
66                translated_string = app.translate("", source_string)
67                if source_string != translated_string:
68                    print('  {} => {}'.format(source_string,translated_string))
69
70                if "%s" in source_string or "%s(" in source_string or "%d" in source_string:
71                    if source_string.count('%') != translated_string.count('%'):
72                        raise(Exception('Invalid string replacement found: "%s" vs "%s" [%s]' %
73                              (translated_string, source_string, lang_code)))
74
75            # Remove translator
76            app.removeTranslator(translator)
77