Merge pull request #299 from vector-im/feature/bma/translations
Translations - Localazy improvement
This commit is contained in:
commit
41fccb4056
41 changed files with 1068 additions and 42 deletions
|
|
@ -57,7 +57,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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -18,6 +20,14 @@ regexToAlwaysExclude = [
|
|||
".*_ios"
|
||||
]
|
||||
|
||||
baseAction = {
|
||||
"type": "android",
|
||||
# Replacement done in all string values
|
||||
"replacements": {
|
||||
"...": "…"
|
||||
}
|
||||
}
|
||||
|
||||
# Store all regex specific to module, to eclude the corresponding keyx from the common string module
|
||||
allRegexToExcludeFromMainModule = []
|
||||
# All actions that will be serialized in the localazy config
|
||||
|
|
@ -26,8 +36,7 @@ allActions = []
|
|||
# Iterating on the config
|
||||
for entry in config["modules"]:
|
||||
# Create action for the default language
|
||||
action = {
|
||||
"type": "android",
|
||||
action = baseAction | {
|
||||
"output": convertModuleToPath(entry["name"]) + "/src/main/res/values/localazy.xml",
|
||||
"includeKeys": list(map(lambda i: "REGEX:" + i, entry["includeRegex"])),
|
||||
"excludeKeys": list(map(lambda i: "REGEX:" + i, regexToAlwaysExclude)),
|
||||
|
|
@ -35,24 +44,23 @@ 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 = baseAction | {
|
||||
"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 = {
|
||||
"type": "android",
|
||||
mainAction = baseAction | {
|
||||
"output": "libraries/ui-strings/src/main/res/values/localazy.xml",
|
||||
"excludeKeys": list(map(lambda i: "REGEX:" + i, allRegexToExcludeFromMainModule + regexToAlwaysExclude)),
|
||||
"conditions": [
|
||||
|
|
@ -62,16 +70,16 @@ 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 = baseAction | {
|
||||
"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 = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue