-
Notifications
You must be signed in to change notification settings - Fork 61
152 lines (146 loc) · 7.69 KB
/
translations.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Check the translations
on:
push:
paths:
- 'src/translations/*'
pull_request:
paths:
- 'src/translations/*'
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.x
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Check translation filenames
shell: python
run: |
import os
import sys
haveError = False
for fileName in os.listdir(os.path.join('src', 'translations')):
filePath = os.path.join('src', 'translations', fileName)
if not fileName.endswith('.ts'):
haveError = True
print(f'::error file={filePath},line=1,col=1::Invalid translation filename: ' +
f'Must end with the "ts" extension.')
if not any(fileName.startswith(prefix)
for prefix in ['main_', 'dynamic_', 'installer_']):
haveError = True
print(f'::error file={filePath},line=1,col=1::Invalid translation filename: ' +
f'Must start with "main_", "dynamic_" or "installer_".')
sys.exit(1 if haveError else 0)
- name: All translations are registered in CMakeLists.txt
shell: python
run: |
import os
import re
import sys
from glob import iglob
with open('CMakeLists.txt') as cMakeListsFile:
cMakeListsContent = cMakeListsFile.read()
def checkTranslations(cMakeVariable, translationFileNames):
match = re.search(
rf'set\(\s*{cMakeVariable}(?P<start>\s*)(?P<translation>(?:.+?\s+)+?)\s*\)',
cMakeListsContent)
if match is None:
print(f'::error file=CMakeLists.txt,line=1,col=1::' +
f'Unable to find {cMakeVariable} variable')
sys.exit(1)
mainTranslationFiles = [path.replace('/', os.path.sep)
for path in match.group('translation').split()]
line = cMakeListsContent[:match.start()].count('\n') \
+ 1 + match.group('start').count('\n')
TRANSLATION_LINE = re.compile(r'^(?P<start>\s*).*?(?P<end>\s*)$')
start = None
for i, translationLine in enumerate(match.group('translation').split('\n')):
match = TRANSLATION_LINE.match(translationLine)
if match:
lineStart = match.group('start')
lineEnd = match.group('end')
if start is None:
if i != 0 or lineStart != '':
start = lineStart
elif start != lineStart:
print(f'::warning file=CMakeLists.txt,line={line + i},col=1::' +
f'Invalid start indentation, expected {start!r}, got {lineStart!r}')
if len(lineEnd):
print(f'::warning file=CMakeLists.txt,line={line + i},col=1::' +
f'Trailing whitespaces')
errorFound = False
for translation in iglob(os.path.join('src', 'translations', translationFileNames)):
if translation not in mainTranslationFiles:
errorFound = True
print(f'::error file=CMakeLists.txt,line={line},col=1::' +
f'Translation file {translation} is not registered ' +
f'in the {cMakeVariable} list in CMakeList.txt')
return errorFound
haveError = checkTranslations('MAIN_TRANSLATION_FILES', 'main_*.ts')
haveError = checkTranslations('DYN_TRANSLATION_FILES', 'dynamic_*.ts') or haveError
sys.exit(1 if haveError else 0)
- name: Special checks for installer translations
shell: python
run: |
import os
import sys
from glob import iglob
from xml.etree import ElementTree
from subprocess import check_output
svnUrl = 'svn://svn.code.sf.net/p/nsis/code/NSIS/trunk/Contrib/Language files'
languageNameFiles = check_output(['svn', 'list', svnUrl]).decode('utf-8')[:-1].split('\n')
languageNames = set([os.path.splitext(file)[0] for file in languageNameFiles])
translations = {}
haveError = False
for installerTranslation in iglob(os.path.join('src', 'translations', 'installer_*.ts')):
language = os.path.splitext(os.path.basename(installerTranslation))[0][10:]
translations[language] = installerTranslation
baseTranslationFile = os.path.join('src', 'translations', 'installer_en.ts')
baseTranslation = ElementTree.parse(baseTranslationFile)
sourceKeys = [source.text for source in baseTranslation.findall('context/message/source')]
for language in translations:
languageNameId = 'Lang_' + language
languageNameElement = baseTranslation.find(
f'context/message/translation[.=\'{languageNameId}\']')
if languageNameElement is None:
haveError = True
print(f'::error file={baseTranslationFile},line=1,col=1::' +
f'Missing translation for language name "{languageNameId}"')
for translationFilePath in translations.values():
translation = ElementTree.parse(translationFilePath)
languageNameElement = translation.find(
'context/message/source[.=\'__LANGUAGE_NAME__\']/../translation')
if languageNameElement is None:
print(f'::error file={translationFilePath},line=1,col=1::' +
f'Missing required entry __LANGUAGE_NAME__')
haveError = True
elif languageNameElement.text not in languageNames:
languageName = languageNameElement.text
with open(translationFilePath) as translationFile:
for lineNumber, line in enumerate(translationFile):
if f'<translation>{languageName}</translation>' in line:
lineNumber += 1
break
else:
lineNumber = 1
languageNamesString = '", "'.join(sorted(languageNames))
print(f'::error file={translationFilePath},line={lineNumber},col=1::' +
f'Invalid __LANGUAGE_NAME__: "{languageName}" is not in the list of ' +
f'possible language names: ["{languageNamesString}"]')
haveError = True
for sourceKey in sourceKeys:
if next((source for source in translation.iterfind(f'context/message/source')
if source.text == sourceKey), None) is None:
print(f'::warning file={translationFilePath},line=1,col=1::' +
f'Missing translation for source "{sourceKey}"')
sys.exit(1 if haveError else 0)
- name: Lint the translations
run: |
set +e
echo "::add-matcher::.github/problem-matchers/translations.json"
.github/scripts/checkTranslation.py src/translations/dynamic_*.ts src/translations/main_*.ts -e src/translations/*_en.ts -i unfinished_translation
ret=$?
.github/scripts/checkTranslation.py src/translations/installer_*.ts -e src/translations/*_en.ts -p '(?P<match>\d+)' '(?P<match>\$\{.*?\})' '(?P<match>\$\\[rn])' '(?P<match>\$\d+)'
exit $(( $ret + $? ))