From a45fbb6a1f8e8b17026d56a7f7d88fde37ded2fc Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 12 Jun 2016 21:57:27 +0200 Subject: [PATCH] Make translations more generic --- translations/build.gradle | 3 + .../android/translations/Android.java | 79 ++++--------------- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/translations/build.gradle b/translations/build.gradle index 60b6e3c4..08dc914b 100644 --- a/translations/build.gradle +++ b/translations/build.gradle @@ -1,4 +1,7 @@ apply plugin: 'java' +apply plugin: 'application' + +mainClassName = 'org.solovyev.android.translations.Android' dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) 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 67bb7c81..d42000cd 100644 --- a/translations/src/main/java/org/solovyev/android/translations/Android.java +++ b/translations/src/main/java/org/solovyev/android/translations/Android.java @@ -9,71 +9,16 @@ import java.util.List; public class Android { - private static final List settingsLinks = new ArrayList<>(); - private static final List calendarLinks = new ArrayList<>(); - private static final List contactsLinks = new ArrayList<>(); - private static final List calculatorLinks = new ArrayList<>(); - private static final List platformLinks = new ArrayList<>(); - - 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")); - settingsLinks.add(new TranslationLink("user_dict_settings_add_menu_title", "cpp_add")); - settingsLinks.add(new TranslationLink("location_mode_title", "cpp_mode")); - settingsLinks.add(new TranslationLink("enable_text", "cpp_enable")); - settingsLinks.add(new TranslationLink("storage_detail_other", "cpp_other")); - settingsLinks.add(new TranslationLink("accessibility_toggle_high_text_contrast_preference_title", "cpp_high_contrast_text")); - - calendarLinks.add(new TranslationLink("edit_label", "cpp_edit")); - calendarLinks.add(new TranslationLink("delete_label", "cpp_delete")); - calendarLinks.add(new TranslationLink("save_label", "cpp_done")); - calendarLinks.add(new TranslationLink("discard_label", "cpp_cancel")); - calendarLinks.add(new TranslationLink("hint_description", "cpp_description")); - calendarLinks.add(new TranslationLink("preferences_about_title", "cpp_about")); - - contactsLinks.add(new TranslationLink("copy_text", "cpp_copy_text")); - contactsLinks.add(new TranslationLink("toast_text_copied", "cpp_text_copied")); - contactsLinks.add(new TranslationLink("header_name_entry", "cpp_name")); - contactsLinks.add(new TranslationLink("activity_title_settings", "cpp_settings")); - - calculatorLinks.add(new TranslationLink("error_nan", "cpp_nan")); - calculatorLinks.add(new TranslationLink("error_syntax", "cpp_error")); - - platformLinks.add(new TranslationLink("copy", "cpp_copy")); - } - public static void main(String... args) throws Exception { final Options options = new Options(); - options.addOption(Option.builder("aosp").hasArg().desc("Local location of aosp project").required().build()); + options.addOption(Option.builder("prefix").hasArg().desc("Local location of Android project").required(false).build()); options.addOption(Option.builder("project").hasArg().desc("Local location of Android project").build()); options.addOption(Option.builder("resources").hasArg().desc("String identifiers to be copied").build()); + options.addOption(Option.builder("output").hasArg().desc("Output folder").required().build()); final CommandLineParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(options, args); - final String aosp = commandLine.getOptionValue("aosp"); - final File aospSettings = makeInputDirectory(aosp + "/platform/packages/apps/settings"); - final File aospCalendar = makeInputDirectory(aosp + "/platform/packages/apps/calendar"); - final File aospContacts = makeInputDirectory(aosp + "/platform/packages/apps/contacts"); - final File aospCalculator = makeInputDirectory(aosp + "/platform/packages/apps/calculator"); - - final String androidHome = System.getenv("ANDROID_HOME"); - if (TextUtils.isEmpty(androidHome)) { - throw new MissingOptionException("ANDROID_HOME must be set"); - } - final File androidPlatform = makeInputDirectory(androidHome + "/platforms/android-23/data"); - final File[] projects; if (commandLine.hasOption("project")) { final String[] projectPaths = commandLine.getOptionValues("project"); @@ -84,6 +29,7 @@ public class Android { } else { projects = null; } + final String prefix = makePrefix(commandLine.getOptionValue("prefix")); final List[] projectsLinks; if (commandLine.hasOption("resources")) { final String[] projectResources = commandLine.getOptionValues("resources"); @@ -94,9 +40,9 @@ public class Android { for (String resource : resources.split(",")) { final int i = resource.indexOf("-"); if (i >= 0) { - projectsLinks[j].add(new TranslationLink(resource.substring(0, i), "cpp_" + resource.substring(i + 1, resource.length()))); + projectsLinks[j].add(new TranslationLink(resource.substring(0, i), prefix + resource.substring(i + 1, resource.length()))); } else { - projectsLinks[j].add(new TranslationLink(resource, "cpp_" + resource)); + projectsLinks[j].add(new TranslationLink(resource, prefix + resource)); } } } @@ -104,11 +50,11 @@ public class Android { projectsLinks = null; } - final File outDir = new File("build/translations/res"); + final File outDir = new File(commandLine.getOptionValue("output")); Utils.delete(outDir); - outDir.mkdirs(); + final File outResDir = new File(outDir, "res"); + outResDir.mkdirs(); - translate(outDir, "aosp", new TranslationDef(aospSettings, settingsLinks), new TranslationDef(aospCalendar, calendarLinks), new TranslationDef(aospContacts, contactsLinks), new TranslationDef(aospCalculator, calculatorLinks), new TranslationDef(androidPlatform, platformLinks)); if (projects != null && projects.length != 0) { if (projectsLinks == null || projectsLinks.length != projects.length) { throw new IllegalArgumentException("Projects=" + projects.length + ", resources=" + (projectsLinks == null ? 0 : projectsLinks.length)); @@ -116,11 +62,18 @@ public class Android { for (int i = 0; i < projects.length; i++) { final File project = projects[i]; final List projectLinks = projectsLinks[i]; - translate(outDir, "other" + (i == 0 ? "" : i), new TranslationDef(project, projectLinks)); + translate(outResDir, "other" + (i == 0 ? "" : i), new TranslationDef(project, projectLinks)); } } } + private static String makePrefix(String prefix) { + if (prefix == null || prefix.length() == 0) { + return ""; + } + return prefix + "_"; + } + private static void translate(File outDir, String outPostfix, TranslationDef... translationDefs) throws Exception { List languageLocales = new ArrayList<>(Utils.languageLocales); languageLocales.add("");