summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2019-03-08 15:45:49 +0100
committerAndrej Mihajlov <and@mullvad.net>2019-03-08 15:45:49 +0100
commit1245828c33bbb91dfcccc875a532ea046f4f74d1 (patch)
tree0d18caaf661625442f17da342e814ca2988be680 /gui
parentd61d3b989ace19a74fe01673aff9e586f9f08132 (diff)
parent3e1b33666d97cec40264b48d825b02229788e437 (diff)
downloadmullvadvpn-1245828c33bbb91dfcccc875a532ea046f4f74d1.tar.xz
mullvadvpn-1245828c33bbb91dfcccc875a532ea046f4f74d1.zip
Merge branch 'add-crowdin-script'
Diffstat (limited to 'gui')
-rw-r--r--gui/locales/README.md19
-rw-r--r--gui/locales/de/.gitkeep0
-rw-r--r--gui/locales/es/.gitkeep0
-rw-r--r--gui/locales/fr/.gitkeep0
-rw-r--r--gui/locales/it/.gitkeep0
-rw-r--r--gui/locales/ja/.gitkeep0
-rw-r--r--gui/locales/nl/.gitkeep0
-rw-r--r--gui/locales/no/.gitkeep0
-rw-r--r--gui/locales/pt/.gitkeep0
-rw-r--r--gui/locales/ru/.gitkeep0
-rw-r--r--gui/locales/sv/.gitkeep0
-rw-r--r--gui/locales/tr/.gitkeep0
-rw-r--r--gui/locales/zh/.gitkeep0
-rwxr-xr-xgui/scripts/crowdin.sh50
-rwxr-xr-xgui/scripts/update-translations.sh15
-rw-r--r--gui/src/shared/gettext.ts2
16 files changed, 74 insertions, 12 deletions
diff --git a/gui/locales/README.md b/gui/locales/README.md
index 06fec35119..8a8c9ae734 100644
--- a/gui/locales/README.md
+++ b/gui/locales/README.md
@@ -34,10 +34,27 @@ In order to initialize the translations catalogue for the new locale, simple fol
procedure, described in the section below.
-## Updating translations
+## Updating translations template
Run `yarn update-translations` to extract the new translations from the source
code and update all of the existing catalogues.
The new translations are automatically added to empty sub-folders using the POT template at
`gui/locales/messages.pot`. Folders that contain a `.gitkeep` file are ignored.
+
+## 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
+```
+
+## Downloading translations from Crowdin
+
+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
+```
diff --git a/gui/locales/de/.gitkeep b/gui/locales/de/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/de/.gitkeep
+++ /dev/null
diff --git a/gui/locales/es/.gitkeep b/gui/locales/es/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/es/.gitkeep
+++ /dev/null
diff --git a/gui/locales/fr/.gitkeep b/gui/locales/fr/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/fr/.gitkeep
+++ /dev/null
diff --git a/gui/locales/it/.gitkeep b/gui/locales/it/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/it/.gitkeep
+++ /dev/null
diff --git a/gui/locales/ja/.gitkeep b/gui/locales/ja/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/ja/.gitkeep
+++ /dev/null
diff --git a/gui/locales/nl/.gitkeep b/gui/locales/nl/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/nl/.gitkeep
+++ /dev/null
diff --git a/gui/locales/no/.gitkeep b/gui/locales/no/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/no/.gitkeep
+++ /dev/null
diff --git a/gui/locales/pt/.gitkeep b/gui/locales/pt/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/pt/.gitkeep
+++ /dev/null
diff --git a/gui/locales/ru/.gitkeep b/gui/locales/ru/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/ru/.gitkeep
+++ /dev/null
diff --git a/gui/locales/sv/.gitkeep b/gui/locales/sv/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/sv/.gitkeep
+++ /dev/null
diff --git a/gui/locales/tr/.gitkeep b/gui/locales/tr/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/tr/.gitkeep
+++ /dev/null
diff --git a/gui/locales/zh/.gitkeep b/gui/locales/zh/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/gui/locales/zh/.gitkeep
+++ /dev/null
diff --git a/gui/scripts/crowdin.sh b/gui/scripts/crowdin.sh
new file mode 100755
index 0000000000..914007ac87
--- /dev/null
+++ b/gui/scripts/crowdin.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+set -e
+
+BASE_URL=https://api.crowdin.com/api/project/mullvad-app
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+ROOT_DIR=$( dirname $SCRIPT_DIR )
+LOCALE_DIR="$ROOT_DIR/locales"
+
+if [ $# -ne 1 ]; then
+ echo "Usage: $0 [upload|export|download]"
+ exit 1
+elif [ -z "$CROWDIN_API_KEY" ]; then
+ echo "Need to set environment variable CROWDIN_API_KEY"
+ exit 1
+fi
+
+mode=$1
+
+function upload_pot {
+ curl \
+ -F "files[/messages.pot]=@$LOCALE_DIR/messages.pot" \
+ $BASE_URL/update-file?key="$CROWDIN_API_KEY"
+}
+
+function export_translations {
+ curl \
+ $BASE_URL/export?key="$CROWDIN_API_KEY"
+}
+
+function download_translations {
+ wget \
+ --content-disposition \
+ $BASE_URL/download/all.zip?key="$CROWDIN_API_KEY"
+ unzip -o all.zip -d $LOCALE_DIR
+ find $LOCALE_DIR -type d -exec chmod 755 {} \;
+ find $LOCALE_DIR -type f -exec chmod 644 {} \;
+ rm all.zip
+}
+
+if [[ $mode == "upload" ]]; then
+ upload_pot
+elif [[ $mode == "export" ]]; then
+ export_translations
+elif [[ $mode == "download" ]]; then
+ download_translations
+else
+ echo "'$mode' is not a valid mode"
+ echo "Usage: $0 [upload|export|download]"
+ exit 1
+fi
diff --git a/gui/scripts/update-translations.sh b/gui/scripts/update-translations.sh
index 030d0c78a8..db9d5e7b74 100755
--- a/gui/scripts/update-translations.sh
+++ b/gui/scripts/update-translations.sh
@@ -3,23 +3,18 @@
# This script creates or updates the existing gettext catalogues using the POT template located
# under locales/messages.pot
-ROOT_DIR=$(dirname $(dirname "${BASH_SOURCE[0]}"))
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+ROOT_DIR=$( dirname $SCRIPT_DIR )
POT_FILE="$ROOT_DIR/locales/messages.pot"
for PO_FILE_DIR in $ROOT_DIR/locales/* ; do
if [ -d $PO_FILE_DIR ] ; then
- PO_FILE="$PO_FILE_DIR/messages.po"
- GITKEEP_FILE="$PO_FILE_DIR/.gitkeep"
+ LOCALE=$( basename $PO_FILE_DIR )
+ PO_FILE="$PO_FILE_DIR/messages-$LOCALE.po"
if [ -f $PO_FILE ] ; then
- echo "Update $PO_FILE_DIR\c"
+ echo "Update $PO_FILE"
msgmerge --no-fuzzy-matching --update $PO_FILE $POT_FILE
- else
- if [ -f $GITKEEP_FILE ] ; then
- echo "Remove $GITKEEP_FILE to initialize the new translation"
- else
- msginit --input $POT_FILE --output $PO_FILE --no-translator
- fi
fi
fi
done
diff --git a/gui/src/shared/gettext.ts b/gui/src/shared/gettext.ts
index 4722e16915..a1e2a3cb0f 100644
--- a/gui/src/shared/gettext.ts
+++ b/gui/src/shared/gettext.ts
@@ -47,7 +47,7 @@ export function loadTranslations(currentLocale: string) {
}
function parseTranslation(locale: string, domain: string): boolean {
- const filename = path.join(LOCALES_DIR, locale, `${domain}.po`);
+ const filename = path.join(LOCALES_DIR, locale, `${domain}-${locale}.po`);
let buffer: Buffer;
try {