Author: nextgens
Date: 2007-04-13 14:04:27 +0000 (Fri, 13 Apr 2007)
New Revision: 12624

Modified:
   trunk/freenet/src/freenet/l10n/L10n.java
Log:
^

Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java    2007-04-13 12:57:26 UTC (rev 
12623)
+++ trunk/freenet/src/freenet/l10n/L10n.java    2007-04-13 14:04:27 UTC (rev 
12624)
@@ -8,6 +8,7 @@
 import java.util.MissingResourceException;
 import java.util.Properties;

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

 /**
@@ -65,17 +66,41 @@
        /**
         * The real meat
         * 
+        * Same thing as getString(key, false);
+        * Ensure it will *always* return a String value.
+        * 
         * @param key
         * @return the translated string or the default value from the default 
language or the key if nothing is found
         */
        public static String getString(String key) {
+               return getString(key, false);
+       }
+       
+       /**
+        * You probably don't want to use that one directly
+        * @see getString(String)
+        */
+       public static String getString(String key, boolean 
returnNullIfNotFound) {
                String result = currentProperties.getProperty(key);
-               if(result != null) 
+               if(result != null)
                        return result;
                else
-                       return getDefaultString(key);
+                       return (returnNullIfNotFound ? null : 
getDefaultString(key));
        }

+       /**
+        * Almost the same as getString(String) ... but it returns a HTMLNode 
and gives the user the ability to contribute to the translation
+        * @param key
+        * @return HTMLNode
+        */
+       public static HTMLNode getHTMLNode(String key) {
+               String value = getString(key, true);
+               if(value != null)
+                       return new HTMLNode("#", value);
+               else
+                       return new HTMLNode("#", value).addChild("span", "id", 
"translate_it").addChild("a", "href", "/?translate=" + key).addChild("small", " 
(translate it in your native language!)");
+       }
+       
        public static String getDefaultString(String key) {
                String result = null;
                // We instanciate it only if necessary


Reply via email to