From 7bf41d12e202033f7d01c88169f6376db16f185b Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Apr 2023 10:58:18 +0200 Subject: [PATCH] Add ability to download only English string (for developer). This is default behavior. --- tools/localazy/README.md | 8 +++- tools/localazy/downloadStrings.sh | 20 ++++++++-- tools/localazy/generateLocalazyConfig.py | 48 +++++++++++++----------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/tools/localazy/README.md b/tools/localazy/README.md index dcb45c5be7..968d92047d 100644 --- a/tools/localazy/README.md +++ b/tools/localazy/README.md @@ -20,7 +20,13 @@ In the root folder of the project, run: ./tools/localazy/downloadStrings.sh ``` -It will update all the `localazy.xml` and `translations.xml` resource files. In case of merge conflicts, just erase the files and download again using the script. +It will update all the `localazy.xml` resource files. In case of merge conflicts, just erase the files and download again using the script. + +To also include the translations, i.e. the `translations.xml` files, add `--all` argument: + +```shell +./tools/localazy/downloadStrings.sh --all +``` ## Add translations to a specific module diff --git a/tools/localazy/downloadStrings.sh b/tools/localazy/downloadStrings.sh index 163aab8e31..5892a87c38 100755 --- a/tools/localazy/downloadStrings.sh +++ b/tools/localazy/downloadStrings.sh @@ -18,12 +18,24 @@ set -e -echo "Generating the configuration file for localazy..." -./tools/localazy/generateLocalazyConfig.py +if [[ $1 == "--all" ]]; then + echo "Note: I will update all the files." + allFiles=1 +else + echo "Note: I will update only the English files." + allFiles=0 +fi -echo "Deleting all existing localazy.xml and translations.xml files..." +echo "Generating the configuration file for localazy..." +./tools/localazy/generateLocalazyConfig.py $allFiles + +echo "Deleting all existing localazy.xml files..." find . -name 'localazy.xml' -delete -find . -name 'translations.xml' -delete + +if [[ $allFiles == 1 ]]; then + echo "Deleting all existing translations.xml files..." + find . -name 'translations.xml' -delete +fi echo "Importing the strings..." localazy download --config ./tools/localazy/localazy.json diff --git a/tools/localazy/generateLocalazyConfig.py b/tools/localazy/generateLocalazyConfig.py index 829541462e..13b76e7d57 100755 --- a/tools/localazy/generateLocalazyConfig.py +++ b/tools/localazy/generateLocalazyConfig.py @@ -1,11 +1,13 @@ #!/usr/bin/env python3 import json +import sys # Read the config.json file with open('./tools/localazy/config.json', 'r') as f: config = json.load(f) +allFiles = sys.argv[1] == "1" # Convert a module name to a path # Ex: ":features:verifysession:impl" => "features/verifysession/impl" @@ -35,20 +37,21 @@ for entry in config["modules"]: "equals: ${languageCode}, en" ] } - # Create action for the translations - actionTranslation = { - "type": "android", - "output": convertModuleToPath(entry["name"]) + "/src/main/res/values-${langAndroidResNoScript}/translations.xml", - "includeKeys": list(map(lambda i: "REGEX:" + i, entry["includeRegex"])), - "excludeKeys": list(map(lambda i: "REGEX:" + i, regexToAlwaysExclude)), - "conditions": [ - "!equals: ${languageCode}, en" - ] - } # print(action) - allRegexToExcludeFromMainModule.extend(entry["includeRegex"]) allActions.append(action) - allActions.append(actionTranslation) + # Create action for the translations + if allFiles: + actionTranslation = { + "type": "android", + "output": convertModuleToPath(entry["name"]) + "/src/main/res/values-${langAndroidResNoScript}/translations.xml", + "includeKeys": list(map(lambda i: "REGEX:" + i, entry["includeRegex"])), + "excludeKeys": list(map(lambda i: "REGEX:" + i, regexToAlwaysExclude)), + "conditions": [ + "!equals: ${languageCode}, en" + ] + } + allActions.append(actionTranslation) + allRegexToExcludeFromMainModule.extend(entry["includeRegex"]) # Append configuration for the main string module: default language mainAction = { @@ -62,16 +65,17 @@ mainAction = { # print(mainAction) allActions.append(mainAction) -# Append configuration for the main string module: translations -mainActionTranslation = { - "type": "android", - "output": "libraries/ui-strings/src/main/res/values-${langAndroidResNoScript}/translations.xml", - "excludeKeys": list(map(lambda i: "REGEX:" + i, allRegexToExcludeFromMainModule + regexToAlwaysExclude)), - "conditions": [ - "!equals: ${languageCode}, en" - ] -} -allActions.append(mainActionTranslation) +if allFiles: + # Append configuration for the main string module: translations + mainActionTranslation = { + "type": "android", + "output": "libraries/ui-strings/src/main/res/values-${langAndroidResNoScript}/translations.xml", + "excludeKeys": list(map(lambda i: "REGEX:" + i, allRegexToExcludeFromMainModule + regexToAlwaysExclude)), + "conditions": [ + "!equals: ${languageCode}, en" + ] + } + allActions.append(mainActionTranslation) # Generate the configuration for localazy result = {