Author: jerome
Date: 2009-02-22 16:24:41 +0100 (Sun, 22 Feb 2009)
New Revision: 3729
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.project
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/es.po
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/fr.po
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/nl.po
Log:
* Updated project on svn.
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.classpath
2009-02-22 15:24:41 UTC (rev 3729)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.project
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.project
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/.project
2009-02-22 15:24:41 UTC (rev 3729)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>tuxdroid-i18n-lib</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/I18NTests.java
2009-02-22 15:24:41 UTC (rev 3729)
@@ -0,0 +1,58 @@
+/* This file is part of "TuxDroid I18N library".
+ * Copyright 2008, kysoh
+ * Author : Conan Jerome
+ * eMail : jerome.conan AT kysoh.com
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid I18N library" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid I18N" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Control Center"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+import com.tuxdroid.I18N.I18N;
+import com.tuxdroid.I18N.error.I18NFileNotFoundException;
+
+public class I18NTests {
+
+ /**
+ * Main tests of the I18N object.
+ * @param args
+ */
+ public static void main(String[] args)
+ {
+ if((args.length > 0) &&
(args[0].toString().equalsIgnoreCase("--files")))
+ {
+ //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."));
+ }
+ }
+ else
+ {
+ //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."));
+ }
+ }
+}
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
2009-02-22 15:24:41 UTC (rev 3729)
@@ -0,0 +1,260 @@
+/* This file is part of "TuxDroid I18N library".
+ * Copyright 2008, kysoh
+ * Author : Conan Jerome
+ * eMail : jerome.conan AT kysoh.com
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid I18N library" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid I18N" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Control Center"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.tuxdroid.I18N;
+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;
+
+import com.tuxdroid.I18N.error.I18NFileNotFoundException;
+
+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.
+ * @param poPath : The path where po files can be found.
+ * @throws I18NFileNotFoundException
+ */
+ public I18N(String poPath, String language) throws
I18NFileNotFoundException
+ {
+ this.createObject(poPath, language);
+ }
+
+
+ /**
+ * 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
+ * @throws I18NFileNotFoundException
+ */
+ private void createObject(String fileName, String language) throws
I18NFileNotFoundException
+ {
+ this.poPath = new File(fileName);
+ this.language = language;
+ //If specified po path doasn't exists, then throw po file not
found error.
+ if(!this.poPath.exists())
+ {
+ throw new
I18NFileNotFoundException(this.poPath.getName());
+ }
+
+ //File exists then, parsing po files.
+ else
+ {
+ this.parseFiles();
+ }
+ }
+
+
+
+ /**
+ * 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.
+ */
+ public String getString(String aString)
+ {
+ if((this.language != null) &&(this.strings.size() > 0))
+ {
+ //then getting string value.
+ if(this.strings.containsKey(aString))
+ {
+ return this.strings.get(aString);
+ }
+ }
+ return aString;
+ }
+
+
+ /**
+ * Reload po files.
+ * @throws I18NFileNotFoundException
+ */
+ public void reload() throws I18NFileNotFoundException
+ {
+ this.parseFiles();
+ }
+
+
+ /**
+ * Parse po files taking the correct po file.
+ * @throws I18NFileNotFoundException
+ */
+ private void parseFiles() throws I18NFileNotFoundException
+ {
+
+ File finalFile = null;
+
+ if(this.language == null)
+ {
+ throw new
I18NFileNotFoundException(this.poPath.getName());
+ }
+
+ File files[] = this.poPath.listFiles();
+ for(File file : files)
+ {
+ String path = file.getAbsolutePath();
+ if(path.endsWith(".po"))
+ {
+ String suff = path.substring(0,
path.indexOf(".po"));
+ suff = suff.substring(suff.length() - 2);
+
+ if(suff.equalsIgnoreCase(this.language))
+ {
+ finalFile = file;
+ }
+ }
+ }
+
+ if(finalFile == null)
+ {
+ //Always return aString in case of getString call.
+ return;
+ }
+
+ //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
+ {
+ InputStreamReader ipsr = new InputStreamReader(ips);
+ BufferedReader br=new BufferedReader(ipsr);
+ String ligne;
+ String msgid = null;
+ String msgstr = null;
+
+ while ((ligne=br.readLine())!=null)
+ {
+ //Encoding to utf-8
+ ligne = new String(ligne.getBytes(), "UTF-8");
+ try
+ {
+ if(ligne.substring(0,
5).equalsIgnoreCase("msgid"))
+ {
+ msgid = ligne;
+ }
+
+ ligne = br.readLine();
+ if(ligne != null)
+ {
+ ligne = new
String(ligne.getBytes(), "UTF-8");
+ if(ligne.substring(0,
6).equalsIgnoreCase("msgstr"))
+ {
+ msgstr = ligne;
+ if((msgid != null) &&
(msgstr != null))
+ {
+ //Adding into
the hashtable.
+ msgid =
msgid.substring(msgid.indexOf("\"") + 1, msgid.lastIndexOf("\""));
+ msgstr =
msgstr.substring(msgstr.indexOf("\"") + 1, msgstr.lastIndexOf("\""));
+
this.strings.put(msgid.replaceAll("\\\\\"", "\""), msgstr.replaceAll("\\\\\"",
"\""));
+ }
+ }
+ else
+ {
+ msgid = null;
+ msgstr = null;
+ }
+ }
+ else
+ {
+ msgid = null;
+ msgstr = null;
+ }
+ }
+ catch(StringIndexOutOfBoundsException e)
+ {
+ ;
+ }
+ }
+ br.close();
+ }
+ catch(Exception e)
+ {
+ ;
+ }
+ }
+}
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
2009-02-22 15:24:41 UTC (rev 3729)
@@ -0,0 +1,56 @@
+/* This file is part of "TuxDroid I18N library".
+ * Copyright 2008, kysoh
+ * Author : Conan Jerome
+ * eMail : jerome.conan AT kysoh.com
+ * Site : http://www.kysoh.com/
+ *
+ * "TuxDroid I18N library" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid I18N" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Control Center"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.tuxdroid.I18N.error;
+
+public class I18NFileNotFoundException extends Exception{
+
+ private static final long serialVersionUID = 1L;
+ private String fileName;
+
+ /**
+ * Handle po files not found/doesn't exists exception.
+ * @param fileName : The file name that doesn't exists.
+ */
+ public I18NFileNotFoundException(String fileName)
+ {
+ this.fileName = fileName;
+ }
+
+
+ /**
+ * Return the localized message.
+ */
+ public String getLocalizedMessage()
+ {
+ return String.format("Cannot found specified file: %s",
this.fileName);
+ }
+
+
+ /**
+ * Return the localized message.
+ */
+ public String getMessage()
+ {
+ return this.getLocalizedMessage();
+ }
+}
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/es.po
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/es.po
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/es.po
2009-02-22 15:24:41 UTC (rev 3729)
@@ -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/trunk/tuxdroid-i18n-lib/src/resourcesTest/fr.po
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/fr.po
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/fr.po
2009-02-22 15:24:41 UTC (rev 3729)
@@ -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/trunk/tuxdroid-i18n-lib/src/resourcesTest/nl.po
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/nl.po
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/trunk/tuxdroid-i18n-lib/src/resourcesTest/nl.po
2009-02-22 15:24:41 UTC (rev 3729)
@@ -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