Author: nextgens
Date: 2007-04-20 20:53:00 +0000 (Fri, 20 Apr 2007)
New Revision: 12829

Modified:
   trunk/freenet/src/freenet/l10n/L10n.java
   trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
   trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties
   trunk/freenet/src/freenet/l10n/freenet.l10n.pl.properties
Log:
Update the l10n framework: now we use SimpleFieldSets and not java Properties 
... it means that we can have utf-8 encoded translation files :)

Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java    2007-04-20 20:51:20 UTC (rev 
12828)
+++ trunk/freenet/src/freenet/l10n/L10n.java    2007-04-20 20:53:00 UTC (rev 
12829)
@@ -4,12 +4,11 @@
 package freenet.l10n;

 import java.io.InputStream;
-import java.util.Enumeration;
 import java.util.MissingResourceException;
-import java.util.Properties;

 import freenet.support.HTMLNode;
 import freenet.support.Logger;
+import freenet.support.SimpleFieldSet;

 /**
  * This class provides a trivial internationalization framework to a freenet 
node.
@@ -31,13 +30,13 @@
        public static final String[] availableLanguages = { "en", "fr", "pl"};
        private String selectedLanguage = availableLanguages[0];

-       private static Properties currentProperties = null;
-       private static Properties fallbackProperties = null;
+       private static SimpleFieldSet currentProperties = null;
+       private static SimpleFieldSet fallbackProperties = null;
        private static L10n currentClass = null;

        L10n(String selected) {
                selectedLanguage = selected;
-               currentProperties = loadProperties(selectedLanguage);
+               currentProperties = loadTranslation(selectedLanguage);
        }

        /**
@@ -52,8 +51,10 @@
                                selectedLanguage = availableLanguages[i];
                                Logger.normal(CLASS_NAME, "Changing the current 
language to : " + selectedLanguage);
                                currentClass = new L10n(selectedLanguage);
-                               if(currentProperties == null)
+                               if(currentProperties == null) {
                                        currentClass = new 
L10n(availableLanguages[0]);
+                                       throw new 
MissingResourceException("Unable to load the translation file for 
"+selectedLanguage, "l10n", selectedLanguage);
+                               }
                                return;
                        }
                }
@@ -68,7 +69,7 @@
         * 
         * @param a property file
         */
-       public static void setLanguage(Properties customLanguage) {
+       public static void setLanguage(SimpleFieldSet customLanguage) {
                currentProperties = customLanguage;
        }

@@ -90,7 +91,7 @@
         * @see getString(String)
         */
        public static String getString(String key, boolean 
returnNullIfNotFound) {
-               String result = currentProperties.getProperty(key);
+               String result = currentProperties.get(key);
                if(result != null)
                        return result;
                else
@@ -116,9 +117,9 @@
        public static String getDefaultString(String key) {
                String result = null;
                // We instanciate it only if necessary
-               if(fallbackProperties == null) fallbackProperties = 
loadProperties(availableLanguages[0]);
+               if(fallbackProperties == null) fallbackProperties = 
loadTranslation(availableLanguages[0]);

-               result = fallbackProperties.getProperty(key);
+               result = fallbackProperties.get(key);

                if(result != null) {
                        Logger.normal(CLASS_NAME, "The translation for " + key 
+ " hasn't been found! please tell the maintainer.");
@@ -165,27 +166,29 @@
                }
                return sb.toString();
        }
-
+       
+       public static String getSelectedLanguage() {
+               return currentClass.selectedLanguage;
+       }
+       
        /**
-        * Load a property file depending on the given name and using the prefix
+        * Load a translation file depending on the given name and using the 
prefix
         * 
         * @param name
         * @return the Properties object or null if not found
         */
-       public static Properties loadProperties (String name) {
+       public static SimpleFieldSet loadTranslation(String name) {
         name = prefix.replace ('.', 
'/').concat(prefix.concat(name.concat(".properties")));
-            
-        Properties result = null;
+        
+        SimpleFieldSet result = null;
         InputStream in = null;
         try {
                ClassLoader loader = ClassLoader.getSystemClassLoader();

                // Returns null on lookup failures:
                in = loader.getResourceAsStream(name);
-               if(in != null) {
-                       result = new Properties();
-                       result.load(in); // Can throw IOException
-               }
+               if(in != null)
+                       result = SimpleFieldSet.readFrom(in, false, false);
         } catch (Exception e) {
                Logger.error("L10n", "Error while loading the l10n file from " 
+ name + " :" + e.getMessage());
             result = null;
@@ -195,50 +198,7 @@

         return result;
     }
-
-       public static String convert(String line) {
-               final StringBuffer sb = new StringBuffer();
-               int pos = 0;
-               while (pos < line.length())     {
-                       char c = line.charAt(pos++);
-                       if (c == '\\') {
-                               c = line.charAt(pos++);
-                               switch (c) {
-                                       case 'n':
-                                               sb.append('\n');
-                                               break;
-                                       case 't':
-                                               sb.append('\t');
-                                               break;
-                                       case 'r':
-                                               sb.append('\r');
-                                               break;
-                                       case 'u':
-                                               if (pos + 4 <= line.length()) {
-                                                       char uni = (char) 
Integer.parseInt(line.substring(pos, pos + 4), 16);
-                                                       sb.append(uni);
-                                                       pos += 4;
-                                               }// else throw something ?
-                                               break;
-                                       default:
-                                               sb.append(c);
-                                       break;
-                               }
-                       }
-                       else
-                               sb.append(c);
-               }
-               return sb.toString();
-       }
-       
-       public static String getSelectedLanguage() {
-               return currentClass.selectedLanguage;
-       }
-       
-       public static Enumeration getKeys() {
-               return currentProperties.propertyNames();
-       }
-       
+               
        public static void main(String[] args) {
                L10n.setLanguage("en");
                
System.out.println(L10n.getString("QueueToadlet.failedToRestart"));

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-04-20 
20:51:20 UTC (rev 12828)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-04-20 
20:53:00 UTC (rev 12829)
@@ -244,3 +244,4 @@
 NodeStat.freeHeapPercentThresholdLong=The node will try to keep it's free heap 
precentage (of max heap bytes allowed) above the threshold by refusing new 
requests
 NodeStat.statsPersister=File to store node statistics in
 NodeStat.statsPersisterLong=File to store node statistics in (not client 
statistics, and these are used to decide whether to accept requests so please 
don't delete)
+End
\ No newline at end of file

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties   2007-04-20 
20:51:20 UTC (rev 12828)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties   2007-04-20 
20:53:00 UTC (rev 12829)
@@ -11,3 +11,4 @@
 QueueToadlet.failedToRestartRequest=Impossible de relancer cette t?che
 QueueToadlet.failedToRestart=Impossible d'annuler la t?che: ${id}
 QueueToadlet.failedToRemoveId=Impossible d'annuler: ${id}
+End
\ No newline at end of file

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.pl.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.pl.properties   2007-04-20 
20:51:20 UTC (rev 12828)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.pl.properties   2007-04-20 
20:53:00 UTC (rev 12829)
@@ -13,4 +13,5 @@
 QueueToadlet.failedToRemove=Usuni?cie ${id} nie uda?o si?: ${message}
 QueueToadlet.failedToRestartRequest=Wznowienie ??dania nie powiod?o si?
 QueueToadlet.failedToRestart=Ponowienie ${id} nie powiod?o si?
-QueueToadlet.failedToRemoveId=Usuni?cie ${id} nie powiod?o si?
\ No newline at end of file
+QueueToadlet.failedToRemoveId=Usuni?cie ${id} nie powiod?o si?
+End
\ No newline at end of file


Reply via email to