From 505bead1da6e521dfd3ede1a98c8542617e772d2 Mon Sep 17 00:00:00 2001 From: bb Date: Thu, 10 Feb 2022 16:18:49 +0000 Subject: [PATCH] Some minor improvements for the localization scripts Comments By: Stan Reviewed By Freagarach Differential Revision: D4397 This was SVN commit r26338. --- source/tools/i18n/checkTranslations.py | 11 +++------- source/tools/i18n/cleanTranslationFiles.py | 5 +---- source/tools/i18n/creditTranslators.py | 20 ++++++++++--------- source/tools/i18n/generateDebugTranslation.py | 4 ++-- source/tools/i18n/i18n_helper/__init__.py | 2 ++ source/tools/i18n/pullTranslations.py | 5 +---- source/tools/i18n/updateTemplates.py | 6 ++---- 7 files changed, 22 insertions(+), 31 deletions(-) diff --git a/source/tools/i18n/checkTranslations.py b/source/tools/i18n/checkTranslations.py index f8726565cb..107bb604d6 100644 --- a/source/tools/i18n/checkTranslations.py +++ b/source/tools/i18n/checkTranslations.py @@ -16,17 +16,12 @@ # You should have received a copy of the GNU General Public License # along with 0 A.D. If not, see . -import os -import re -import sys -import multiprocessing +import sys, os, re, multiprocessing -from i18n_helper import projectRootDirectory +from i18n_helper import l10nFolderName, projectRootDirectory from i18n_helper.catalog import Catalog from i18n_helper.globber import getCatalogs -l10nFolderName = "l10n" - VERBOSE = 0 @@ -110,7 +105,7 @@ def main(): foundPots = 0 for root, folders, filenames in os.walk(projectRootDirectory): for filename in filenames: - if len(filename) > 4 and filename[-4:] == ".pot" and os.path.basename(root) == "l10n": + if len(filename) > 4 and filename[-4:] == ".pot" and os.path.basename(root) == l10nFolderName: foundPots += 1 multiprocessing.Process( target=check_translations, diff --git a/source/tools/i18n/cleanTranslationFiles.py b/source/tools/i18n/cleanTranslationFiles.py index 0b31eb9f4a..5635276b79 100644 --- a/source/tools/i18n/cleanTranslationFiles.py +++ b/source/tools/i18n/cleanTranslationFiles.py @@ -28,12 +28,9 @@ strip the e-mails using this script. import sys, os, glob, re, fileinput -from i18n_helper import l10nToolsDirectory, projectRootDirectory +from i18n_helper import l10nFolderName, transifexClientFolder, projectRootDirectory def main(): - l10nFolderName = "l10n" - transifexClientFolder = ".tx" - # Prepare some regexes. commentMatch = re.compile('#.*') translatorMatch = re.compile("(# [^,<]*)(?: <.*>)?(?:, [0-9,-]{4,9})") diff --git a/source/tools/i18n/creditTranslators.py b/source/tools/i18n/creditTranslators.py index 9ec4d0543f..625666f1eb 100755 --- a/source/tools/i18n/creditTranslators.py +++ b/source/tools/i18n/creditTranslators.py @@ -31,6 +31,8 @@ once before updateTemplates.py. import json, os, glob, re +from i18n_helper import l10nFolderName, transifexClientFolder, projectRootDirectory + # We credit everyone that helps translating even if the translations don't # make it into the game. # Note: Needs to be edited manually when new languages are added on Transifex. @@ -110,14 +112,14 @@ langs = { 'zh': '中文, 汉语, 漢語 (Chinese)', 'zh_TW': '臺灣話 Chinese (Taiwan)'} -root = '../../../' +poLocations = [] +for root, folders, filenames in os.walk(projectRootDirectory): + for folder in folders: + if folder == l10nFolderName: + if os.path.exists(os.path.join(root, folder, transifexClientFolder)): + poLocations.append(os.path.join(root, folder)) -poLocations = [ - 'binaries/data/l10n/', - 'binaries/data/mods/public/l10n/', - 'binaries/data/mods/mod/l10n/'] - -creditsLocation = 'binaries/data/mods/public/gui/credits/texts/translators.json' +creditsLocation = os.path.join(projectRootDirectory, 'binaries', 'data', 'mods', 'public', 'gui', 'credits', 'texts', 'translators.json') # This dictionnary will hold creditors lists for each language, indexed by code langsLists = {} @@ -137,7 +139,7 @@ for lang in langs.keys(): langsLists[lang] = [] for location in poLocations: - files = glob.glob(root + location + lang + '.*.po') + files = glob.glob(os.path.join(location, lang + '.*.po')) for file in files: poFile = open(file.replace('\\', '/'), encoding='utf-8') reached = False @@ -165,6 +167,6 @@ for (langCode, langList) in sorted(langsLists.items()): newJSONData['Content'][-1]['List'].append({'name': name}) # Save the JSON data to the credits file -creditsFile = open(root + creditsLocation, 'w', encoding='utf-8') +creditsFile = open(creditsLocation, 'w', encoding='utf-8') json.dump(newJSONData, creditsFile, indent=4) creditsFile.close() diff --git a/source/tools/i18n/generateDebugTranslation.py b/source/tools/i18n/generateDebugTranslation.py index 83411f5803..bf31d73c86 100644 --- a/source/tools/i18n/generateDebugTranslation.py +++ b/source/tools/i18n/generateDebugTranslation.py @@ -21,7 +21,7 @@ import os import sys import multiprocessing -from i18n_helper import projectRootDirectory +from i18n_helper import l10nFolderName, projectRootDirectory from i18n_helper.catalog import Catalog from i18n_helper.globber import getCatalogs @@ -142,7 +142,7 @@ def main(): found_pot_files = 0 for root, _, filenames in os.walk(projectRootDirectory): for filename in filenames: - if len(filename) > 4 and filename[-4:] == ".pot" and os.path.basename(root) == "l10n": + if len(filename) > 4 and filename[-4:] == ".pot" and os.path.basename(root) == l10nFolderName: found_pot_files += 1 if args.debug: multiprocessing.Process( diff --git a/source/tools/i18n/i18n_helper/__init__.py b/source/tools/i18n/i18n_helper/__init__.py index 58650ee6ec..6280442d49 100644 --- a/source/tools/i18n/i18n_helper/__init__.py +++ b/source/tools/i18n/i18n_helper/__init__.py @@ -1,4 +1,6 @@ import os +l10nFolderName = "l10n" +transifexClientFolder = ".tx" l10nToolsDirectory = os.path.dirname(os.path.realpath(__file__)) projectRootDirectory = os.path.abspath(os.path.join(l10nToolsDirectory, os.pardir, os.pardir, os.pardir, os.pardir)) diff --git a/source/tools/i18n/pullTranslations.py b/source/tools/i18n/pullTranslations.py index b9b3106df4..4c6168efd9 100644 --- a/source/tools/i18n/pullTranslations.py +++ b/source/tools/i18n/pullTranslations.py @@ -20,12 +20,9 @@ import os, sys from txclib.project import Project -from i18n_helper import l10nToolsDirectory, projectRootDirectory +from i18n_helper import l10nFolderName, transifexClientFolder, projectRootDirectory def main(): - l10nFolderName = "l10n" - transifexClientFolder = ".tx" - for root, folders, filenames in os.walk(projectRootDirectory): for folder in folders: if folder == l10nFolderName: diff --git a/source/tools/i18n/updateTemplates.py b/source/tools/i18n/updateTemplates.py index 8d2d37571e..d3013321d2 100644 --- a/source/tools/i18n/updateTemplates.py +++ b/source/tools/i18n/updateTemplates.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2020 Wildfire Games. +# Copyright (C) 2021 Wildfire Games. # This file is part of 0 A.D. # # 0 A.D. is free software: you can redistribute it and/or modify @@ -22,11 +22,9 @@ from importlib import import_module from lxml import etree -from i18n_helper import l10nToolsDirectory, projectRootDirectory +from i18n_helper import l10nFolderName, projectRootDirectory from i18n_helper.catalog import Catalog from extractors import extractors - -l10nFolderName = "l10n" messagesFilename = "messages.json"