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