From 7e41f30e06aad1f7598ddbd485607dbaed65e58e Mon Sep 17 00:00:00 2001 From: serso Date: Tue, 16 Feb 2016 15:33:10 +0100 Subject: [PATCH] Copy translations from AOSP --- app/src/main/res/values-ar/text_imported.xml | 8 ++ app/src/main/res/values-cs/text_imported.xml | 8 ++ app/src/main/res/values-de/text_imported.xml | 8 ++ app/src/main/res/values-es/text_imported.xml | 8 ++ app/src/main/res/values-fi/text_imported.xml | 8 ++ app/src/main/res/values-fr/text_imported.xml | 8 ++ app/src/main/res/values-it/text_imported.xml | 8 ++ app/src/main/res/values-ja/text_imported.xml | 8 ++ app/src/main/res/values-nl/text_imported.xml | 8 ++ app/src/main/res/values-pl/text_imported.xml | 8 ++ .../main/res/values-pt-rBR/text_imported.xml | 8 ++ .../main/res/values-pt-rPT/text_imported.xml | 8 ++ app/src/main/res/values-ru/text_imported.xml | 8 ++ app/src/main/res/values-tr/text_imported.xml | 8 ++ app/src/main/res/values-vi/text_imported.xml | 8 ++ .../main/res/values-zh-rCN/text_imported.xml | 8 ++ .../main/res/values-zh-rTW/text_imported.xml | 8 ++ app/src/main/res/values/text_imported.xml | 8 ++ app/src/main/res/values/text_preferences.xml | 1 - .../main/res/xml/preferences_appearance.xml | 11 +- settings.gradle | 2 +- {wiki => translations}/.gitignore | 0 {wiki => translations}/build.gradle | 0 .../android/translations/Android.java | 67 ++++++++++ .../android/translations/ResourceString.java | 22 ++++ .../android/translations/Resources.java | 16 +++ .../solovyev/android/translations/Utils.java | 90 +++++++++++++ .../solovyev/android/translations/Wiki.java | 118 ++---------------- 28 files changed, 355 insertions(+), 116 deletions(-) create mode 100644 app/src/main/res/values-ar/text_imported.xml create mode 100644 app/src/main/res/values-cs/text_imported.xml create mode 100644 app/src/main/res/values-de/text_imported.xml create mode 100644 app/src/main/res/values-es/text_imported.xml create mode 100644 app/src/main/res/values-fi/text_imported.xml create mode 100644 app/src/main/res/values-fr/text_imported.xml create mode 100644 app/src/main/res/values-it/text_imported.xml create mode 100644 app/src/main/res/values-ja/text_imported.xml create mode 100644 app/src/main/res/values-nl/text_imported.xml create mode 100644 app/src/main/res/values-pl/text_imported.xml create mode 100644 app/src/main/res/values-pt-rBR/text_imported.xml create mode 100644 app/src/main/res/values-pt-rPT/text_imported.xml create mode 100644 app/src/main/res/values-ru/text_imported.xml create mode 100644 app/src/main/res/values-tr/text_imported.xml create mode 100644 app/src/main/res/values-vi/text_imported.xml create mode 100644 app/src/main/res/values-zh-rCN/text_imported.xml create mode 100644 app/src/main/res/values-zh-rTW/text_imported.xml create mode 100644 app/src/main/res/values/text_imported.xml rename {wiki => translations}/.gitignore (100%) rename {wiki => translations}/build.gradle (100%) create mode 100644 translations/src/main/java/org/solovyev/android/translations/Android.java create mode 100644 translations/src/main/java/org/solovyev/android/translations/ResourceString.java create mode 100644 translations/src/main/java/org/solovyev/android/translations/Resources.java create mode 100644 translations/src/main/java/org/solovyev/android/translations/Utils.java rename wiki/src/main/java/org/solovyev/wiki/Main.java => translations/src/main/java/org/solovyev/android/translations/Wiki.java (54%) diff --git a/app/src/main/res/values-ar/text_imported.xml b/app/src/main/res/values-ar/text_imported.xml new file mode 100644 index 00000000..7c39c5a9 --- /dev/null +++ b/app/src/main/res/values-ar/text_imported.xml @@ -0,0 +1,8 @@ + + + الاهتزاز عند اللمس + التدوير التلقائي للشاشة + اللغة + المظهر + البقاء في الوضع النشط + \ 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 new file mode 100644 index 00000000..9ba6263e --- /dev/null +++ b/app/src/main/res/values-cs/text_imported.xml @@ -0,0 +1,8 @@ + + + Při dotyku vibrovat + Autom. otočení obrazovky + Jazyk + Motiv + Nevypínat obrazovku + \ 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 new file mode 100644 index 00000000..cb9da5e0 --- /dev/null +++ b/app/src/main/res/values-de/text_imported.xml @@ -0,0 +1,8 @@ + + + Bei Berührung vibrieren + Display automatisch drehen + Sprache + Design + Aktiv lassen + \ 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 new file mode 100644 index 00000000..bb74c841 --- /dev/null +++ b/app/src/main/res/values-es/text_imported.xml @@ -0,0 +1,8 @@ + + + Vibrar al tocar + Girar pantalla automáticamente + Idioma + Tema + Pantalla activa + \ 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 new file mode 100644 index 00000000..a0f3ebb6 --- /dev/null +++ b/app/src/main/res/values-fi/text_imported.xml @@ -0,0 +1,8 @@ + + + Käytä värinää kosketettaessa + Näytön automaattinen kierto + Kieli + Teema + Pysy käynnissä + \ 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 new file mode 100644 index 00000000..c92983df --- /dev/null +++ b/app/src/main/res/values-fr/text_imported.xml @@ -0,0 +1,8 @@ + + + Vibrer au toucher + Rotation auto de l\'écran + Langue + Thème + Rester activé + \ 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 new file mode 100644 index 00000000..bde8abf4 --- /dev/null +++ b/app/src/main/res/values-it/text_imported.xml @@ -0,0 +1,8 @@ + + + Vibra alla pressione + Rotazione automatica + Lingua + Tema + Rimani attivo + \ 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 new file mode 100644 index 00000000..d07d1181 --- /dev/null +++ b/app/src/main/res/values-ja/text_imported.xml @@ -0,0 +1,8 @@ + + + タッチ操作バイブ + 画面の自動回転 + 言語 + テーマ + スリープモードにしない + \ 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 new file mode 100644 index 00000000..1460c85d --- /dev/null +++ b/app/src/main/res/values-nl/text_imported.xml @@ -0,0 +1,8 @@ + + + Trillen bij aanraking + Scherm autom. draaien + Taal + Thema + Stand-by + \ 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 new file mode 100644 index 00000000..420bafba --- /dev/null +++ b/app/src/main/res/values-pl/text_imported.xml @@ -0,0 +1,8 @@ + + + Wibracje przy dotknięciu + Autoobracanie ekranu + Język + Motyw + Pozostaw ekran włączony + \ 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 new file mode 100644 index 00000000..937b472d --- /dev/null +++ b/app/src/main/res/values-pt-rBR/text_imported.xml @@ -0,0 +1,8 @@ + + + Vibrar ao tocar + Girar tela + Idioma + Tema + Permanecer ativo + \ 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 new file mode 100644 index 00000000..e47cd050 --- /dev/null +++ b/app/src/main/res/values-pt-rPT/text_imported.xml @@ -0,0 +1,8 @@ + + + Vibrar ao tocar + Rodar ecrã automaticamente + Idioma + Tema + Manter ativo + \ 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 new file mode 100644 index 00000000..cd5f0f62 --- /dev/null +++ b/app/src/main/res/values-ru/text_imported.xml @@ -0,0 +1,8 @@ + + + Виброотклик + Автоповорот экрана + Язык + Тема + Не выключать экран + \ 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 new file mode 100644 index 00000000..9f10898e --- /dev/null +++ b/app/src/main/res/values-tr/text_imported.xml @@ -0,0 +1,8 @@ + + + Dokunulduğunda titreşim + Ekranı otomatik döndür + Dil + Tema + Uyanık kal + \ 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 new file mode 100644 index 00000000..4fdec80a --- /dev/null +++ b/app/src/main/res/values-vi/text_imported.xml @@ -0,0 +1,8 @@ + + + Rung khi chạm + Tự động xoay màn hình + Ngôn ngữ + Chủ đề + Không khóa màn hình + \ 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 new file mode 100644 index 00000000..b57c8a63 --- /dev/null +++ b/app/src/main/res/values-zh-rCN/text_imported.xml @@ -0,0 +1,8 @@ + + + 触摸时振动 + 自动旋转屏幕 + 语言 + 主题背景 + 不锁定屏幕 + \ 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 new file mode 100644 index 00000000..5b52d938 --- /dev/null +++ b/app/src/main/res/values-zh-rTW/text_imported.xml @@ -0,0 +1,8 @@ + + + 觸控時震動 + 自動旋轉螢幕 + 語言 + 主題 + 螢幕不休眠 + \ 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 new file mode 100644 index 00000000..1aad04eb --- /dev/null +++ b/app/src/main/res/values/text_imported.xml @@ -0,0 +1,8 @@ + + + Vibrate on touch + Auto-rotate screen + Language + Theme + Stay awake + \ No newline at end of file diff --git a/app/src/main/res/values/text_preferences.xml b/app/src/main/res/values/text_preferences.xml index 6dd91173..1a31fa36 100644 --- a/app/src/main/res/values/text_preferences.xml +++ b/app/src/main/res/values/text_preferences.xml @@ -18,5 +18,4 @@ If turned on screen will not fade while using the app Language - Vibrate on keypress diff --git a/app/src/main/res/xml/preferences_appearance.xml b/app/src/main/res/xml/preferences_appearance.xml index 82592cb0..2a05646c 100644 --- a/app/src/main/res/xml/preferences_appearance.xml +++ b/app/src/main/res/xml/preferences_appearance.xml @@ -27,7 +27,7 @@ + a:title="@string/cpp_prefs_theme" /> + a:title="@string/cpp_prefs_auto_rotate_screen" /> + a:title="@string/cpp_prefs_keep_screen_on" /> \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 0bbe5e7d..8e7e28da 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':jscl', ':wiki' +include ':app', ':jscl', ':translations' diff --git a/wiki/.gitignore b/translations/.gitignore similarity index 100% rename from wiki/.gitignore rename to translations/.gitignore diff --git a/wiki/build.gradle b/translations/build.gradle similarity index 100% rename from wiki/build.gradle rename to translations/build.gradle diff --git a/translations/src/main/java/org/solovyev/android/translations/Android.java b/translations/src/main/java/org/solovyev/android/translations/Android.java new file mode 100644 index 00000000..de3b1118 --- /dev/null +++ b/translations/src/main/java/org/solovyev/android/translations/Android.java @@ -0,0 +1,67 @@ +package org.solovyev.android.translations; + +import org.apache.http.util.TextUtils; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class Android { + + private static class TranslationLink { + public final String inName; + public final String outName; + + private TranslationLink(String inName, String outName) { + this.inName = inName; + this.outName = outName; + } + } + + public static void main(String... args) throws Exception { + final File inDir = + new File("/home/serso/projects/java/aosp/platform/packages-apps-settings/res"); + 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_prefs_language")); + translationLinks.add(new TranslationLink("night_mode_title", "cpp_prefs_theme")); + translationLinks.add(new TranslationLink("keep_screen_on", "cpp_prefs_keep_screen_on")); + + 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)); + } + } + Utils.saveTranslations(translations, languageLocale, outDir, "text_imported.xml"); + } + } + + private static String translate(Resources resources, TranslationLink translationLink) { + for (ResourceString string: resources.strings) { + if (string.name.equals(translationLink.inName)) { + if(TextUtils.isBlank(string.value)) { + return null; + } + if (string.value.length() >= 2 && string.value.startsWith("\"") && string.value + .endsWith("\"")) { + return string.value.substring(1, string.value.length() - 1); + } + return string.value; + } + } + return null; + } +} diff --git a/translations/src/main/java/org/solovyev/android/translations/ResourceString.java b/translations/src/main/java/org/solovyev/android/translations/ResourceString.java new file mode 100644 index 00000000..070c7641 --- /dev/null +++ b/translations/src/main/java/org/solovyev/android/translations/ResourceString.java @@ -0,0 +1,22 @@ +package org.solovyev.android.translations; + +import org.simpleframework.xml.Attribute; +import org.simpleframework.xml.Root; +import org.simpleframework.xml.Text; + +@SuppressWarnings("unused") +@Root(name = "string", strict = false) +public class ResourceString { + @Attribute + public String name; + @Text(required = false) + public String value; + + public ResourceString() { + } + + ResourceString(String name, String value) { + this.name = name; + this.value = value; + } +} diff --git a/translations/src/main/java/org/solovyev/android/translations/Resources.java b/translations/src/main/java/org/solovyev/android/translations/Resources.java new file mode 100644 index 00000000..14846c87 --- /dev/null +++ b/translations/src/main/java/org/solovyev/android/translations/Resources.java @@ -0,0 +1,16 @@ +package org.solovyev.android.translations; + +import org.simpleframework.xml.ElementList; +import org.simpleframework.xml.Root; + +import java.util.ArrayList; +import java.util.List; + +@Root(strict = false) +public class Resources { + @ElementList(inline = true) + public List strings = new ArrayList<>(); + + public Resources() { + } +} diff --git a/translations/src/main/java/org/solovyev/android/translations/Utils.java b/translations/src/main/java/org/solovyev/android/translations/Utils.java new file mode 100644 index 00000000..02e5bc9a --- /dev/null +++ b/translations/src/main/java/org/solovyev/android/translations/Utils.java @@ -0,0 +1,90 @@ +package org.solovyev.android.translations; + +import org.apache.http.util.TextUtils; +import org.simpleframework.xml.core.Persister; + +import java.io.Closeable; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public class Utils { + + static final List languageLocales = new ArrayList<>(); + static final Persister persister = new Persister(); + + static void saveTranslations(Resources translations, String language, File outDir, + String fileName) { + final File dir = new File(outDir, valuesFolderName(language)); + dir.mkdirs(); + FileWriter out = null; + try { + out = new FileWriter(new File(dir, fileName)); + out.write("\n"); + persister.write(translations, out); + } catch (Exception e) { + e.printStackTrace(); + } finally { + close(out); + } + + } + + static void close(Closeable closeable) { + if (closeable == null) { + return; + } + try { + closeable.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + static boolean delete(File file) { + if(!file.exists()) { + return true; + } + if (file.isFile()) { + return file.delete(); + } + boolean deleted = true; + final File[] children = file.listFiles(); + if (children != null) { + for (File child : children) { + deleted &= delete(child); + } + } + return deleted && file.delete(); + } + + static String valuesFolderName(String languageLocale) { + if(TextUtils.isEmpty(languageLocale)) { + return "values"; + } + return "values-" + languageLocale; + } + + static { + languageLocales.add("ar"); + languageLocales.add("cs"); + languageLocales.add("es"); + languageLocales.add("de"); + languageLocales.add("fi"); + languageLocales.add("fr"); + languageLocales.add("it"); + languageLocales.add("nl"); + languageLocales.add("pl"); + languageLocales.add("pt-rBR"); + languageLocales.add("pt-rPT"); + languageLocales.add("ru"); + languageLocales.add("tr"); + languageLocales.add("vi"); + languageLocales.add("ja"); + languageLocales.add("ja"); + languageLocales.add("zh-rCN"); + languageLocales.add("zh-rTW"); + } +} diff --git a/wiki/src/main/java/org/solovyev/wiki/Main.java b/translations/src/main/java/org/solovyev/android/translations/Wiki.java similarity index 54% rename from wiki/src/main/java/org/solovyev/wiki/Main.java rename to translations/src/main/java/org/solovyev/android/translations/Wiki.java index cb490fdb..da5f90c6 100644 --- a/wiki/src/main/java/org/solovyev/wiki/Main.java +++ b/translations/src/main/java/org/solovyev/android/translations/Wiki.java @@ -1,4 +1,4 @@ -package org.solovyev.wiki; +package org.solovyev.android.translations; import org.apache.commons.codec.Charsets; import org.apache.http.client.methods.CloseableHttpResponse; @@ -9,55 +9,29 @@ import org.apache.http.util.EntityUtils; import org.apache.http.util.TextUtils; import org.json.JSONArray; import org.json.JSONObject; -import org.simpleframework.xml.Attribute; -import org.simpleframework.xml.ElementList; -import org.simpleframework.xml.Root; -import org.simpleframework.xml.Text; -import org.simpleframework.xml.core.Persister; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.net.URLEncoder; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -public class Main { - private static final Persister persister = new Persister(); - +public class Wiki { public static void main(String... args) throws Exception { final String inFileName = "app/src/main/res/values/text_converter.xml"; final File inFile = new File(inFileName); final File outDir = new File("build/translations/res"); - delete(outDir); + Utils.delete(outDir); outDir.mkdirs(); - final Resources resources = persister.read(Resources.class, inFile); - final List languageLocales = new ArrayList<>(); - languageLocales.add("ar"); - languageLocales.add("cs"); - languageLocales.add("es"); - languageLocales.add("de"); - languageLocales.add("fi"); - languageLocales.add("fr"); - languageLocales.add("it"); - languageLocales.add("nl"); - languageLocales.add("pl"); - languageLocales.add("pt-rbr"); - languageLocales.add("pt-rpt"); - languageLocales.add("ru"); - languageLocales.add("tr"); - languageLocales.add("vi"); - languageLocales.add("ja"); - languageLocales.add("ja"); - languageLocales.add("zh-rcn"); - languageLocales.add("zh-rtw"); + final Resources resources = Utils.persister.read(Resources.class, inFile); final CloseableHttpClient client = HttpClients.createDefault(); try { final Map allTranslations = new HashMap<>(); - for (String languageLocale : languageLocales) { + for (String languageLocale : Utils.languageLocales) { final String language = toLanguage(languageLocale); Resources translations = allTranslations.get(language); if (translations == null) { @@ -70,31 +44,14 @@ public class Main { } } } - saveTranslations(translations, languageLocale, outDir, inFile.getName()); + Utils.saveTranslations(translations, languageLocale, outDir, inFile.getName()); } } finally { - close(client); + Utils.close(client); } } - private static boolean delete(File file) { - if(!file.exists()) { - return true; - } - if (file.isFile()) { - return file.delete(); - } - boolean deleted = true; - final File[] children = file.listFiles(); - if (children != null) { - for (File child : children) { - deleted &= delete(child); - } - } - return deleted && file.delete(); - } - private static String translate(CloseableHttpClient client, String word, String language) throws UnsupportedEncodingException { final String uri = @@ -134,27 +91,11 @@ public class Main { e.printStackTrace(); System.err.println("Uri=" + uri); } finally { - close(response); + Utils.close(response); } return null; } - private static void saveTranslations(Resources translations, String language, File outDir, String fileName) { - final File dir = new File(outDir, "values-" + language); - dir.mkdirs(); - FileWriter out = null; - try { - out = new FileWriter(new File(dir, fileName)); - out.write("\n"); - persister.write(translations, out); - } catch (Exception e) { - e.printStackTrace(); - } finally { - close(out); - } - - } - private static String toLanguage(String languageLocale) { final int i = languageLocale.indexOf('-'); if(i >= 0) { @@ -162,41 +103,4 @@ public class Main { } return languageLocale; } - - private static void close(Closeable closeable) { - if (closeable == null) { - return; - } - try { - closeable.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Root - public static class Resources { - @ElementList(inline = true) - public List strings = new ArrayList<>(); - - public Resources() { - } - } - - @SuppressWarnings("unused") - @Root(name = "string") - public static class ResourceString { - @Attribute - public String name; - @Text - public String value; - - public ResourceString() { - } - - private ResourceString(String name, String value) { - this.name = name; - this.value = value; - } - } }