[Lutinutil-commits] r1293 - in lutinutil/tags: . lutinutil-1.0.1 lutinutil-1.0.1/src/main/java/org/codelutin/i18n
Author: chatellier Date: 2008-12-22 09:16:38 +0000 (Mon, 22 Dec 2008) New Revision: 1293 Added: lutinutil/tags/lutinutil-1.0.1/ lutinutil/tags/lutinutil-1.0.1/pom.xml lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/I18nf.java lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java Removed: lutinutil/tags/lutinutil-1.0.1/pom.xml lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java Log: [maven-release-plugin] copy for tag lutinutil-1.0.1 Copied: lutinutil/tags/lutinutil-1.0.1 (from rev 1287, lutinutil/trunk) Deleted: lutinutil/tags/lutinutil-1.0.1/pom.xml =================================================================== --- lutinutil/trunk/pom.xml 2008-12-15 02:11:01 UTC (rev 1287) +++ lutinutil/tags/lutinutil-1.0.1/pom.xml 2008-12-22 09:16:38 UTC (rev 1293) @@ -1,115 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - - <parent> - <groupId>org.codelutin</groupId> - <artifactId>lutinproject</artifactId> - <version>3.2</version> - </parent> - - <artifactId>lutinutil</artifactId> - - <version>1.1-SNAPSHOT</version> - - <dependencies> - - <dependency> - <groupId>log4j</groupId> - <artifactId>log4j</artifactId> - <version>1.2.14</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>commons-primitives</groupId> - <artifactId>commons-primitives</artifactId> - <version>1.0</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>commons-collections</groupId> - <artifactId>commons-collections</artifactId> - <version>3.2.1</version> - <scope>compile</scope> - </dependency> - - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.8.0</version> - <scope>compile</scope> - </dependency> - - </dependencies> - - - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>Lutin utilities library</name> - <description>Library of usefull class to be used in any project.</description> - <inceptionYear>2004</inceptionYear> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - - <packaging>jar</packaging> - - <properties> - - <labs.id>12</labs.id> - - <labs.project>lutinutil</labs.project> - - <!-- TODO remove this as soon as tests are fixed on hudson... --> - <maven.test.testFailureIgnore>true</maven.test.testFailureIgnore> - </properties> - - <build> - - <plugins> - - <!-- i18n --> - <plugin> - <groupId>org.codelutin</groupId> - <artifactId>maven-i18n-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> - </plugin> - - <!-- javadoc --> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - </plugin> - - </plugins> - </build> - - - <!-- ************************************************************* --> - <!-- *** Build Environment ************************************** --> - <!-- ************************************************************* --> - - <!--Source control management--> - <scm> - <connection>${maven.scm.connection}</connection> - <developerConnection>${maven.scm.developerConnection}</developerConnection> - <url>${maven.scm.url}</url> - </scm> - -</project> Copied: lutinutil/tags/lutinutil-1.0.1/pom.xml (from rev 1292, lutinutil/trunk/pom.xml) =================================================================== --- lutinutil/tags/lutinutil-1.0.1/pom.xml (rev 0) +++ lutinutil/tags/lutinutil-1.0.1/pom.xml 2008-12-22 09:16:38 UTC (rev 1293) @@ -0,0 +1,115 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <!-- ************************************************************* --> + <!-- *** POM Relationships *************************************** --> + <!-- ************************************************************* --> + + <parent> + <groupId>org.codelutin</groupId> + <artifactId>lutinproject</artifactId> + <version>3.2</version> + </parent> + + <artifactId>lutinutil</artifactId> + + <version>1.0.1</version> + + <dependencies> + + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <version>1.2.14</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-primitives</groupId> + <artifactId>commons-primitives</artifactId> + <version>1.0</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2.1</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>commons-beanutils</groupId> + <artifactId>commons-beanutils</artifactId> + <version>1.8.0</version> + <scope>compile</scope> + </dependency> + + </dependencies> + + + <!-- ************************************************************* --> + <!-- *** Project Information ************************************* --> + <!-- ************************************************************* --> + + <name>Lutin utilities library</name> + <description>Library of usefull class to be used in any project.</description> + <inceptionYear>2004</inceptionYear> + + <!-- ************************************************************* --> + <!-- *** Build Settings ****************************************** --> + <!-- ************************************************************* --> + + <packaging>jar</packaging> + + <properties> + + <labs.id>12</labs.id> + + <labs.project>lutinutil</labs.project> + + <!-- TODO remove this as soon as tests are fixed on hudson... --> + <maven.test.testFailureIgnore>true</maven.test.testFailureIgnore> + </properties> + + <build> + + <plugins> + + <!-- i18n --> + <plugin> + <groupId>org.codelutin</groupId> + <artifactId>maven-i18n-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>gen</goal> + </goals> + </execution> + </executions> + </plugin> + + <!-- javadoc --> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + </plugin> + + </plugins> + </build> + + + <!-- ************************************************************* --> + <!-- *** Build Environment ************************************** --> + <!-- ************************************************************* --> + + <!--Source control management--> + <scm> + <connection>scm:svn:svn://anonymous@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.1</connection> + <developerConnection>scm:svn:svn+ssh://chatellier@labs.libre-entreprise.org/svnroot/lutinutil/lutinutil/tags/lutinutil-1.0.1</developerConnection> + <url>http://labs.libre-entreprise.org/plugins/scmsvn/viewcvs.php/lutinutil/tags/lutinutil-1.0.1?root=lutinutil</url> + </scm> + +</project> Copied: lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/I18nf.java (from rev 1290, lutinutil/trunk/src/main/java/org/codelutin/i18n/I18nf.java) =================================================================== --- lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/I18nf.java (rev 0) +++ lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/I18nf.java 2008-12-22 09:16:38 UTC (rev 1293) @@ -0,0 +1,34 @@ +/* *##% Lutin utilities library + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +package org.codelutin.i18n; + +/** + * Transition class during project switch between MessageFormat.format syntax + * to String.format syntax. + * + * @author poussin + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + * + * @deprecated Use I18n class instead. + */ +public class I18nf extends I18n { + +} \ No newline at end of file Deleted: lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java =================================================================== --- lutinutil/trunk/src/main/java/org/codelutin/i18n/Language.java 2008-12-15 02:11:01 UTC (rev 1287) +++ lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java 2008-12-22 09:16:38 UTC (rev 1293) @@ -1,205 +0,0 @@ -/* *##% Lutin utilities library - * Copyright (C) 2004 - 2008 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ - -/** - * Language.java - */ - -package org.codelutin.i18n; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.codelutin.i18n.bundle.I18nBundleManager; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URLClassLoader; -import java.util.Enumeration; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.Properties; - -/** - * This class is used by the i18n class. It encapsulates the translation - * resource for a given language. - * <p/> - * Encoding to be used to read properties files will be ISO-8859-1 since java does it like this. - */ -public class Language { - - /** to use log facility, just put in your code: log.info(\"...\"); */ - private static final Log log = LogFactory.getLog(Language.class); - - public static URLClassLoader getLoader() { - ClassLoader loader = Language.class.getClassLoader(); - if (loader instanceof URLClassLoader) { - return (URLClassLoader) loader; - } - log.warn("could not find the URLClassLoader : "+loader); - return null; - } - - /** toutes les traductions pour cette langue */ - protected Properties resource; - - /** la locale de la langue */ - protected Locale locale; - - /** @param l the current locale of the language */ - public Language(Locale l) { - this.locale = l; - } - - /** - * charge les traductions de la langue. - * <p/> - * recherche dans un premier temps, les urls des bundles puis les charge. - * - * @param bundleManager the used bundle manager - */ - public void load(I18nBundleManager bundleManager) { - // make sure the bundlemanager is init - bundleManager.init(); - // load resources from bundles - resource = new Properties(); - // get bundles for this locale - try { - bundleManager.load(this, resource); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - /** - * translate takes a sentence and returns its translation if found, the very - * same string otherwise. - * - * @param sentence sentence to translate - * @return translated sentence - */ - public String translate(String sentence) { - if (resource == null) { - recordNotFound(sentence); - return sentence; - } - try { - String result = resource.getProperty(sentence); - if (null != result && !"".equals(result)) { - return result; - } - recordNotFound(sentence); - return sentence; - } catch (MissingResourceException eee) { - log.warn("Resource " + sentence + " unavailable"); - return sentence; - } catch (Exception eee) { - log.error("Unexpected error while translating : " + eee); - return sentence; - } - } - - private void recordNotFound(String key) { - if (I18n.recordFilePath != null && key != null && !"".equals(key)) { - File f = new File(I18n.recordFilePath); - Properties recordProps = new Properties(); - try { - if (f.exists()) { - FileInputStream fis = new FileInputStream(f); - recordProps.load(fis); - fis.close(); - } - recordProps.put(key, ""); - FileOutputStream fos = new FileOutputStream(f); - recordProps.store(fos, "Adding the key : " + key); - fos.close(); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * untranslate takes a translated sentence and returns the original one if - * found, the very same string otherwise. - * - * @param sentence sentence to untranslate - * @return untranslated sentence - */ - public String untranslate(String sentence) { - if (resource == null) { - return sentence; - } - try { - Enumeration<?> e = resource.propertyNames(); - // Look for the given sentence through all translations - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); - String translation = resource.getProperty(key); - // If found returns the corresponding key - if (sentence.equals(translation)) { - return key; - } - } - } catch (MissingResourceException eee) { - // Well, this can't happen... - } - // No such translated sentence in our resourceBundle - return sentence; - } - - public Locale getLocale() { - return locale; - } - - public int size() { - return resource == null ? 0 : resource.size(); - } - - public void close() { - if (resource != null) { - log.info(this); - resource.clear(); - resource = null; - } - } - - @Override - protected void finalize() throws Throwable { - super.finalize(); - close(); - } - - @Override - public boolean equals(Object o) { - return this == o || o instanceof Language && locale.equals(((Language) o).locale); - } - - @Override - public int hashCode() { - return locale.hashCode(); - } - - @Override - public String toString() { - return "Language <locale: " + locale + ",nbStences:" + (size()) + ">"; - } -} Copied: lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java (from rev 1289, lutinutil/trunk/src/main/java/org/codelutin/i18n/Language.java) =================================================================== --- lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java (rev 0) +++ lutinutil/tags/lutinutil-1.0.1/src/main/java/org/codelutin/i18n/Language.java 2008-12-22 09:16:38 UTC (rev 1293) @@ -0,0 +1,206 @@ +/* *##% Lutin utilities library + * Copyright (C) 2004 - 2008 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. ##%* */ + +/** + * Language.java + */ + +package org.codelutin.i18n; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URLClassLoader; +import java.util.Enumeration; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.Properties; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.codelutin.i18n.bundle.I18nBundleManager; +import org.codelutin.util.RecursiveProperties; + +/** + * This class is used by the i18n class. It encapsulates the translation + * resource for a given language. + * <p/> + * Encoding to be used to read properties files will be ISO-8859-1 since java does it like this. + */ +public class Language { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static final Log log = LogFactory.getLog(Language.class); + + public static URLClassLoader getLoader() { + ClassLoader loader = Language.class.getClassLoader(); + if (loader instanceof URLClassLoader) { + return (URLClassLoader) loader; + } + log.warn("could not find the URLClassLoader : "+loader); + return null; + } + + /** toutes les traductions pour cette langue */ + protected Properties resource; + + /** la locale de la langue */ + protected Locale locale; + + /** @param l the current locale of the language */ + public Language(Locale l) { + this.locale = l; + } + + /** + * charge les traductions de la langue. + * <p/> + * recherche dans un premier temps, les urls des bundles puis les charge. + * + * @param bundleManager the used bundle manager + */ + public void load(I18nBundleManager bundleManager) { + // make sure the bundlemanager is init + bundleManager.init(); + // load resources from bundles + resource = new RecursiveProperties(); + // get bundles for this locale + try { + bundleManager.load(this, resource); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + /** + * translate takes a sentence and returns its translation if found, the very + * same string otherwise. + * + * @param sentence sentence to translate + * @return translated sentence + */ + public String translate(String sentence) { + if (resource == null) { + recordNotFound(sentence); + return sentence; + } + try { + String result = resource.getProperty(sentence); + if (null != result && !"".equals(result)) { + return result; + } + recordNotFound(sentence); + return sentence; + } catch (MissingResourceException eee) { + log.warn("Resource " + sentence + " unavailable", eee); + return sentence; + } catch (Exception eee) { + log.error("Unexpected error while translating : ", eee); + return sentence; + } + } + + private void recordNotFound(String key) { + if (I18n.recordFilePath != null && key != null && !"".equals(key)) { + File f = new File(I18n.recordFilePath); + Properties recordProps = new Properties(); + try { + if (f.exists()) { + FileInputStream fis = new FileInputStream(f); + recordProps.load(fis); + fis.close(); + } + recordProps.put(key, ""); + FileOutputStream fos = new FileOutputStream(f); + recordProps.store(fos, "Adding the key : " + key); + fos.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + /** + * untranslate takes a translated sentence and returns the original one if + * found, the very same string otherwise. + * + * @param sentence sentence to untranslate + * @return untranslated sentence + */ + public String untranslate(String sentence) { + if (resource == null) { + return sentence; + } + try { + Enumeration<?> e = resource.propertyNames(); + // Look for the given sentence through all translations + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + String translation = resource.getProperty(key); + // If found returns the corresponding key + if (sentence.equals(translation)) { + return key; + } + } + } catch (MissingResourceException eee) { + // Well, this can't happen... + } + // No such translated sentence in our resourceBundle + return sentence; + } + + public Locale getLocale() { + return locale; + } + + public int size() { + return resource == null ? 0 : resource.size(); + } + + public void close() { + if (resource != null) { + log.info(this); + resource.clear(); + resource = null; + } + } + + @Override + protected void finalize() throws Throwable { + super.finalize(); + close(); + } + + @Override + public boolean equals(Object o) { + return this == o || o instanceof Language && locale.equals(((Language) o).locale); + } + + @Override + public int hashCode() { + return locale.hashCode(); + } + + @Override + public String toString() { + return "Language <locale: " + locale + ",nbStences:" + (size()) + ">"; + } +}
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org