Update main_fr.ts #189
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 + $? )) |