This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository i18n. See https://gitlab.nuiton.org/nuiton/i18n.git commit 8bd101423fcea828fd84d04aa84c6a06c5aa9108 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Sep 2 14:16:25 2016 +0200 Add doc (See #4010) --- i18n-maven-plugin/src/site/apt/usages.apt | 83 ++++++++++++++++++++++++++++ i18n-maven-plugin/src/site/en/apt/usages.apt | 83 ++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) diff --git a/i18n-maven-plugin/src/site/apt/usages.apt b/i18n-maven-plugin/src/site/apt/usages.apt index c8b4518..49c7073 100644 --- a/i18n-maven-plugin/src/site/apt/usages.apt +++ b/i18n-maven-plugin/src/site/apt/usages.apt @@ -266,5 +266,88 @@ And there is more for you! There is some other interesting properties in the plugin, for example it is possible to translate the new i18n key detected while parsing via a swing ui. +* Generate I18n keys for enumerations (since 3.6) + + You can generate a java file, with i18n keys based on some enumerations constants. + + To do this, you need to describe how to generate i18n keys from you enumeration. + + The following example explains how to do this: + +----------------------------------------------------------------------------- +<plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>generateI18nEnumHelper</goal> + </goals> + <configuration> + <enumerationSets> + <enumerationSet> + <name>label</name> <!-- property to generate methods to translate your keys --> + <pattern>observe.enum.@CLASS_NAME@.@NAME@</pattern> <!-- How to generate your keys (available tokens are CLASS_NAME, SIMPLE_CLASS_NAME, NAME and ORDINAL)--> + <enums> + <enum>fr.ird.observe.services.dto.constants.GearType</enum> + <enum>fr.ird.observe.application.swing.configuration.constants.CreationMode</enum> + </enums> + </enumerationSet> + <enumerationSet> + <name>description</name> + <pattern>observe.enum.@CLASS_NAME@.@NAME@.description</pattern> + <enums> + <enum>fr.ird.observe.application.swing.configuration.constants.CreationMode</enum> + <enum>fr.ird.observe.application.swing.configuration.constants.DbMode</enum> + </enums> + </enumerationSet> + </enumerationSets> + </configuration> + </execution> + </executions> +</plugin> +----------------------------------------------------------------------------- + + will generate: + +----------------------------------------------------------------------------- +public class I18nEnumHelper { + + public static <E extends Enum<E>> String getLabel(E e) { + return t(getLabelKey(e)); + } + + public static <E extends Enum<E>> String getLabel(Locale locale, E e) { + return l(locale, getLabelKey(e)); + } + + protected static <E extends Enum<E>> String getLabelKey(E e) { + return "observe.enum." + e.getClass().getName() + "." + e.name(); + } + + public static <E extends Enum<E>> String getDescription(E e) { + return t(getDescriptionKey(e)); + } + + public static <E extends Enum<E>> String getDescription(Locale locale, E e) { + return l(locale, getDescriptionKey(e)); + } + + protected static <E extends Enum<E>> String getDescriptionKey(E e) { + return "observe.enum." + e.getClass().getName() + "." + e.name() + ".description"; + } + + static { + + n("observe.enum.fr.ird.observe.services.dto.constants.GearType.longline"); + n("observe.enum.fr.ird.observe.services.dto.constants.GearType.seine"); + n("fr.ird.observe.application.swing.configuration.constants.CreationMode.no"); + n("fr.ird.observe.application.swing.configuration.constants.CreationMode.no.description"); + ... + + } +} +----------------------------------------------------------------------------- + To see all the features of the plugin, consult the {{{./plugin-info.html}goals details}} page. diff --git a/i18n-maven-plugin/src/site/en/apt/usages.apt b/i18n-maven-plugin/src/site/en/apt/usages.apt index a39612d..a4e0912 100644 --- a/i18n-maven-plugin/src/site/en/apt/usages.apt +++ b/i18n-maven-plugin/src/site/en/apt/usages.apt @@ -236,5 +236,88 @@ And there is more for you! There is some other interesting properties in the plugin, for example it is possible to translate the new i18n key detected while parsing via a swing ui. +* Generate I18n keys for enumerations (since 3.6) + + You can generate a java file, with i18n keys based on some enumerations constants. + + To do this, you need to describe how to generate i18n keys from you enumeration. + + The following example explains how to do this: + +----------------------------------------------------------------------------- +<plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>generateI18nEnumHelper</goal> + </goals> + <configuration> + <enumerationSets> + <enumerationSet> + <name>label</name> <!-- property to generate methods to translate your keys --> + <pattern>observe.enum.@CLASS_NAME@.@NAME@</pattern> <!-- How to generate your keys (available tokens are CLASS_NAME, SIMPLE_CLASS_NAME, NAME and ORDINAL)--> + <enums> + <enum>fr.ird.observe.services.dto.constants.GearType</enum> + <enum>fr.ird.observe.application.swing.configuration.constants.CreationMode</enum> + </enums> + </enumerationSet> + <enumerationSet> + <name>description</name> + <pattern>observe.enum.@CLASS_NAME@.@NAME@.description</pattern> + <enums> + <enum>fr.ird.observe.application.swing.configuration.constants.CreationMode</enum> + <enum>fr.ird.observe.application.swing.configuration.constants.DbMode</enum> + </enums> + </enumerationSet> + </enumerationSets> + </configuration> + </execution> + </executions> +</plugin> +----------------------------------------------------------------------------- + +Will generate: + +----------------------------------------------------------------------------- +public class I18nEnumHelper { + + public static <E extends Enum<E>> String getLabel(E e) { + return t(getLabelKey(e)); + } + + public static <E extends Enum<E>> String getLabel(Locale locale, E e) { + return l(locale, getLabelKey(e)); + } + + protected static <E extends Enum<E>> String getLabelKey(E e) { + return "observe.enum." + e.getClass().getName() + "." + e.name(); + } + + public static <E extends Enum<E>> String getDescription(E e) { + return t(getDescriptionKey(e)); + } + + public static <E extends Enum<E>> String getDescription(Locale locale, E e) { + return l(locale, getDescriptionKey(e)); + } + + protected static <E extends Enum<E>> String getDescriptionKey(E e) { + return "observe.enum." + e.getClass().getName() + "." + e.name() + ".description"; + } + + static { + + n("observe.enum.fr.ird.observe.services.dto.constants.GearType.longline"); + n("observe.enum.fr.ird.observe.services.dto.constants.GearType.seine"); + n("fr.ird.observe.application.swing.configuration.constants.CreationMode.no"); + n("fr.ird.observe.application.swing.configuration.constants.CreationMode.no.description"); + ... + + } +} +----------------------------------------------------------------------------- + To see all the features of the plugin, consult the {{{./plugin-info.html}goals details}} page. -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.