Fix the translation problem since the Java compat update + fix README
authorNiki Roo <roo.niki@gmail.com>
Wed, 9 Mar 2016 07:51:21 +0000 (08:51 +0100)
committerNiki Roo <roo.niki@gmail.com>
Wed, 9 Mar 2016 07:51:21 +0000 (08:51 +0100)
README.md
src/be/nikiroo/jvcard/i18n/Trans.java

index fa5b5632541240234c62a0f6b39609b9bdfef1ff..067b2f00c7d8b611b4cd487700c5dfebc3f8bc02 100644 (file)
--- a/README.md
+++ b/README.md
@@ -14,7 +14,6 @@ Small TUI (text mode) VCard manager (also supports abook files)
 
 ## TODO
 
-- ".properties" files to easily change the colours
 - customisation of VIEW_CONTACT
 - lot of other things
 - correct UI for new contact/new data/edit data-types
index 0b2af474b5a3fafe24d6439f45dab234833461fb..c87a71f8155e06391be6aa22db35698002378c1d 100644 (file)
@@ -123,19 +123,12 @@ public class Trans {
        /**
         * Initialise the translation mappings for the given language.
         * 
-        * @param lang
-        *            the language to initialise
+        * @param language
+        *            the language to initialise, in the form "en-GB" or "fr" for
+        *            instance
         */
-       private void setLanguage(String lang) {
-               Locale locale = null;
-
-               if (lang == null) {
-                       locale = Locale.getDefault();
-               } else {
-                       locale = new Locale(lang);
-               }
-
-               map = Bundles.getBundle("resources", locale);
+       private void setLanguage(String language) {
+               map = Bundles.getBundle("resources", getLocaleFor(language));
        }
 
        /**
@@ -150,10 +143,10 @@ public class Trans {
         * @throws IOException
         *             in case of IO errors
         */
-       public static void main(String[] args) throws IOException {
+       static public void main(String[] args) throws IOException {
                String path = args[0];
                for (int i = 1; i < args.length; i++) {
-                       Locale locale = new Locale(args[i].replaceAll("_", "-"));
+                       Locale locale = getLocaleFor(args[i]);
                        String code = locale.toString();
                        Trans trans = new Trans(code);
 
@@ -209,6 +202,39 @@ public class Trans {
                }
        }
 
+       /**
+        * Return the {@link Locale} representing the given language.
+        * 
+        * @param language
+        *            the language to initialise, in the form "en-GB" or "fr" for
+        *            instance
+        * 
+        * @return the corresponding {@link Locale} or the default {@link Locale} if
+        *         it is not known
+        */
+       static private Locale getLocaleFor(String language) {
+               Locale locale;
+
+               if (language == null) {
+                       locale = Locale.getDefault();
+               } else {
+                       language = language.replaceAll("_", "-");
+                       String lang = language;
+                       String country = null;
+                       if (language.contains("-")) {
+                               lang = language.split("-")[0];
+                               country = language.split("-")[1];
+                       }
+
+                       if (country != null)
+                               locale = new Locale(lang, country);
+                       else
+                               locale = new Locale(lang);
+               }
+
+               return locale;
+       }
+
        /**
         * Return formated, display-able information from the {@link Meta} field
         * given. Each line will always starts with a "#" character.
@@ -218,7 +244,7 @@ public class Trans {
         * 
         * @return the information to display or NULL if none
         */
-       private static String getMetaInfo(Meta meta) {
+       static private String getMetaInfo(Meta meta) {
                String what = meta.what();
                String where = meta.where();
                String format = meta.format();