Migrate to Lokalise for managing translations (#555)

This commit is contained in:
Adam Mills 2017-11-03 23:34:47 -04:00 committed by Paulus Schoutsen
parent 551cbe5afa
commit fdf2fa3d3f
31 changed files with 136 additions and 307 deletions

3
.gitignore vendored
View File

@ -19,3 +19,6 @@ venv
lib lib
bin bin
dist dist
# Secrets
.lokalise_token

View File

@ -63,6 +63,13 @@ gulp.task(taskName, function () {
.pipe(merge({ .pipe(merge({
fileName: tr + '.json', fileName: tr + '.json',
})) }))
.pipe(transform(function(data, file) {
// For now, language strings are only used for the native names list. We're deleting
// them from the rolled up translation files for now until we have a more robust
// system for splitting translation strings into multiple resource files.
delete data['language'];
return data;
}))
.pipe(transform(function(data, file) { .pipe(transform(function(data, file) {
// Polymer.AppLocalizeBehavior requires flattened json // Polymer.AppLocalizeBehavior requires flattened json
return flatten(data); return flatten(data);
@ -102,6 +109,20 @@ gulp.task(taskName, ['build-translation-fingerprints', 'build-translation-native
'build-temp/translationNativeNames.json', 'build-temp/translationNativeNames.json',
]) ])
.pipe(merge({})) .pipe(merge({}))
.pipe(transform(function(data, file) {
return Object.keys(data)
.filter(key => {
if (!data[key]['nativeName']) {
console.warn(`Skipping language ${key}. Native name was not translated.`);
return false;
}
return true;
})
.reduce((obj, key) => {
obj[key] = data[key];
return obj;
}, {});
}))
.pipe(insert.wrap('<script>\nwindow.translationMetadata = ', ';\n</script>')) .pipe(insert.wrap('<script>\nwindow.translationMetadata = ', ';\n</script>'))
.pipe(rename('translationMetadata.html')) .pipe(rename('translationMetadata.html'))
.pipe(gulp.dest('build-temp')); .pipe(gulp.dest('build-temp'));

View File

@ -11,6 +11,10 @@ OUTPUT_DIR=hass_frontend
rm -rf $OUTPUT_DIR rm -rf $OUTPUT_DIR
cp -r public $OUTPUT_DIR cp -r public $OUTPUT_DIR
# Download latest translations
echo "Downloading translations from Lokalise"
script/translations_download
# Build frontend # Build frontend
BUILD_DEV=0 ./node_modules/.bin/gulp BUILD_DEV=0 ./node_modules/.bin/gulp

37
script/translations_download Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Safe bash settings
# -e Exit on command fail
# -u Exit on unset variable
# -o pipefail Exit if piped command has error code
set -eu -o pipefail
cd "$(dirname "$0")/.."
if [ ! -f .lokalise_token ] ; then
echo "Lokalise API token is required to download the latest set of" \
"translations. Please create an account by using the following link:" \
"https://lokalise.co/signup/3420425759f6d6d241f598.13594006/all/"
exit 1
fi
API_TOKEN="$(<.lokalise_token)"
PROJECT_ID="3420425759f6d6d241f598.13594006"
LOCAL_DIR="$(pwd)/translations"
DOWNLOAD_FILE="${LOCAL_DIR}/Home_Assistant_-_Polymer_frontend-locale.zip"
FILE_FORMAT=json
rm -rf ${LOCAL_DIR}
mkdir -p ${LOCAL_DIR}
docker run \
-v ${LOCAL_DIR}:/opt/dest \
lokalise/lokalise-cli lokalise \
--token ${API_TOKEN} \
export ${PROJECT_ID} \
--type json \
--dest /opt/dest
# Extract and delete downloaded zip bundle
unzip -j "${DOWNLOAD_FILE}" locale/* -d "${LOCAL_DIR}"
rm -f "${DOWNLOAD_FILE}"

29
script/translations_upload_base Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Safe bash settings
# -e Exit on command fail
# -u Exit on unset variable
# -o pipefail Exit if piped command has error code
set -eu -o pipefail
cd "$(dirname "$0")/.."
if [ ! -f .lokalise_token ] ; then
echo "Lokalise API token is required to download the latest set of" \
"translations. Please create an account by using the following link:" \
"https://lokalise.co/signup/3420425759f6d6d241f598.13594006/all/"
exit 1
fi
API_TOKEN="$(<.lokalise_token)"
PROJECT_ID="3420425759f6d6d241f598.13594006"
LOCAL_FILE="$(pwd)/src/translations/en.json"
LANG_ISO=en
docker run \
-v ${LOCAL_FILE}:/opt/src/${LOCAL_FILE} \
lokalise/lokalise-cli lokalise \
--token ${API_TOKEN} \
import ${PROJECT_ID} \
--file /opt/src/${LOCAL_FILE} \
--lang_iso ${LANG_ISO}

38
src/translations/en.json Normal file
View File

@ -0,0 +1,38 @@
{
"language": {
"bg": "Bulgarian",
"cs": "Czech",
"da": "Danish",
"de": "German",
"el": "Greek",
"en": "English",
"fa": "Persian",
"fi": "Finnish",
"fr": "French",
"hu": "Hungarian",
"it": "Italian",
"ja": "Japanese",
"lt": "Lithuanian",
"nl": "Dutch",
"no": "Norwegian",
"pl": "Polish",
"pt": "Portuguese",
"ru": "Russian",
"sv": "Swedish",
"th": "Thai",
"tr": "Turkish",
"vi": "Vietnamese",
"zh-Hans": "Chinese Simplified",
"zh-Hant": "Chinese Traditional"
},
"panel": {
"config": "Configuration",
"states": "Overview",
"map": "Map",
"logbook": "Logbook",
"history": "History",
"log_out": "Log Out",
"mailbox": "Mailbox",
"shopping_list": "Shopping List"
}
}

4
translations/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore

View File

@ -1,12 +0,0 @@
{
"language": {
"bg": "Български"
},
"panel": {
"states": "Състояние",
"map": "Карта",
"logbook": "Дневник",
"history": "История",
"log_out": "Излез"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"cs": "Čeština"
},
"panel": {
"config": "Nastavení",
"states": "Stavy",
"map": "Mapa",
"logbook": "Deník",
"history": "Historie",
"log_out": "Odhlásit se"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"da": "Dansk"
},
"panel": {
"states": "Oversigt",
"map": "Kort",
"logbook": "Logbog",
"history": "Historik",
"log_out": "Log af",
"config": "Indstillinger"
}
}

View File

@ -1,15 +0,0 @@
{
"language": {
"de": "Deutsch"
},
"panel": {
"config": "Konfiguration",
"states": "Übersicht",
"map": "Karte",
"logbook": "Logbuch",
"history": "Verlauf",
"log_out": "Abmelden",
"mailbox": "Posteingang",
"shopping_list": "Einkaufsliste"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"el": "Ελληνικά"
},
"panel": {
"config": "Ρυθμίσεις",
"states": "Επισκόπηση",
"map": "Χάρτης",
"logbook": "Αρχείο Συμβάντων",
"history": "Ιστορικό",
"log_out": "Αποσύνδεση"
}
}

View File

@ -1,15 +0,0 @@
{
"language": {
"en": "English"
},
"panel": {
"config": "Configuration",
"states": "Overview",
"map": "Map",
"logbook": "Logbook",
"history": "History",
"log_out": "Log Out",
"mailbox": "Mailbox",
"shopping_list": "Shopping List"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"fa": "فارسی"
},
"panel": {
"states": "وضعیت",
"map": "نقشه",
"logbook": "گزارش روزانه",
"history": "تاریخچه",
"log_out": "خروج"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"fi": "Suomi"
},
"panel": {
"config": "Asetukset",
"states": "Yleisnäkymä",
"map": "Kartta",
"logbook": "Lokikirja",
"history": "Historia",
"log_out": "Kirjaudu ulos"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"fr": "Français"
},
"panel": {
"config": "Configuration",
"states": "États",
"map": "Carte",
"logbook": "Journal",
"history": "Historique",
"log_out": "Déconnexion"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"hu": "Magyar"
},
"panel": {
"config": "Konfiguráció",
"states": "Áttekintés",
"map": "Térkép",
"logbook": "Napló",
"history": "Előzmények",
"log_out": "Kilépés"
}
}

View File

@ -1,10 +0,0 @@
{
"language": {
"it": "Italiano"
},
"panel": {
"states": "Stati",
"map": "Mappa",
"history": "Storico"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"jp": "日本語"
},
"panel": {
"states": "状態",
"map": "地図",
"logbook": "ログブック",
"history": "履歴",
"log_out": "ログアウト"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"lt": "Lietuvių"
},
"panel": {
"states": "Valdymas",
"map": "Žemėlapis",
"logbook": "Veiksmų žurnalas",
"history": "Istorija",
"log_out": "Atsijungti"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"nl": "Nederlands"
},
"panel": {
"config": "Instellingen",
"states": "Overzicht",
"map": "Kaart",
"logbook": "Logboek",
"history": "Geschiedenis",
"log_out": "Uitloggen"
}
}

View File

@ -1,15 +0,0 @@
{
"language": {
"no": "Norsk"
},
"panel": {
"config": "Innstillinger",
"states": "Oversikt",
"map": "Kart",
"logbook": "Loggbok",
"history": "Historie",
"log_out": "Logg av",
"mailbox": "Postboks",
"shopping_list": "Handleliste"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"pl": "Polski"
},
"panel": {
"states": "Stany",
"map": "Mapa",
"logbook": "Dziennik",
"history": "Historia",
"log_out": "Wyloguj"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"pt": "Português"
},
"panel": {
"states": "Estados",
"map": "Mapa",
"logbook": "Eventos",
"history": "Histórico",
"log_out": "Desconectar"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"ru": "Русский"
},
"panel": {
"config": "Настройки",
"states": "Обзор",
"map": "Карта",
"logbook": "Журнал",
"history": "История",
"log_out": "Выход"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"sv": "Svenska"
},
"panel": {
"states": "Översikt",
"map": "Karta",
"logbook": "Loggbok",
"history": "Historik",
"log_out": "Logga Ut"
}
}

View File

@ -1,12 +0,0 @@
{
"language": {
"th": "ภาษาไทย"
},
"panel": {
"states": "ภาพรวม",
"map": "แผนที่",
"logbook": "สมุดบันทึก",
"history": "ประวัติ",
"log_out": "ลงชื่อออก"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"tr": "Türkçe"
},
"panel": {
"config": "Ayarlar",
"states": "Durum",
"map": "Harita",
"logbook": "Kayıt Defteri",
"history": "Geçmiş",
"log_out": ıkış Yap"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"vi": "Tiếng Việt"
},
"panel": {
"config": "Cấu hình",
"states": "Tổng quan",
"map": "Bản đồ",
"logbook": "Nhật ký",
"history": "Lịch sử",
"log_out": "Đăng xuất"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"zh-Hans": "简体中文"
},
"panel": {
"config": "配置",
"states": "概览",
"map": "地图",
"logbook": "日志",
"history": "历史",
"log_out": "退出"
}
}

View File

@ -1,13 +0,0 @@
{
"language": {
"zh-Hant": "繁體中文"
},
"panel": {
"config": "設定",
"states": "概覽",
"map": "地圖",
"logbook": "日誌",
"history": "歷史",
"log_out": "登出"
}
}