From 922b9d7d2a935a98f975312d7d3f3025097893d7 Mon Sep 17 00:00:00 2001 From: serso Date: Fri, 26 Feb 2016 22:52:33 +0100 Subject: [PATCH] More imported strings --- app/src/main/res/values-ar/text_imported.xml | 5 + app/src/main/res/values-cs/text_imported.xml | 5 + app/src/main/res/values-de/text_imported.xml | 5 + app/src/main/res/values-es/text_imported.xml | 5 + app/src/main/res/values-fi/text_imported.xml | 5 + app/src/main/res/values-fr/text_imported.xml | 5 + app/src/main/res/values-it/text_imported.xml | 5 + app/src/main/res/values-ja/text_imported.xml | 5 + app/src/main/res/values-nl/text_imported.xml | 5 + app/src/main/res/values-pl/text_imported.xml | 5 + .../main/res/values-pt-rBR/text_imported.xml | 5 + .../main/res/values-pt-rPT/text_imported.xml | 5 + app/src/main/res/values-ru/text_imported.xml | 5 + app/src/main/res/values-tr/text_imported.xml | 5 + app/src/main/res/values-vi/text_imported.xml | 5 + .../main/res/values-zh-rCN/text_imported.xml | 5 + .../main/res/values-zh-rTW/text_imported.xml | 5 + app/src/main/res/values/text_imported.xml | 5 + .../android/translations/Android.java | 112 ++++++++++++------ 19 files changed, 163 insertions(+), 39 deletions(-) diff --git a/app/src/main/res/values-ar/text_imported.xml b/app/src/main/res/values-ar/text_imported.xml index 81f1990e..ee4a2f67 100644 --- a/app/src/main/res/values-ar/text_imported.xml +++ b/app/src/main/res/values-ar/text_imported.xml @@ -13,4 +13,9 @@ إنشاء إغلاق تبديل + تعديل + حذف + تم + إلغاء + الوصف \ No newline at end of file diff --git a/app/src/main/res/values-cs/text_imported.xml b/app/src/main/res/values-cs/text_imported.xml index c31e13d3..24b40a8b 100644 --- a/app/src/main/res/values-cs/text_imported.xml +++ b/app/src/main/res/values-cs/text_imported.xml @@ -13,4 +13,9 @@ Vytvořit Zavřít Přepnout + Upravit + Smazat + Hotovo + Zrušit + Popis \ No newline at end of file diff --git a/app/src/main/res/values-de/text_imported.xml b/app/src/main/res/values-de/text_imported.xml index 33e220c2..32f83649 100644 --- a/app/src/main/res/values-de/text_imported.xml +++ b/app/src/main/res/values-de/text_imported.xml @@ -13,4 +13,9 @@ Erstellen Schließen Wechseln + Bearbeiten + Löschen + Fertig + Abbrechen + Beschreibung \ No newline at end of file diff --git a/app/src/main/res/values-es/text_imported.xml b/app/src/main/res/values-es/text_imported.xml index 9c581748..4375c4dc 100644 --- a/app/src/main/res/values-es/text_imported.xml +++ b/app/src/main/res/values-es/text_imported.xml @@ -13,4 +13,9 @@ Crear Cerrar Cambiar + Editar + Eliminar + Listo + Cancelar + Descripción \ No newline at end of file diff --git a/app/src/main/res/values-fi/text_imported.xml b/app/src/main/res/values-fi/text_imported.xml index a47e3a27..4fb6708a 100644 --- a/app/src/main/res/values-fi/text_imported.xml +++ b/app/src/main/res/values-fi/text_imported.xml @@ -13,4 +13,9 @@ Luo Sulje Vaihda + Muokkaa + Poista + Valmis + Peruuta + Kuvaus \ No newline at end of file diff --git a/app/src/main/res/values-fr/text_imported.xml b/app/src/main/res/values-fr/text_imported.xml index cbfbc9e2..dc8adbcc 100644 --- a/app/src/main/res/values-fr/text_imported.xml +++ b/app/src/main/res/values-fr/text_imported.xml @@ -13,4 +13,9 @@ Créer Fermer Changer + Modifier + Supprimer + OK + Annuler + Description \ No newline at end of file diff --git a/app/src/main/res/values-it/text_imported.xml b/app/src/main/res/values-it/text_imported.xml index 82899f8c..bb4c32d5 100644 --- a/app/src/main/res/values-it/text_imported.xml +++ b/app/src/main/res/values-it/text_imported.xml @@ -13,4 +13,9 @@ Crea Chiudi Cambia + Modifica + Elimina + Salva + Annulla + Descrizione \ No newline at end of file diff --git a/app/src/main/res/values-ja/text_imported.xml b/app/src/main/res/values-ja/text_imported.xml index 4397dc68..9936b8e6 100644 --- a/app/src/main/res/values-ja/text_imported.xml +++ b/app/src/main/res/values-ja/text_imported.xml @@ -13,4 +13,9 @@ 作成 閉じる 切り替え + 編集 + 削除 + 完了 + キャンセル + 説明 \ No newline at end of file diff --git a/app/src/main/res/values-nl/text_imported.xml b/app/src/main/res/values-nl/text_imported.xml index 461577e1..f206d8ff 100644 --- a/app/src/main/res/values-nl/text_imported.xml +++ b/app/src/main/res/values-nl/text_imported.xml @@ -13,4 +13,9 @@ Aanmaken Sluiten Overschakelen + Bewerken + Verwijderen + Gereed + Annuleren + Beschrijving \ No newline at end of file diff --git a/app/src/main/res/values-pl/text_imported.xml b/app/src/main/res/values-pl/text_imported.xml index 12d3807d..72af86d5 100644 --- a/app/src/main/res/values-pl/text_imported.xml +++ b/app/src/main/res/values-pl/text_imported.xml @@ -13,4 +13,9 @@ Utwórz Zamknij Przełącz + Edytuj + Usuń + Gotowe + Anuluj + Opis \ No newline at end of file diff --git a/app/src/main/res/values-pt-rBR/text_imported.xml b/app/src/main/res/values-pt-rBR/text_imported.xml index a8273ace..ef159d1d 100644 --- a/app/src/main/res/values-pt-rBR/text_imported.xml +++ b/app/src/main/res/values-pt-rBR/text_imported.xml @@ -13,4 +13,9 @@ Criar Fechar Alternar + Editar + Excluir + Concluído + Cancelar + Descrição \ No newline at end of file diff --git a/app/src/main/res/values-pt-rPT/text_imported.xml b/app/src/main/res/values-pt-rPT/text_imported.xml index 3e39ecb0..0b94e4cc 100644 --- a/app/src/main/res/values-pt-rPT/text_imported.xml +++ b/app/src/main/res/values-pt-rPT/text_imported.xml @@ -13,4 +13,9 @@ Criar Fechar Alternar + Editar + Eliminar + Concluído + Cancelar + Descrição \ No newline at end of file diff --git a/app/src/main/res/values-ru/text_imported.xml b/app/src/main/res/values-ru/text_imported.xml index b934a9f4..0a7f1db0 100644 --- a/app/src/main/res/values-ru/text_imported.xml +++ b/app/src/main/res/values-ru/text_imported.xml @@ -13,4 +13,9 @@ Создать Закрыть Сменить аккаунт + Изменить + Удалить + Готово + Отмена + Описание \ No newline at end of file diff --git a/app/src/main/res/values-tr/text_imported.xml b/app/src/main/res/values-tr/text_imported.xml index a31144e7..4a72cbb0 100644 --- a/app/src/main/res/values-tr/text_imported.xml +++ b/app/src/main/res/values-tr/text_imported.xml @@ -13,4 +13,9 @@ Oluştur Kapat Değiştir + Düzenle + Sil + Bitti + İptal + Açıklama \ No newline at end of file diff --git a/app/src/main/res/values-vi/text_imported.xml b/app/src/main/res/values-vi/text_imported.xml index 5d9462fa..a44eeb02 100644 --- a/app/src/main/res/values-vi/text_imported.xml +++ b/app/src/main/res/values-vi/text_imported.xml @@ -13,4 +13,9 @@ Tạo Đóng Chuyển đổi + Chỉnh sửa + Xóa + Xong + Hủy + Mô tả \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/text_imported.xml b/app/src/main/res/values-zh-rCN/text_imported.xml index a5f51507..0868c578 100644 --- a/app/src/main/res/values-zh-rCN/text_imported.xml +++ b/app/src/main/res/values-zh-rCN/text_imported.xml @@ -13,4 +13,9 @@ 创建 关闭 切换 + 编辑 + 删除 + 完成 + 取消 + 说明 \ No newline at end of file diff --git a/app/src/main/res/values-zh-rTW/text_imported.xml b/app/src/main/res/values-zh-rTW/text_imported.xml index 46b1df52..e834ed94 100644 --- a/app/src/main/res/values-zh-rTW/text_imported.xml +++ b/app/src/main/res/values-zh-rTW/text_imported.xml @@ -13,4 +13,9 @@ 建立 關閉 切換 + 編輯 + 刪除 + 完成 + 取消 + 說明 \ No newline at end of file diff --git a/app/src/main/res/values/text_imported.xml b/app/src/main/res/values/text_imported.xml index f41ffc01..b43d5fc0 100644 --- a/app/src/main/res/values/text_imported.xml +++ b/app/src/main/res/values/text_imported.xml @@ -13,4 +13,9 @@ Create Close Switch + Edit + Delete + Done + Cancel + Description \ No newline at end of file diff --git a/translations/src/main/java/org/solovyev/android/translations/Android.java b/translations/src/main/java/org/solovyev/android/translations/Android.java index 5fd1913e..6f2c2911 100644 --- a/translations/src/main/java/org/solovyev/android/translations/Android.java +++ b/translations/src/main/java/org/solovyev/android/translations/Android.java @@ -9,69 +9,93 @@ import java.util.List; public class Android { - private static class TranslationLink { - public final String inName; - public final String outName; + private static final List settingsLinks = new ArrayList<>(); + private static final List calendarLinks = new ArrayList<>(); - private TranslationLink(String inName, String outName) { - this.inName = inName; - this.outName = outName; - } + static { + settingsLinks.add(new TranslationLink("haptic_feedback_enable_title", "cpp_prefs_vibrate_on_keypress")); + settingsLinks.add(new TranslationLink("accelerometer_title", "cpp_prefs_auto_rotate_screen")); + settingsLinks.add(new TranslationLink("phone_language", "cpp_language")); + settingsLinks.add(new TranslationLink("night_mode_title", "cpp_theme")); + settingsLinks.add(new TranslationLink("night_mode_no", "cpp_theme_light")); + settingsLinks.add(new TranslationLink("night_mode_yes", "cpp_theme_dark")); + settingsLinks.add(new TranslationLink("keep_screen_on", "cpp_prefs_keep_screen_on")); + settingsLinks.add(new TranslationLink("draw_overlay", "cpp_permission_overlay")); + settingsLinks.add(new TranslationLink("yes", "cpp_yes")); + settingsLinks.add(new TranslationLink("no", "cpp_no")); + settingsLinks.add(new TranslationLink("create", "cpp_create")); + settingsLinks.add(new TranslationLink("dlg_close", "cpp_close")); + settingsLinks.add(new TranslationLink("dlg_switch", "cpp_switch")); + + calendarLinks.add(new TranslationLink("edit_label", "cpp_edit")); + calendarLinks.add(new TranslationLink("delete_label", "cpp_delete")); + calendarLinks.add(new TranslationLink("save_label", "cpp_save")); + calendarLinks.add(new TranslationLink("discard_label", "cpp_cancel")); + calendarLinks.add(new TranslationLink("hint_description", "cpp_description")); } public static void main(String... args) throws Exception { final Options options = new Options(); options.addOption(Option.builder("as").longOpt("aosp-settings").hasArg().desc("Local location of aosp/platform/packages/apps/settings").required().build()); + options.addOption(Option.builder("ac").longOpt("aosp-calendar").hasArg().desc("Local location of aosp/platform/packages/apps/calendar").required().build()); final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(options, args); - final File aospSettings = new File(commandLine.getOptionValue("as")); - if (!aospSettings.exists() || !aospSettings.isDirectory()) { - throw new IllegalArgumentException(aospSettings + " doesn't exist or not a directory"); - } - final File inDir = - new File(aospSettings, "res"); + final File aospSettings = makeInputDirectory(commandLine.getOptionValue("as")); + final File aospCalendar = makeInputDirectory(commandLine.getOptionValue("ac")); + final File outDir = new File("build/translations/res"); Utils.delete(outDir); outDir.mkdirs(); - final List translationLinks = new ArrayList<>(); - translationLinks.add(new TranslationLink("haptic_feedback_enable_title", "cpp_prefs_vibrate_on_keypress")); - translationLinks.add(new TranslationLink("accelerometer_title", "cpp_prefs_auto_rotate_screen")); - translationLinks.add(new TranslationLink("phone_language", "cpp_language")); - translationLinks.add(new TranslationLink("night_mode_title", "cpp_theme")); - translationLinks.add(new TranslationLink("night_mode_no", "cpp_theme_light")); - translationLinks.add(new TranslationLink("night_mode_yes", "cpp_theme_dark")); - translationLinks.add(new TranslationLink("keep_screen_on", "cpp_prefs_keep_screen_on")); - translationLinks.add(new TranslationLink("draw_overlay", "cpp_permission_overlay")); - translationLinks.add(new TranslationLink("yes", "cpp_yes")); - translationLinks.add(new TranslationLink("no", "cpp_no")); - translationLinks.add(new TranslationLink("create", "cpp_create")); - translationLinks.add(new TranslationLink("dlg_close", "cpp_close")); - translationLinks.add(new TranslationLink("dlg_switch", "cpp_switch")); - List languageLocales = new ArrayList<>(Utils.languageLocales); languageLocales.add(""); for (String languageLocale : languageLocales) { - final File inLanguageDir = new File(inDir, Utils.valuesFolderName(languageLocale)); - final File inFile = new File(inLanguageDir, "strings.xml"); - final Resources resources = Utils.persister.read(Resources.class, inFile); Resources translations = new Resources(); - for (TranslationLink translationLink : translationLinks) { - String translation = translate(resources, translationLink); - if(!TextUtils.isBlank(translation)) { - translations.strings.add(new ResourceString(translationLink.outName, translation)); - } - } + translate(readResources(aospSettings, languageLocale), translations, settingsLinks); + translate(readResources(aospCalendar, languageLocale), translations, calendarLinks); Utils.saveTranslations(translations, languageLocale, outDir, "text_imported.xml"); } } + private static Resources readResources(File from, String languageLocale) throws Exception { + File inFile = makeStringsFile(from, languageLocale); + if(!inFile.exists()) { + final int i = languageLocale.indexOf("-r"); + if(i >= 0) { + inFile = makeStringsFile(from, languageLocale.substring(0, i)); + } + } + return Utils.persister.read(Resources.class, inFile); + } + + private static File makeStringsFile(File from, String languageLocale) { + return new File(new File(from, Utils.valuesFolderName(languageLocale)), "strings.xml"); + } + + private static File makeInputDirectory(String dirName) { + final File dir = new File(dirName); + if (!dir.exists() || !dir.isDirectory()) { + throw new IllegalArgumentException(dir + " doesn't exist or not a directory"); + } + + return new File(dir, "res"); + } + + private static void translate(Resources from, Resources to, List links) { + for (TranslationLink translationLink : links) { + String translation = translate(from, translationLink); + if (!TextUtils.isBlank(translation)) { + to.strings.add(new ResourceString(translationLink.outName, translation)); + } + } + } + private static String translate(Resources resources, TranslationLink translationLink) { - for (ResourceString string: resources.strings) { + for (ResourceString string : resources.strings) { if (string.name.equals(translationLink.inName)) { - if(TextUtils.isBlank(string.value)) { + if (TextUtils.isBlank(string.value)) { return null; } if (string.value.length() >= 2 && string.value.startsWith("\"") && string.value @@ -83,4 +107,14 @@ public class Android { } return null; } + + private static class TranslationLink { + public final String inName; + public final String outName; + + private TranslationLink(String inName, String outName) { + this.inName = inName; + this.outName = outName; + } + } }