Skip to content

Commit a38ff7e

Browse files
authored
Merge pull request #4353 from OpenShot/fix-translation-tests
Fix translation testing scripts to actually work!
2 parents 466d311 + 2358119 commit a38ff7e

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

src/language/show_translations.py

+33-25
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,36 @@
4141
app = QCoreApplication(sys.argv)
4242

4343
# Load POT template (all English strings)
44-
POT_source = open(os.path.join(language_path, 'OpenShot', 'OpenShot.pot')).read()
45-
all_strings = re.findall('^msgid \"(.*)\"', POT_source, re.MULTILINE)
46-
47-
print("Scanning {} strings in all translation files...".format(len(all_strings)))
48-
49-
# Loop through folders/languages
50-
for filename in fnmatch.filter(os.listdir(language_path), 'OpenShot_*.qm'):
51-
lang_code = filename[:-3]
52-
# Install language
53-
translator = QTranslator(app)
54-
55-
# Load translation
56-
if translator.load(lang_code, language_path):
57-
app.installTranslator(translator)
58-
59-
print("\n=================================================")
60-
print("Showing translations for {}".format(filename))
61-
print("=================================================")
62-
# Loop through all test strings
63-
for source_string in all_strings:
64-
translated_string = app.translate("", source_string)
65-
if source_string != translated_string:
66-
print(' {} => {}'.format(source_string,translated_string))
67-
# Remove translator
68-
app.removeTranslator(translator)
44+
all_templates = ['OpenShot.pot', 'OpenShot_transitions.pot', 'OpenShot_blender.pot']
45+
for 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)

src/language/test_translations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
app = QCoreApplication(sys.argv)
4545

4646
# Load POT template (all English strings)
47-
all_templates = ['OpenShot.pot', 'OpenShot_transitions.pot', 'OpenShot_blender.pot', 'OpenShot_transitions.pot']
47+
all_templates = ['OpenShot.pot', 'OpenShot_transitions.pot', 'OpenShot_blender.pot']
4848
for template_name in all_templates:
4949
POT_source = open(os.path.join(language_path, 'OpenShot', template_name)).read()
5050
all_strings = re.findall('^msgid \"(.*)\"', POT_source, re.MULTILINE)
5151

5252
print("Testing {} strings in {}...".format(len(all_strings), template_name))
5353

5454
# Loop through folders/languages
55-
for filename in fnmatch.filter(os.listdir(language_path), 'OpenShot.*.qm'):
55+
for filename in fnmatch.filter(os.listdir(language_path), 'OpenShot*.qm'):
5656
lang_code = filename[:-3]
5757
# Install language
5858
translator = QTranslator(app)

0 commit comments

Comments
 (0)