Author: nextgens
Date: 2007-03-31 22:11:28 +0000 (Sat, 31 Mar 2007)
New Revision: 12497

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
Log:
Add a convenient method to the framework allowing the usage of patterns within 
the translation file.

Modified: trunk/freenet/src/freenet/l10n/L10n.java
===================================================================
--- trunk/freenet/src/freenet/l10n/L10n.java    2007-03-31 22:09:27 UTC (rev 
12496)
+++ trunk/freenet/src/freenet/l10n/L10n.java    2007-03-31 22:11:28 UTC (rev 
12497)
@@ -78,6 +78,25 @@
        }

        /**
+        * Allows things like :
+        * L10n.getString("testing.test", new String[]{ "test1", "test2" }, new 
String[] { "a", "b" })
+        * 
+        * @param key
+        * @param patterns : a list of patterns wich are matchable from the 
translation
+        * @param values : the values corresponding to the list
+        * @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, String[] patterns, String[] 
values) {
+               assert(patterns.length == values.length);
+               String result = getString(key);
+
+               for(int i=0; i<patterns.length; i++)
+                       result = result.replaceAll("\\$\\("+patterns[i]+"\\)", 
values[i]);
+               
+               return result;
+       }
+       
+       /**
         * Load a property file depending on the given name and using the prefix
         * 
         * @param name
@@ -109,5 +128,6 @@
        public static void main(String[] args) {
                L10n.setLanguage("fr");
                System.out.println(L10n.getString("testing.test"));
+               System.out.println(L10n.getString("testing.test", new String[]{ 
"test1", "test2" }, new String[] { "a", "b" }));
        }
 }

Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-03-31 
22:09:27 UTC (rev 12496)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.en.properties   2007-03-31 
22:11:28 UTC (rev 12497)
@@ -1 +1 @@
-testing.test=test
\ No newline at end of file
+testing.test=test$(test1)test$(test2)test
\ 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-03-31 
22:09:27 UTC (rev 12496)
+++ trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties   2007-03-31 
22:11:28 UTC (rev 12497)
@@ -1 +1 @@
-testing.test=testfr
\ No newline at end of file
+testing.test=testfr$(test1)testfr$(test2)testfr
\ No newline at end of file


Reply via email to