Author: nextgens
Date: 2008-06-08 09:08:51 +0000 (Sun, 08 Jun 2008)
New Revision: 20258

Modified:
   trunk/freenet/src/freenet/l10n/L10n.java
   trunk/freenet/src/freenet/node/Node.java
Log:
Implement #1333: L10n: use full names instead of the ISO code

I am not sure about the native language names... review would be welcome

Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java    2008-06-08 08:32:13 UTC (rev 
20257)
+++ trunk/freenet/src/freenet/l10n/L10n.java    2008-06-08 09:08:51 UTC (rev 
20258)
@@ -32,8 +32,22 @@
        public static final String OVERRIDE_SUFFIX = ".override" + SUFFIX;

        public static final String FALLBACK_DEFAULT = "en";
-       public static final String[] AVAILABLE_LANGUAGES = { "en", "es", "da", 
"de", "fi", "fr", "it", "no", "pl", "se",
-               "zh-cn", "zh-tw", "unlisted" };
+       /** @see http://www.omniglot.com/language/names.htm */
+       public static final String[][] AVAILABLE_LANGUAGES = {
+               new String[] { "en", "English" },
+               new String[] { "es", "Espa?ol" },
+               new String[] { "da", "Dansk" },
+               new String[] { "de", "Deutsch" },
+               new String[] { "fi", "Suomi" },
+               new String[] { "fr", "Fran?ais" },
+               new String[] { "it", "Italiano" },
+               new String[] { "no", "Norsk" },
+               new String[] { "pl", "Polski" },
+               new String[] { "se", "Svenska" },
+               new String[] { "zh-cn", "??" },
+               new String[] { "zh-tw", "??" },
+               new String[] { "unlisted", "unlisted"},
+       };
        private final String selectedLanguage;

        private static SimpleFieldSet currentTranslation = null;
@@ -81,25 +95,13 @@
        */
        public static void setLanguage(String selectedLanguage) throws 
MissingResourceException {
                synchronized (sync) {
-                       for(int i=0; i<AVAILABLE_LANGUAGES.length; i++){
-                               
if(selectedLanguage.equalsIgnoreCase(AVAILABLE_LANGUAGES[i])){          
-                                       selectedLanguage = 
AVAILABLE_LANGUAGES[i];
-                                       Logger.normal(CLASS_NAME, "Changing the 
current language to : " + selectedLanguage);
-
-                                       currentClass = new 
L10n(selectedLanguage);      
-
-                                       if(currentTranslation == null) {
-                                               currentClass = new 
L10n(FALLBACK_DEFAULT);      
-                                               throw new 
MissingResourceException("Unable to load the translation file for 
"+selectedLanguage, "l10n", selectedLanguage);
-                                       }
-
-                                       return;
-                               }
+                       Logger.normal(CLASS_NAME, "Changing the current 
language to : " + selectedLanguage);
+                       currentClass = new L10n(selectedLanguage);
+                       if(currentClass == null) {
+                               currentClass = new L10n(FALLBACK_DEFAULT);
+                               Logger.error(CLASS_NAME, "The requested 
translation is not available!" + selectedLanguage);
+                               throw new MissingResourceException("The 
requested translation (" + selectedLanguage + ") hasn't been found!", 
CLASS_NAME, selectedLanguage);
                        }
-
-                       currentClass = new L10n(FALLBACK_DEFAULT);
-                       Logger.error(CLASS_NAME, "The requested translation is 
not available!" + selectedLanguage);
-                       throw new MissingResourceException("The requested 
translation ("+selectedLanguage+") hasn't been found!", CLASS_NAME, 
selectedLanguage);
                }
        }

@@ -322,6 +324,12 @@
        * @return the Properties object or null if not found
        */
        public static SimpleFieldSet loadTranslation(String name) {
+               String shortCountryCode = mapLanguageNameToShortCode(name);
+               if(shortCountryCode == null) { 
+                       Logger.error("L10n", "Can't map "+name+" to a country 
code!");
+                       return null;
+               } else
+                       name = shortCountryCode;
                name = PREFIX.replace ('.', 
'/').concat(PREFIX.concat(name.concat(SUFFIX)));

                SimpleFieldSet result = null;
@@ -342,6 +350,23 @@

                return result;
        }
+       
+       /**
+        * Map a full string language name to the corresponding country short 
code
+        * 
+        * @param The name to look for
+        * @return The two letters short code OR null if not found
+        */
+       public static String mapLanguageNameToShortCode(String name) {
+               for(int i=0; i<AVAILABLE_LANGUAGES.length; i++) {
+                       String currentShortCode = AVAILABLE_LANGUAGES[i][0];
+                       String currentLongName = AVAILABLE_LANGUAGES[i][1];
+                       
+                       if(currentShortCode.equalsIgnoreCase(name) || 
currentLongName.equalsIgnoreCase(name))
+                               return currentShortCode;
+               }
+               return null;
+       }

        public static boolean isOverridden(String key) {
                synchronized(sync) {

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2008-06-08 08:32:13 UTC (rev 
20257)
+++ trunk/freenet/src/freenet/node/Node.java    2008-06-08 09:08:51 UTC (rev 
20258)
@@ -212,7 +212,10 @@
                }

                public String[] getPossibleValues() {
-                       return L10n.AVAILABLE_LANGUAGES;
+                       String[] result = new 
String[L10n.AVAILABLE_LANGUAGES.length];
+                       for(int i=0; i<L10n.AVAILABLE_LANGUAGES.length; i++)
+                               result[i] = L10n.AVAILABLE_LANGUAGES[i][1];
+                       return result;
                }
        }



Reply via email to