Author: jerome
Date: 2009-02-22 16:19:42 +0100 (Sun, 22 Feb 2009)
New Revision: 3727

Added:
   software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/
   software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/es.po
   software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/fr.po
   software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/nl.po
Modified:
   software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java
   
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
Log:
* The library can now be used with local files and internal jar resources.

Modified: software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java       
2009-02-22 13:37:51 UTC (rev 3726)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java       
2009-02-22 15:19:42 UTC (rev 3727)
@@ -31,15 +31,28 @@
         */
        public static void main(String[] args)
        {
-               try 
+               if((args.length > 0) && 
(args[0].toString().equalsIgnoreCase("--files")))
                {
-                       I18N i18n = new 
I18N("D:/devel/svn-tuxisalive/software_suite_v2/software/gadgets/tuxdroid-gadget-weather/trunk/tuxdroid-gadget-weather/resources",
 "nl");
-                       System.out.println(i18n.getString("Current weather at 
{0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity level is {3} 
percent."));
-                       
+                       //Test with external files.
+                       I18N i18n = null;
+                       try 
+                       {
+                               i18n = new 
I18N("D:/devel/svn-tuxisalive/software_suite_v2/software/gadgets/tuxdroid-gadget-weather/trunk/tuxdroid-gadget-weather/resources",
 "nl");
+                       } 
+                       catch (I18NFileNotFoundException e) 
+                       {
+                               ;
+                       }
+                       if(i18n != null)
+                       {
+                               System.out.println(i18n.getString("Current 
weather at {0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity 
level is {3} percent."));
+                       }
                }
-               catch (I18NFileNotFoundException e) 
+               else
                {
-                       e.printStackTrace();
+                       //Test with internal resources ( compressed into the 
jar file ).
+                       I18N i18n = new I18N("/resourcesTest", "fr", 
I18NTests.class);
+                       System.out.println(i18n.getString("Current weather at 
{0} is \"unknown\" with a temperature of {1} degrees {2}; Humidity level is {3} 
percent."));
                }
        }
 }

Modified: 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
===================================================================
--- 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
  2009-02-22 13:37:51 UTC (rev 3726)
+++ 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
  2009-02-22 15:19:42 UTC (rev 3727)
@@ -24,6 +24,7 @@
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Hashtable;
@@ -33,8 +34,11 @@
 public class I18N {
        
        private File poPath;
+       private String poURL;
        private String language;
        private Hashtable<String, String> strings = new Hashtable<String, 
String>(); 
+       private boolean isResource = false;
+       private Class<?> parent;
        
        /**
         * This class create an I18N object based on po files.
@@ -48,6 +52,22 @@
        
        
        /**
+        * Create a I18N object based on the given URL, in this case, po files 
must be
+        * as "en.po", "fr.po", "nl.po", ...
+        * @param resource : the resource directory where can be found streams.
+        * @param language : Target language.
+        */
+       public I18N(String resource, String language, Class<?> parent)
+       {
+               this.poURL = resource;
+               this.isResource = true;
+               this.language = language;
+               this.parent = parent;
+               this.createObjectAsStream();
+       }
+       
+       
+       /**
         * Create the language object.
         * @param fileName
         * @param language
@@ -71,7 +91,29 @@
        }
        
        
+       
        /**
+        * Create the I18N Object with a given URL.
+        */
+       private void createObjectAsStream()
+       {
+               if((this.poURL != null) &&(this.isResource))
+               {
+                       try
+                       {
+                               String newURL = poURL + "/" + this.language + 
".po";    
+                               InputStream ips = 
this.parent.getResourceAsStream(newURL);
+                               this.parseInputStream(ips);
+                       }
+                       catch(Exception e)
+                       {
+                               ;
+                       }
+               }
+       }
+         
+       
+       /**
         * Return asked string.
         * @param aString : the String to search.
         * @return : translated string.
@@ -83,7 +125,7 @@
                        //then getting string value.
                        if(this.strings.containsKey(aString))
                        {
-                               return this.strings.get(aString).toString();
+                               return this.strings.get(aString);
                        }
                }
                return aString;
@@ -137,10 +179,29 @@
                }
                
                //Read po file.
+               try 
+               {
+                       InputStream ips = new FileInputStream(finalFile);
+                       this.parseInputStream(ips);
+               } 
+               catch (FileNotFoundException e) 
+               {
+                       ;
+               } 
+                       
+               
+       }
+       
+       
+       /**
+        * Parse the given input stream.
+        * @param ips : input stream.
+        */
+       public void parseInputStream(InputStream ips)
+       {
                try
                {
-                       InputStream ips = new FileInputStream(finalFile); 
-                       InputStreamReader ipsr=new InputStreamReader(ips);
+                       InputStreamReader ipsr = new InputStreamReader(ips);
                        BufferedReader br=new BufferedReader(ipsr);
                        String ligne;
                        String msgid = null;
@@ -190,10 +251,10 @@
                                }
                        }
                        br.close(); 
-               }               
-               catch (Exception e)
+               }
+               catch(Exception e)
                {
-                       e.printStackTrace();
+                       ;
                }
        }
 }

Added: 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/es.po
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/es.po  
                        (rev 0)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/es.po  
2009-02-22 15:19:42 UTC (rev 3727)
@@ -0,0 +1,35 @@
+msgid "Weather Gadget"
+msgstr "Gadget del Tiempo"
+
+msgid "Weather Gadget"
+msgstr "Gadget del Tiempo"
+
+msgid "Google Weather Gadget"
+msgstr "Gadget del tiempo de Google"
+
+msgid "Weather location"
+msgstr "Ubicación"
+
+msgid "Temperature unit"
+msgstr "Unidad de temperatura"
+
+msgid "Give tomorrow's weather too"
+msgstr "Dar el tiempo para mañana tambien"
+
+msgid "Check the weather"
+msgstr "Comprobar el tiempo"
+
+msgid "Current weather at {0} is \"{1}\" with a temperature of {2} degrees 
{3}; Humidity level is {4} percent."
+msgstr "El tiempo en {0} es \"{1}\" con una temperatura de {2} grados {3}. El 
mivel de humedad es del {4} porciento."
+
+msgid "Current weather at {0} is \"unknown\" with a temperature of {1} degrees 
{2}; Humidity level is {3} percent."
+msgstr "El tiempo en {0} es \"desconodido\" con una temperatura de {2} grados 
{3}. El nivel de humedad es del {4} porciento."
+
+msgid "Tomorrow's forecast. \"{0}\" temperatures from {1} to {2} degrees."
+msgstr "El tiempo para mañana: \"{0}\" temperaturas de {1} a {2} grados."
+
+msgid "http://www.google.com/ig/api?hl=en&weather=%s";
+msgstr "http://www.google.com/ig/api?hl=es&weather=%s";
+
+msgid "Location could not be found. Please check the city name or enter 
another close by location."
+msgstr "La ubicacion no se encuentra. Compruebe el nombre de la ciudad o 
indique otra cercana."

Added: 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/fr.po
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/fr.po  
                        (rev 0)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/fr.po  
2009-02-22 15:19:42 UTC (rev 3727)
@@ -0,0 +1,35 @@
+msgid "Weather Gadget"
+msgstr "Gadget Météo"
+
+msgid "Weather Gadget"
+msgstr "Gadget Météo"
+
+msgid "Google Weather Gadget"
+msgstr "Google Gadget Météo"
+
+msgid "Weather location"
+msgstr "Localisation"
+
+msgid "Temperature unit"
+msgstr "Unité de température"
+
+msgid "Give tomorrow's weather too"
+msgstr "Donner les prévisions météo"
+
+msgid "Check the weather"
+msgstr "Vérifier la météo"
+
+msgid "Current weather at {0} is \"{1}\" with a temperature of {2} degrees 
{3}; Humidity level is {4} percent."
+msgstr "La météo actuelle à {0} est \"{1}\" avec une température de {2} degrés 
{3}. Le taux d'humidité est de {4} pour cent."
+
+msgid "Current weather at {0} is \"unknown\" with a temperature of {1} degrees 
{2}; Humidity level is {3} percent."
+msgstr "La météo actuelle à {0} est \"inconnue\" avec une température de {1} 
degrés {2}. Le taux d'humidité est de {3} pour cent."
+
+msgid "Tomorrow's forecast. \"{0}\" temperatures from {1} to {2} degrees."
+msgstr "Les prévisions pour demain : \"{0}\" avec des température de {1} à {2} 
degrés."
+
+msgid "http://www.google.com/ig/api?hl=en&weather=%s";
+msgstr "http://www.google.com/ig/api?hl=fr&weather=%s";
+
+msgid "Location could not be found. Please check the city name or enter 
another close by location."
+msgstr "La localité ne peut être trouvée. Veuillez vérifier le nom de la ville 
ou choisir un endroit proche de celle-ci"

Added: 
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/nl.po
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/nl.po  
                        (rev 0)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/resourcesTest/nl.po  
2009-02-22 15:19:42 UTC (rev 3727)
@@ -0,0 +1,35 @@
+msgid "Weather Gadget"
+msgstr "Weer Gadget"
+
+msgid "Weather Gadget"
+msgstr "Weer Gadget"
+
+msgid "Google Weather Gadget"
+msgstr "Google Weer Gadget"
+
+msgid "Weather location"
+msgstr "Locatie"
+
+msgid "Temperature unit"
+msgstr "Temperatuur eenheid"
+
+msgid "Give tomorrow's weather too"
+msgstr "Geef ook de weersverwachtingen"
+
+msgid "Check the weather"
+msgstr "Het weer opvragen"
+
+msgid "Current weather at {0} is \"{1}\" with a temperature of {2} degrees 
{3}; Humidity level is {4} percent."
+msgstr "Het weer vandaag in {0} is \"{1}\" met een temperatuur van {2} graden 
{3}. De vochtigheidsgraad is {4} percent."
+
+msgid "Current weather at {0} is \"unknown\" with a temperature of {1} degrees 
{2}; Humidity level is {3} percent."
+msgstr "Het weer vandaag in {0} is \"onbekend\" met een temperatuur van {2} 
graden {3}. De vochtigheidsgraad is {4} percent."
+
+msgid "Tomorrow's forecast. \"{0}\" temperatures from {1} to {2} degrees."
+msgstr "De weersverwachtingen voor morgen : \"{0}\" met temperaturen van {1} 
tot {2} graden."
+
+msgid "http://www.google.com/ig/api?hl=en&weather=%s";
+msgstr "http://www.google.com/ig/api?hl=nl&weather=%s";
+
+msgid "Location could not be found. Please check the city name or enter 
another close by location."
+msgstr "Locatie werd niet gevonden. Gelieve de ingegeven stadsnaam te 
controleren of een andere nabij gelegen stad in te geven."


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to