summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2022-07-15 11:45:51 +0200
committerOskar Nyberg <oskar@mullvad.net>2022-07-15 11:45:51 +0200
commit783a1c95bbb2d973df5e3b0b31e2258ae45853fc (patch)
treeccd5687432afcbbc0233553b13640566994ff184
parent9ba1ffe343ceed18674885dca1940ef403924433 (diff)
parentd20500a4cab06d7ae584799162423d9ff3f093c8 (diff)
downloadmullvadvpn-783a1c95bbb2d973df5e3b0b31e2258ae45853fc.tar.xz
mullvadvpn-783a1c95bbb2d973df5e3b0b31e2258ae45853fc.zip
Merge branch 'add-localization-helper-script'
-rw-r--r--android/README.md7
-rwxr-xr-xbuild.sh30
-rw-r--r--gui/locales/README.md55
-rwxr-xr-xscripts/localization105
-rw-r--r--scripts/utils/log32
5 files changed, 164 insertions, 65 deletions
diff --git a/android/README.md b/android/README.md
index 514ffd263c..c45092b4da 100644
--- a/android/README.md
+++ b/android/README.md
@@ -4,6 +4,12 @@ This directory contains the files specific to the Android app.
## Translations / Localization
+### How to update translations
+
+See [/gui/locales/README.md][gui-locales-readme] for how to easily update translations.
+
+### Detailed structure and script documentation
+
The app has localized messages stored in `src/main/res/values-<locale>/` directories, where
`<locale>` is a two letter locale and can be followed by a two letter region code. For example: `en`
or `en-rGB`.
@@ -25,5 +31,6 @@ did not find any translation, making it simpler to use the template for obtainin
translations.
[root-readme]: ../README.md
+[gui-locales-readme]: ../gui/locales/README.md
[gui-locales]: ../gui/locales/
[messages.pot]: ../gui/locales/messages.pot
diff --git a/build.sh b/build.sh
index 1de0b49e12..9f759ad4de 100755
--- a/build.sh
+++ b/build.sh
@@ -8,35 +8,7 @@ set -eu
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPT_DIR"
-function log {
- local NO_COLOR="0m"
- local msg=$1
- local color=${2:-"$NO_COLOR"}
- echo -e "\033[$color$msg\033[$NO_COLOR"
-}
-
-function log_header {
- local YELLOW="33m"
- echo ""
- log "### $1 ###" $YELLOW
- echo ""
-}
-
-function log_success {
- local GREEN="32m"
- log "$1" $GREEN
-}
-
-function log_error {
- local RED="31m"
- log "!! $1" $RED
-}
-
-function log_info {
- local BOLD="1m"
- log "$1" $BOLD
-}
-
+source scripts/utils/log
################################################################################
# Analyze environment and parse arguments
diff --git a/gui/locales/README.md b/gui/locales/README.md
index b696de4e5d..bd40ce78e0 100644
--- a/gui/locales/README.md
+++ b/gui/locales/README.md
@@ -40,56 +40,39 @@ This is a folder with gettext translations for Mullvad VPN app.
## Updating translations template
-### messages.pot
-
-Run `npm run update-translations` to extract the new translations from the source
-code.
-
-#### Android translations
-
-The Android app uses translation strings stored in a different format, but which can be generated
-from the translations in this directory. For more information, see [here](../../android/README.md).
-
-### relay-locations.pot
+Use the localization script to prepare the pot-files by running the following command from the
+root-directory:
+```
+./scripts/localization prepare
+```
-To update the countries and cities you have to run the geo data scripts. Follow the instructions
-in [`gui/scripts/README.md`](../scripts/README.md).
+It will update `messages.pot` with localization strings from both the desktop app and Android app,
+and will update `relay-localizations.pot`. The changes to each file will also be committed
+individually.
## Uploading translations template to Crowdin
After updating the translations template (POT) locally, make sure to upload it to Crowdin:
-
```
-CROWDIN_API_KEY=$YOUR_CROWDIN_KEY ./gui/scripts/crowdin.sh upload
+CROWDIN_API_KEY=$YOUR_CROWDIN_KEY `./scripts/localization upload`
```
Triggering Crowdin to start translating has to be done manually. Speak to the project owner
## Downloading translations from Crowdin
-Before downloading from Crowdin the project must be "built" first. When you
-later download you will receive the translations from the last point in time when it was built.
-
-In order to make a fresh build with translations, use the following command:
-
+When the translations are done, download it by running:
```
-CROWDIN_API_KEY=$YOUR_CROWDIN_KEY ./gui/scripts/crowdin.sh export
+CROWDIN_API_KEY=$YOUR_CROWDIN_KEY `./scripts/localization download`
```
-In order to download and integrate the new translations from Crowdin into the app, use the following
-command:
-
-```
-CROWDIN_API_KEY=$YOUR_CROWDIN_KEY ./gui/scripts/crowdin.sh download
-```
+## Keeping messages.pot in sync
-## Add new translations to the Android app
-
-Adding the new translations to the Android app after downloading them from Crowdin is similar to how
-the translations template is updated. First run:
-```
-npm run update-translations
-```
+This is only relevant when running the different tools for updating `messages.pot` manually, and
+is not relevant when using the localization script mentioned above.
-And then run the Android translations converter tool as described in the
-[Android readme](../../android/README.md).
+It's important that `messages.pot` reflect both the desktop app and the Android app. To prevent it
+from getting out of sync with the strings in the source code, always run both
+`npm run update-translations` and the `translations-converter` tool in that order. If the first one
+is run on it's own it will remove the strings specific to Android. The easiest way to accomplish
+this is to just run `./scripts/localization prepare` as described above.
diff --git a/scripts/localization b/scripts/localization
new file mode 100755
index 0000000000..a35445a011
--- /dev/null
+++ b/scripts/localization
@@ -0,0 +1,105 @@
+#!/usr/bin/env bash
+
+set -eu
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "$SCRIPT_DIR"
+
+source utils/log
+
+function main {
+ case ${1:-""} in
+ prepare) prepare_localization_strings;;
+ upload) upload_to_crowdin;;
+ download) download_from_crowdin;;
+ "")
+ echo "Available subcommands: prepare, upload and download"
+ ;;
+ *)
+ echo "Unknown parameter: $1"
+ exit 1
+ ;;
+ esac
+}
+
+function update_messages_pot {
+ # Update desktop strings in messages.pot
+ log_header "Extracting localization strings from desktop app source code"
+ pushd ../gui
+ npm run update-translations
+ popd
+
+ # Update android strings and add Android strings to messages.pot
+ log_header "Extracting localization strings from android app source code"
+ pushd ../android/translations-converter/
+ cargo run
+ popd
+}
+
+function update_relay_locations_pot {
+ log_header "Retrieving relay locations from server list and translating by using map data"
+ pushd ../gui/scripts
+ # Download geo data
+ curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_0_countries.zip
+ curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/50m/cultural/ne_50m_admin_1_states_provinces_lines.zip
+ curl -L -O https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip
+
+ unzip ne_50m_admin_0_countries.zip -d ne_50m_admin_0_countries/
+ unzip ne_50m_admin_1_states_provinces_lines.zip -d ne_50m_admin_1_states_provinces_lines/
+ unzip ne_10m_populated_places.zip -d ne_10m_populated_places/
+
+ # Add translations from geo data
+ python3 extract-geo-data.py
+ python3 integrate-into-app.py
+
+ # Remove geo data
+ rm ne_10m_populated_places.zip \
+ ne_50m_admin_0_countries.zip \
+ ne_50m_admin_1_states_provinces_lines.zip
+ rm -r ne_10m_populated_places ne_50m_admin_0_countries ne_50m_admin_1_states_provinces_lines
+
+ git restore ../assets
+
+ popd
+}
+
+function commit_changes {
+ if [[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]; then
+ git commit -a -S -m "$1"
+ fi
+}
+
+function prepare_localization_strings {
+ update_messages_pot
+ commit_changes "Update messages.pot"
+
+ update_relay_locations_pot
+ commit_changes "Update relay-locations.pot"
+}
+
+function ensure_crowdin_api_key {
+ test ! -z "$CROWDIN_API_KEY"
+}
+
+function upload_to_crowdin {
+ ensure_crowdin_api_key
+
+ log_header "Uploading translations to crowdin"
+ ../gui/scripts/crowdin.sh upload
+}
+
+function download_from_crowdin {
+ ensure_crowdin_api_key
+
+ log_header "Downloading translations from crowdin"
+ ../gui/scripts/crowdin.sh export
+ ../gui/scripts/crowdin.sh download
+
+ # Add new translations to Android xml-files
+ log_header "Updating Android xml-files with new translations"
+ update_messages_pot
+ commit_changes "Update translations"
+}
+
+main "$@"
+
diff --git a/scripts/utils/log b/scripts/utils/log
new file mode 100644
index 0000000000..101ed9c5a5
--- /dev/null
+++ b/scripts/utils/log
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+# This is a logging tool for bash scripts
+
+function log {
+ local NO_COLOR="0m"
+ local msg=$1
+ local color=${2:-"$NO_COLOR"}
+ echo -e "\033[$color$msg\033[$NO_COLOR"
+}
+
+function log_header {
+ local YELLOW="33m"
+ echo ""
+ log "### $1 ###" $YELLOW
+ echo ""
+}
+
+function log_success {
+ local GREEN="32m"
+ log "$1" $GREEN
+}
+
+function log_error {
+ local RED="31m"
+ log "!! $1" $RED
+}
+
+function log_info {
+ local BOLD="1m"
+ log "$1" $BOLD
+}