Skip to content

Commit

Permalink
chore(cordova/apple/ios): expand import_messages action to generate…
Browse files Browse the repository at this point in the history
… iOS strings (#1683)

* Add `ios` as target for importing messages.

* Move message loading into a function to be shared across Android and iOS.

* Refactor `import_messages`  to reduce duplication.

* Update function types in JSDoc annotations.

* Fix typo.

* Change strings directory into a list of strings.

* Fix locales for Chinese Simplified and Traditional.

* Add the localization files to the iOS project.

* Use localized strings in the menu bar.

* Move localized strings into the Swift package, where they are used.

* Install latest `node-gyp` version.

`node-gyp` versions older than v8.0.0 don't work with Python 3.11.
  • Loading branch information
sbruens authored Sep 11, 2023
1 parent 0cae8d0 commit 1312fc3
Show file tree
Hide file tree
Showing 77 changed files with 1,884 additions and 220 deletions.
1,481 changes: 1,355 additions & 126 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"file-loader": "^6.2.0",
"html-webpack-plugin": "^5.1.0",
"husky": "^1.3.1",
"i18n-strings-files": "^2.0.0",
"intl-messageformat": "^9.12.0",
"istanbul": "^0.4.5",
"karma": "^6.3.16",
Expand All @@ -112,6 +113,7 @@
"karma-webpack": "^5.0.0",
"minimist": "^1.2.6",
"node-fetch": "^3.3.0",
"node-gyp": "^9.4.0",
"outline-i18n": "Jigsaw-Code/outline-i18n#v0.0.7",
"postcss": "^7.0.39",
"postcss-rtl": "^1.7.3",
Expand Down
24 changes: 0 additions & 24 deletions src/cordova/android/get_native_locale.mjs

This file was deleted.

84 changes: 84 additions & 0 deletions src/cordova/android/import_messages.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2023 The Outline Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import {readFile, writeFile} from 'fs/promises';
import path from 'path';
import XML from 'xmlbuilder2';

const STRINGS_DIR = ['src', 'cordova', 'plugin', 'android', 'resources', 'strings'];
const STRINGS_FILENAME = 'strings.xml';
const XML_STRING_ID_PROPERTY = '@name';
const XML_TEXT_CONTENT = '#';

function escapeXmlCharacters(str) {
return str
.replace(/"/g, '\\"')
.replace(/'/g, "\\'")
.replace(/</g, '\\<')
.replace(/>/g, '\\>;')
.replace(/&/g, '\\&');
}

function getNativeLocale(locale) {
switch (locale) {
case 'es-419':
return 'es';
case 'sr-Latn':
return 'b+sr+Latn';
default:
return locale.replace('-', '-r');
}
}

/**
* Retrieves a filepath for a given locale to read/write strings to.
* @param {string} locale A locale for which to get a strings filepath.
* @returns {string} The filepath.
*/
export function getStringsFilepath(locale) {
const localeSuffix = locale ? `-${getNativeLocale(locale)}` : '';
return path.join(...STRINGS_DIR, `values${localeSuffix}`, STRINGS_FILENAME);
}

/**
* Reads messages that require translations.
* @return {Map<string, string>} messages The messages to translate.
*/
export async function readMessages() {
const strings = await XML.create(await readFile(getStringsFilepath(), 'utf8')).end({format: 'object'}).resources
.string;
return strings.reduce((acc, string) => {
return acc.set(string[XML_STRING_ID_PROPERTY], string[XML_TEXT_CONTENT]);
}, new Map());
}

/**
* Writes output messages to a given path in the Android expected format.
* @param {string} path The path to write the messages to.
* @param {Map<string, string>} messages The messages to write.
*/
export async function writeMessages(path, messages) {
const output = Object.entries(messages).reduce((acc, [key, value]) => {
acc.push({
[XML_STRING_ID_PROPERTY]: key,
[XML_TEXT_CONTENT]: escapeXmlCharacters(value),
});
return acc;
}, []);

await writeFile(
path,
XML.create({encoding: 'UTF-8'}, {resources: {string: output}}).end({prettyPrint: true, wellFormed: true})
);
}
1 change: 1 addition & 0 deletions src/cordova/apple/OutlineAppleLib/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PackageDescription

let package = Package(
name: "OutlineAppleLib",
defaultLocalization: "en",
products: [
.library(
name: "OutlineAppleLib",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Gekoppel";
"disconnected_server_state" = "Ontkoppel";
"tray_open_window" = "Oop";
"quit" = "Verlaat";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "ተገናኝቷል";
"disconnected_server_state" = "ተቋርጧል";
"tray_open_window" = "ክፈት";
"quit" = "ጨርስ";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "متصل";
"disconnected_server_state" = "غير متصل";
"tray_open_window" = "فتح";
"quit" = "إنهاء";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Qoşuldu";
"disconnected_server_state" = "Bağlantı kəsildi";
"tray_open_window" = "Açın";
"quit" = "Çıxın";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Установена е връзка";
"disconnected_server_state" = "Връзката бе прекратена";
"tray_open_window" = "Отваряне";
"quit" = "Излизане";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "কানেক্ট করা আছে";
"disconnected_server_state" = "ডিসকানেক্ট হয়ে গেছে";
"tray_open_window" = "খুলুন";
"quit" = "বেরিয়ে আসুন";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Povezano";
"disconnected_server_state" = "Veza je prekinuta";
"tray_open_window" = "Otvori";
"quit" = "Napusti";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Connectat";
"disconnected_server_state" = "Desconnectat";
"tray_open_window" = "Obre";
"quit" = "Surt";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Připojeno";
"disconnected_server_state" = "Odpojeno";
"tray_open_window" = "Otevřít";
"quit" = "Zavřít";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Tilsluttet";
"disconnected_server_state" = "Forbindelsen er afbrudt";
"tray_open_window" = "Åbn";
"quit" = "Luk";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Verbunden";
"disconnected_server_state" = "Nicht verbunden";
"tray_open_window" = "Öffnen";
"quit" = "Beenden";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Συνδεδεμένος";
"disconnected_server_state" = "Αποσυνδεδεμένος";
"tray_open_window" = "Άνοιγμα";
"quit" = "Έξοδος";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Connected";
"disconnected_server_state" = "Disconnected";
"tray_open_window" = "Open";
"quit" = "Exit";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Connected";
"disconnected_server_state" = "Disconnected";
"tray_open_window" = "Open";
"quit" = "Quit";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Conectado";
"disconnected_server_state" = "Desconectado";
"tray_open_window" = "Abrir";
"quit" = "Salir";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Conectado";
"disconnected_server_state" = "Desconectado";
"tray_open_window" = "Abrir";
"quit" = "Cerrar";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Ühendatud";
"disconnected_server_state" = "Ühendus on katkestatud";
"tray_open_window" = "Ava";
"quit" = "Välju";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "وصل شدید";
"disconnected_server_state" = "اتصال قطع شد";
"tray_open_window" = "باز کردن";
"quit" = "خروج";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Yhdistetty";
"disconnected_server_state" = "Yhteys katkaistu";
"tray_open_window" = "Avaa";
"quit" = "Sulje";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Nakakonekta na";
"disconnected_server_state" = "Nadiskonekta";
"tray_open_window" = "Buksan";
"quit" = "Umalis";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Connecté";
"disconnected_server_state" = "Déconnecté";
"tray_open_window" = "Ouvrir";
"quit" = "Quitter";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "מחובר";
"disconnected_server_state" = "מנותק";
"tray_open_window" = "פתיחה";
"quit" = "יציאה";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "कनेक्ट किया गया";
"disconnected_server_state" = "डिसकनेक्ट किया गया";
"tray_open_window" = "खोलें";
"quit" = "छोड़ें";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Povezano";
"disconnected_server_state" = "Veza je prekinuta";
"tray_open_window" = "Otvori";
"quit" = "Zatvori";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Csatlakoztatva";
"disconnected_server_state" = "Leválasztva";
"tray_open_window" = "Megnyitás";
"quit" = "Kilépés";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Միացված է";
"disconnected_server_state" = "Անջատված է";
"tray_open_window" = "Բացել";
"quit" = "Փակել";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Terhubung";
"disconnected_server_state" = "Sambungan terputus";
"tray_open_window" = "Buka";
"quit" = "Tutup";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Tengt";
"disconnected_server_state" = "Aftengt";
"tray_open_window" = "Opna";
"quit" = "Hætta";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Connesso";
"disconnected_server_state" = "Server disconnesso";
"tray_open_window" = "Apri";
"quit" = "Esci";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "接続しました";
"disconnected_server_state" = "接続が切断されました";
"tray_open_window" = "開く";
"quit" = "終了";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "დაკავშირებულია";
"disconnected_server_state" = "კავშირი გაწყვეტილია";
"tray_open_window" = "ღიაა";
"quit" = "გასვლა";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Байланыс орнатылды.";
"disconnected_server_state" = "Ажыратылған";
"tray_open_window" = "Ашу";
"quit" = "Шығу";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "បានភ្ជាប់";
"disconnected_server_state" = "បានផ្ដាច់";
"tray_open_window" = "បើក";
"quit" = "ចាកចេញ";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "연결됨";
"disconnected_server_state" = "연결 해제됨";
"tray_open_window" = "열기";
"quit" = "종료";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "ເຊື່ອມຕໍ່ແລ້ວ";
"disconnected_server_state" = "ຕັດການເຊື່ອມຕໍ່ແລ້ວ";
"tray_open_window" = "ເປີດ";
"quit" = "ປິດ";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Prisijungta";
"disconnected_server_state" = "Atsijungta";
"tray_open_window" = "Atidaryti";
"quit" = "Išeiti";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Savienojums izveidots";
"disconnected_server_state" = "Savienojums pārtraukts";
"tray_open_window" = "Atvērt";
"quit" = "Aizvērt";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Поврзано";
"disconnected_server_state" = "Не е поврзано";
"tray_open_window" = "Отвори";
"quit" = "Излези";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Холбогдсон";
"disconnected_server_state" = "Салсан";
"tray_open_window" = "Нээх";
"quit" = "Гарах";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "कनेक्ट केले आहे";
"disconnected_server_state" = "डिस्कनेक्ट केले";
"tray_open_window" = "उघडा";
"quit" = "बाहेर पडा";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Disambungkan";
"disconnected_server_state" = "Diputuskan sambungan";
"tray_open_window" = "Buka";
"quit" = "Keluar";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "ချိတ်ဆက်ထားသည်";
"disconnected_server_state" = "ချိတ်ဆက်မထားပါ";
"tray_open_window" = "ဖွင့်ရန်";
"quit" = "ထွက်ရန်";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "कनेक्ट गरिएको छ";
"disconnected_server_state" = "डिस्कनेक्ट गरिएको छ";
"tray_open_window" = "खोल्नुहोस्";
"quit" = "बाहिरिनुहोस्";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Verbonden";
"disconnected_server_state" = "Verbinding verbroken";
"tray_open_window" = "Openen";
"quit" = "Sluiten";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Tilkoblet";
"disconnected_server_state" = "Koblet fra";
"tray_open_window" = "Åpne";
"quit" = "Avslutt";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Połączono";
"disconnected_server_state" = "Odłączono";
"tray_open_window" = "Otwórz";
"quit" = "Zamknij";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Conectado";
"disconnected_server_state" = "Desconectado";
"tray_open_window" = "Abrir";
"quit" = "Sair";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Ligado";
"disconnected_server_state" = "Desligado";
"tray_open_window" = "Abrir";
"quit" = "Sair";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Conectat";
"disconnected_server_state" = "Deconectat";
"tray_open_window" = "Deschideți";
"quit" = "Ieșiți";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Подключен";
"disconnected_server_state" = "Отключен";
"tray_open_window" = "Открыть";
"quit" = "Выйти";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "සම්බන්‍ධයි";
"disconnected_server_state" = "විසන්‍ධි විය";
"tray_open_window" = "විවෘතයි";
"quit" = "ඉවත් වන්න";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Pripojené";
"disconnected_server_state" = "Odpojené";
"tray_open_window" = "Otvoriť";
"quit" = "Ukončiť";
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"connected_server_state" = "Povezava je vzpostavljena";
"disconnected_server_state" = "Povezava je prekinjena";
"tray_open_window" = "Odpri";
"quit" = "Zapri";
Loading

0 comments on commit 1312fc3

Please sign in to comment.