All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.i18n.I18n Maven / Gradle / Ivy

There is a newer version: 4.0-beta-27
Show newest version
package org.nuiton.i18n;

/*-
 * #%L
 * I18n :: Runtime
 * %%
 * Copyright (C) 2018 Code Lutin, Ultreia.io
 * %%
 * 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
 * .
 * #L%
 */

import io.ultreia.java4all.i18n.runtime.I18nLanguage;
import io.ultreia.java4all.i18n.runtime.format.I18nMessageFormatter;

import java.util.Locale;

/**
 * New generation I18n class.
 * 

* Note: This class replace the previous one in project {@code * nuiton-utils}. *

* This class is a facility for internationalization. To use it in your soft, * you can either :

  • import the org.nuiton.i18n.I18n class,
  • init * the translation support with the init(String language) or init(String * language, String country), init(Localelocale) static methods in your main, ( * eg: I18n.init("fr","FR") )
  • call the translate static method for each * sentence, ( eg: I18n.l("hello you !") )
  • create a resource file for each * language following the naming convention given in the * java.util.ResourceBundle javadoc and translate all the sentence.
* * @author Tony Chemit - [email protected] * @since 1.1 * @deprecated since 4.0, use now {@link io.ultreia.java4all.i18n.I18n} */ @Deprecated public class I18n extends io.ultreia.java4all.i18n.I18n { /** * Change le filtre des chaines traduites * * @param filter l'objet filtre a utiliser */ public static void setFilter(I18nFilter filter) { io.ultreia.java4all.i18n.I18n.setFilter(filter); } public static void reload() { io.ultreia.java4all.i18n.I18n.reload(); } /** * Obtain the default locale setted in I18n. This very locale is used in * translation when no locale information is given * (says in method {@link I18n#t(String, Object...)}. *

* Note : The I18n system must have been initialized by one of the * {@code init} method. * * @return the default locale initialized in I18n */ public static Locale getDefaultLocale() { return io.ultreia.java4all.i18n.I18n.getDefaultLocale(); } /** * Sets the default locale used by I18n for the method * {@link I18n#t(String, Object...)}. * *

* As a side effect, it will also set this locale is the default locale in * the system (says the method {@link Locale#getDefault()} will return the * given locale). *

* Note : The I18n system must have been initialized by one of the * {@code init} method. * * @param locale the new default locale. * @since 2.1 */ public static void setDefaultLocale(Locale locale) { io.ultreia.java4all.i18n.I18n.setDefaultLocale(locale); } /** * Look into the default {@link I18nLanguage} if the given {@code message} * can be found. * * @param message the message to check presence * @return true/false whether the message is present in the default language * @see #getDefaultLocale() * @see #hasKey(Locale, String) * @since 2.4.1 */ public static boolean hasKey(String message) { return io.ultreia.java4all.i18n.I18n.hasKey(message); } /** * Look into the {@link I18nLanguage} associated to the {@code locale} if * the given {@code message} can be found. * * @param locale the locale to be used to get the I18nLanguage * @param message the message to check presence * @return true/false whether the message is present for the given locale * @since 2.4.1 */ public static boolean hasKey(Locale locale, String message) { return io.ultreia.java4all.i18n.I18n.hasKey(locale, message); } /** * Retourne la chaine traduite si possible dans la locale demandée. * * @param locale la locale dans lequel on souhaite la traduction * @param message message formate avec {@link I18nMessageFormatter} * @param args les parametres pour le message. * @return la traduction si possible ou la chaine passee en parametre * sinon. * @since 2.1 */ public static String l(Locale locale, String message, Object... args) { return io.ultreia.java4all.i18n.I18n.l(locale, message, args); } /** * Retourne la chaine traduite si possible. * * @param message message formate avec {@link I18nMessageFormatter} * @param args les parametres pour le message. * @return la traduction si possible ou la chaine passee en parametre * sinon. */ public static String t(String message, Object... args) { return io.ultreia.java4all.i18n.I18n.t(message, args); } /** * Retourne la chaine passée en argument. *

* Utile surtout pour collecter les chaines et ne pas les traduires à leur * apparition. *

* Par exemple : *

String key = "nuitonutils.key";
     * String result = l(key)
* fonctionnera, mais la chaine n'aura pas été marquée comme devant être * internationalisé. *

* Tres utile par exemple, pour crée des objets non internationnalisé, et * devant être traduit seulement à leur lecture suivant la locale du lecteur * et non du créateur. * * @param message message formate avec {@link I18nMessageFormatter} * @param args les parametres pour le message. * @return le message passe en argument mais formatté avec les parametres */ public static String n(String message, Object... args) { return io.ultreia.java4all.i18n.I18n.n(message, args); } /** * Close i18n caches, says the store if exists. *

* This method should be called to reset all caches (languages, * bundles,...) */ public static void close() { io.ultreia.java4all.i18n.I18n.close(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy