Copy translations from AOSP
This commit is contained in:
parent
57cdbad079
commit
7e41f30e06
8
app/src/main/res/values-ar/text_imported.xml
Normal file
8
app/src/main/res/values-ar/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">الاهتزاز عند اللمس</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">التدوير التلقائي للشاشة</string>
|
||||||
|
<string name="cpp_prefs_language">اللغة</string>
|
||||||
|
<string name="cpp_prefs_theme">المظهر</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">البقاء في الوضع النشط</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-cs/text_imported.xml
Normal file
8
app/src/main/res/values-cs/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Při dotyku vibrovat</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Autom. otočení obrazovky</string>
|
||||||
|
<string name="cpp_prefs_language">Jazyk</string>
|
||||||
|
<string name="cpp_prefs_theme">Motiv</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Nevypínat obrazovku</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-de/text_imported.xml
Normal file
8
app/src/main/res/values-de/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Bei Berührung vibrieren</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Display automatisch drehen</string>
|
||||||
|
<string name="cpp_prefs_language">Sprache</string>
|
||||||
|
<string name="cpp_prefs_theme">Design</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Aktiv lassen</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-es/text_imported.xml
Normal file
8
app/src/main/res/values-es/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Vibrar al tocar</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Girar pantalla automáticamente</string>
|
||||||
|
<string name="cpp_prefs_language">Idioma</string>
|
||||||
|
<string name="cpp_prefs_theme">Tema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Pantalla activa</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-fi/text_imported.xml
Normal file
8
app/src/main/res/values-fi/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Käytä värinää kosketettaessa</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Näytön automaattinen kierto</string>
|
||||||
|
<string name="cpp_prefs_language">Kieli</string>
|
||||||
|
<string name="cpp_prefs_theme">Teema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Pysy käynnissä</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-fr/text_imported.xml
Normal file
8
app/src/main/res/values-fr/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Vibrer au toucher</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Rotation auto de l\'écran</string>
|
||||||
|
<string name="cpp_prefs_language">Langue</string>
|
||||||
|
<string name="cpp_prefs_theme">Thème</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Rester activé</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-it/text_imported.xml
Normal file
8
app/src/main/res/values-it/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Vibra alla pressione</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Rotazione automatica</string>
|
||||||
|
<string name="cpp_prefs_language">Lingua</string>
|
||||||
|
<string name="cpp_prefs_theme">Tema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Rimani attivo</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-ja/text_imported.xml
Normal file
8
app/src/main/res/values-ja/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">タッチ操作バイブ</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">画面の自動回転</string>
|
||||||
|
<string name="cpp_prefs_language">言語</string>
|
||||||
|
<string name="cpp_prefs_theme">テーマ</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">スリープモードにしない</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-nl/text_imported.xml
Normal file
8
app/src/main/res/values-nl/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Trillen bij aanraking</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Scherm autom. draaien</string>
|
||||||
|
<string name="cpp_prefs_language">Taal</string>
|
||||||
|
<string name="cpp_prefs_theme">Thema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Stand-by</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-pl/text_imported.xml
Normal file
8
app/src/main/res/values-pl/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Wibracje przy dotknięciu</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Autoobracanie ekranu</string>
|
||||||
|
<string name="cpp_prefs_language">Język</string>
|
||||||
|
<string name="cpp_prefs_theme">Motyw</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Pozostaw ekran włączony</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-pt-rBR/text_imported.xml
Normal file
8
app/src/main/res/values-pt-rBR/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Vibrar ao tocar</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Girar tela</string>
|
||||||
|
<string name="cpp_prefs_language">Idioma</string>
|
||||||
|
<string name="cpp_prefs_theme">Tema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Permanecer ativo</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-pt-rPT/text_imported.xml
Normal file
8
app/src/main/res/values-pt-rPT/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Vibrar ao tocar</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Rodar ecrã automaticamente</string>
|
||||||
|
<string name="cpp_prefs_language">Idioma</string>
|
||||||
|
<string name="cpp_prefs_theme">Tema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Manter ativo</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-ru/text_imported.xml
Normal file
8
app/src/main/res/values-ru/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Виброотклик</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Автоповорот экрана</string>
|
||||||
|
<string name="cpp_prefs_language">Язык</string>
|
||||||
|
<string name="cpp_prefs_theme">Тема</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Не выключать экран</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-tr/text_imported.xml
Normal file
8
app/src/main/res/values-tr/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Dokunulduğunda titreşim</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Ekranı otomatik döndür</string>
|
||||||
|
<string name="cpp_prefs_language">Dil</string>
|
||||||
|
<string name="cpp_prefs_theme">Tema</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Uyanık kal</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-vi/text_imported.xml
Normal file
8
app/src/main/res/values-vi/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Rung khi chạm</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Tự động xoay màn hình</string>
|
||||||
|
<string name="cpp_prefs_language">Ngôn ngữ</string>
|
||||||
|
<string name="cpp_prefs_theme">Chủ đề</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Không khóa màn hình</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-zh-rCN/text_imported.xml
Normal file
8
app/src/main/res/values-zh-rCN/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">触摸时振动</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">自动旋转屏幕</string>
|
||||||
|
<string name="cpp_prefs_language">语言</string>
|
||||||
|
<string name="cpp_prefs_theme">主题背景</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">不锁定屏幕</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values-zh-rTW/text_imported.xml
Normal file
8
app/src/main/res/values-zh-rTW/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">觸控時震動</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">自動旋轉螢幕</string>
|
||||||
|
<string name="cpp_prefs_language">語言</string>
|
||||||
|
<string name="cpp_prefs_theme">主題</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">螢幕不休眠</string>
|
||||||
|
</resources>
|
8
app/src/main/res/values/text_imported.xml
Normal file
8
app/src/main/res/values/text_imported.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string name="cpp_prefs_vibrate_on_keypress">Vibrate on touch</string>
|
||||||
|
<string name="cpp_prefs_auto_rotate_screen">Auto-rotate screen</string>
|
||||||
|
<string name="cpp_prefs_language">Language</string>
|
||||||
|
<string name="cpp_prefs_theme">Theme</string>
|
||||||
|
<string name="cpp_prefs_keep_screen_on">Stay awake</string>
|
||||||
|
</resources>
|
@ -18,5 +18,4 @@
|
|||||||
<string name="prefs_prevent_screen_from_fading_summary">If turned on screen will not fade while using the app
|
<string name="prefs_prevent_screen_from_fading_summary">If turned on screen will not fade while using the app
|
||||||
</string>
|
</string>
|
||||||
<string name="prefs_language_title">Language</string>
|
<string name="prefs_language_title">Language</string>
|
||||||
<string name="cpp_prefs_vibrate_on_keypress">Vibrate on keypress</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
<org.solovyev.android.material.preferences.ListPreference
|
<org.solovyev.android.material.preferences.ListPreference
|
||||||
a:key="gui.language"
|
a:key="gui.language"
|
||||||
a:title="@string/prefs_language_title"
|
a:title="@string/cpp_prefs_language"
|
||||||
m:materialColor="@color/material_text_selector" />
|
m:materialColor="@color/material_text_selector" />
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
@ -51,8 +51,7 @@
|
|||||||
a:entries="@array/p_theme_names"
|
a:entries="@array/p_theme_names"
|
||||||
a:entryValues="@array/p_theme_values"
|
a:entryValues="@array/p_theme_values"
|
||||||
a:key="@string/p_calc_theme_key"
|
a:key="@string/p_calc_theme_key"
|
||||||
a:summary="@string/c_calc_theme_summary"
|
a:title="@string/cpp_prefs_theme" />
|
||||||
a:title="@string/c_calc_theme" />
|
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
a:entries="@array/p_layout_names"
|
a:entries="@array/p_layout_names"
|
||||||
@ -64,8 +63,7 @@
|
|||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
a:defaultValue="true"
|
a:defaultValue="true"
|
||||||
a:key="autoOrientation"
|
a:key="autoOrientation"
|
||||||
a:summary="@string/c_auto_orientation_summary"
|
a:title="@string/cpp_prefs_auto_rotate_screen" />
|
||||||
a:title="@string/c_auto_orientation_title" />
|
|
||||||
|
|
||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
@ -76,7 +74,6 @@
|
|||||||
|
|
||||||
<android.preference.CheckBoxPreference
|
<android.preference.CheckBoxPreference
|
||||||
a:key="preventScreenFromFading"
|
a:key="preventScreenFromFading"
|
||||||
a:summary="@string/prefs_prevent_screen_from_fading_summary"
|
a:title="@string/cpp_prefs_keep_screen_on" />
|
||||||
a:title="@string/prefs_prevent_screen_from_fading_title" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@ -1 +1 @@
|
|||||||
include ':app', ':jscl', ':wiki'
|
include ':app', ':jscl', ':translations'
|
||||||
|
@ -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<TranslationLink> 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<String> 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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<ResourceString> strings = new ArrayList<>();
|
||||||
|
|
||||||
|
public Resources() {
|
||||||
|
}
|
||||||
|
}
|
@ -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<String> 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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\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");
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.solovyev.wiki;
|
package org.solovyev.android.translations;
|
||||||
|
|
||||||
import org.apache.commons.codec.Charsets;
|
import org.apache.commons.codec.Charsets;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
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.apache.http.util.TextUtils;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
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.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Main {
|
public class Wiki {
|
||||||
private static final Persister persister = new Persister();
|
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
final String inFileName = "app/src/main/res/values/text_converter.xml";
|
final String inFileName = "app/src/main/res/values/text_converter.xml";
|
||||||
final File inFile = new File(inFileName);
|
final File inFile = new File(inFileName);
|
||||||
|
|
||||||
final File outDir = new File("build/translations/res");
|
final File outDir = new File("build/translations/res");
|
||||||
delete(outDir);
|
Utils.delete(outDir);
|
||||||
outDir.mkdirs();
|
outDir.mkdirs();
|
||||||
|
|
||||||
final Resources resources = persister.read(Resources.class, inFile);
|
final Resources resources = Utils.persister.read(Resources.class, inFile);
|
||||||
final List<String> 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 CloseableHttpClient client = HttpClients.createDefault();
|
final CloseableHttpClient client = HttpClients.createDefault();
|
||||||
try {
|
try {
|
||||||
final Map<String, Resources> allTranslations = new HashMap<>();
|
final Map<String, Resources> allTranslations = new HashMap<>();
|
||||||
for (String languageLocale : languageLocales) {
|
for (String languageLocale : Utils.languageLocales) {
|
||||||
final String language = toLanguage(languageLocale);
|
final String language = toLanguage(languageLocale);
|
||||||
Resources translations = allTranslations.get(language);
|
Resources translations = allTranslations.get(language);
|
||||||
if (translations == null) {
|
if (translations == null) {
|
||||||
@ -70,31 +44,14 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveTranslations(translations, languageLocale, outDir, inFile.getName());
|
Utils.saveTranslations(translations, languageLocale, outDir, inFile.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
} finally {
|
} 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)
|
private static String translate(CloseableHttpClient client, String word, String language)
|
||||||
throws UnsupportedEncodingException {
|
throws UnsupportedEncodingException {
|
||||||
final String uri =
|
final String uri =
|
||||||
@ -134,27 +91,11 @@ public class Main {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.err.println("Uri=" + uri);
|
System.err.println("Uri=" + uri);
|
||||||
} finally {
|
} finally {
|
||||||
close(response);
|
Utils.close(response);
|
||||||
}
|
}
|
||||||
return null;
|
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("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
|
|
||||||
persister.write(translations, out);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
close(out);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String toLanguage(String languageLocale) {
|
private static String toLanguage(String languageLocale) {
|
||||||
final int i = languageLocale.indexOf('-');
|
final int i = languageLocale.indexOf('-');
|
||||||
if(i >= 0) {
|
if(i >= 0) {
|
||||||
@ -162,41 +103,4 @@ public class Main {
|
|||||||
}
|
}
|
||||||
return languageLocale;
|
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<ResourceString> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user