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