Author: jerome
Date: 2009-02-22 14:37:51 +0100 (Sun, 22 Feb 2009)
New Revision: 3726
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/.classpath
software_suite_v2/libraries/java/tuxdroid-i18n-lib/.project
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/
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/error/
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
Log:
* Added I18N lib project.
Added: software_suite_v2/libraries/java/tuxdroid-i18n-lib/.classpath
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/.classpath
(rev 0)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/.classpath
2009-02-22 13:37:51 UTC (rev 3726)
@@ -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/.project
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/.project
(rev 0)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/.project 2009-02-22
13:37:51 UTC (rev 3726)
@@ -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/src/I18NTests.java
===================================================================
--- software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java
(rev 0)
+++ software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/I18NTests.java
2009-02-22 13:37:51 UTC (rev 3726)
@@ -0,0 +1,45 @@
+/* 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)
+ {
+ try
+ {
+ 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."));
+
+ }
+ catch (I18NFileNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
Added:
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
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/I18N.java
2009-02-22 13:37:51 UTC (rev 3726)
@@ -0,0 +1,199 @@
+/* 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.InputStream;
+import java.io.InputStreamReader;
+import java.util.Hashtable;
+
+import com.tuxdroid.I18N.error.I18NFileNotFoundException;
+
+public class I18N {
+
+ private File poPath;
+ private String language;
+ private Hashtable<String, String> strings = new Hashtable<String,
String>();
+
+ /**
+ * 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 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();
+ }
+ }
+
+
+ /**
+ * 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).toString();
+ }
+ }
+ 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);
+ 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)
+ {
+ e.printStackTrace();
+ }
+ }
+}
Added:
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
===================================================================
---
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
(rev 0)
+++
software_suite_v2/libraries/java/tuxdroid-i18n-lib/src/com/tuxdroid/I18N/error/I18NFileNotFoundException.java
2009-02-22 13:37:51 UTC (rev 3726)
@@ -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();
+ }
+}
------------------------------------------------------------------------------
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