Author: jcouteau Date: 2011-03-24 14:24:18 +0100 (Thu, 24 Mar 2011) New Revision: 1893 Url: http://nuiton.org/repositories/revision/i18n/1893 Log: Update tutorials Added: trunk/src/site/apt/library.apt.vm trunk/src/site/en/apt/library.apt.vm trunk/src/site/resources/application-i18n.tar.gz trunk/src/site/resources/helloworld.tar.gz trunk/src/site/resources/library-i18n.tar.gz Removed: trunk/src/site/apt/library.apt trunk/src/site/en/apt/library.apt Modified: trunk/src/site/apt/application.apt trunk/src/site/apt/helloWorld.apt trunk/src/site/en/apt/application.apt trunk/src/site/en/apt/helloWorld.apt trunk/src/site/resources/application-i18n.zip trunk/src/site/resources/helloworld.zip trunk/src/site/resources/library-i18n.zip Modified: trunk/src/site/apt/application.apt =================================================================== --- trunk/src/site/apt/application.apt 2011-03-24 12:15:20 UTC (rev 1892) +++ trunk/src/site/apt/application.apt 2011-03-24 13:24:18 UTC (rev 1893) @@ -80,5 +80,7 @@ * Sources du tutoriel - {{{./application-i18n.zip}Sources du tutoriel}} + * {{{./application-i18n.zip}Sources du tutoriel (zip)}} + * {{{./application-i18n.tar.gz}Sources du tutoriel (tar.gz)}} + Modified: trunk/src/site/apt/helloWorld.apt =================================================================== --- trunk/src/site/apt/helloWorld.apt 2011-03-24 12:15:20 UTC (rev 1892) +++ trunk/src/site/apt/helloWorld.apt 2011-03-24 13:24:18 UTC (rev 1893) @@ -71,14 +71,14 @@ la ligne ---- -org.nuiton.i18n.I18n.init(Locale.FRANCE); +org.nuiton.i18n.I18n.init(null, Locale.FRANCE); ---- avant le premier appel à la librairie Nuiton I18n. Cela a pour effet de dire - à Nuiton I18n quelle langue utiliser (en l'occurence le français). Il - recherche donc dans le classpath tous les fichiers i18n/????fr_FR et les - charge. + à Nuiton I18n quelle langue utiliser (en l'occurence le français). Comme nous + mettons l'initializer à null, il utilise celui par défaut. Il recherche donc + dans le classpath tous les fichiers i18n/????fr_FR et les charge. Pour tester il suffit de recompiler et de relancer l'application, vous devriez obtenir : @@ -111,6 +111,6 @@ Sources du tutoriel Les sources de ce tutoriel sont téléchargeables - {{{./helloworld.zip}ici}}. Elles sont packagées - avec les librairies nécessaires à la compilation et l'exécution de cet - exemple. + {{{./helloworld.zip}ici (zip)}} ou {{{./helloworld.tar.gz}ici (tar.gz)}}. + Elles sont packagées avec les librairies nécessaires à la compilation et + l'exécution de cet exemple. Deleted: trunk/src/site/apt/library.apt =================================================================== --- trunk/src/site/apt/library.apt 2011-03-24 12:15:20 UTC (rev 1892) +++ trunk/src/site/apt/library.apt 2011-03-24 13:24:18 UTC (rev 1893) @@ -1,206 +0,0 @@ -~~~ -~~ #%L -~~ I18n -~~ -~~ $Id$ -~~ $HeadURL$ -~~ %% -~~ Copyright (C) 2008 - 2010 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>. -~~ #L% -~~~ -Tutoriel de librairie utilisant Nuiton I18n (utilisation de Maven) - -* Pourquoi un tutoriel différent pour une librairie et pour une application -finale ? - - Lorsque l'on crée une application finale, au moment du build, on crée un - bundle regroupant les chaînes de l'application et de ses dépendances afin - d'optimiser le chargement de l'application (on peut ainsi économiser jusqu'à - plusieurs secondes au démarrage). Lorsque l'on crée une librairie, aucun - bundle n'est réalisé, l'utilisation et la configuration de la librairie est - donc plus simple. - -* Le tutoriel - - Dans ce tutoriel nous allons créer une librairie avec une classe unique qui va - juste afficher un message. C'est ce message qui sera traduit. - -* Créons le projet Maven et configurons le plugin Nuiton I18n - - Créons un projet Maven standard. Dans le pom.xml, nous allons configurer le - plugin Maven Nuiton I18n. - -------------------------------------------------------------------------------- -<plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>maven-i18n-plugin</artifactId> - <version>1.2.1</version> - <executions> - <execution> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> -</plugin> -------------------------------------------------------------------------------- - - Dans la configuration du plugin, nous spécifions les goals à effectuer. Le - goal parserJava extrait toutes les chaînes de charactère à traduire du code - java. Le goal gen récupère le fichier de ressources contenant les chaînes déjà - traduites et y ajoute les chaînes extraites par le goal parserJava qui ne sont - pas déjà présentes. Vous pouvez ensuite traduire les chaînes. - - Afin que le plugin fonctionne, il ne faut pas oublier d'ajouter la librairie - Nuiton I18n dans les dépendances. - -------------------------------------------------------------------------------- -<dependency> - <groupId>org.nuiton.i18n</groupId> - <artifactId>nuiton-i18n-api</artifactId> - <version>1.2.1</version> - <scope>compile</scope> -</dependency> -------------------------------------------------------------------------------- - - Comme nous réalisons un import static, il faut configurer le plugin maven de - compilation - -------------------------------------------------------------------------------- -<plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.1</version> - <configuration> - <source>1.6</source> - <target>1.6</target> - <encoding>UTF-8</encoding> - <showDeprecation>true</showDeprecation> - <showWarnings>true</showWarnings> - </configuration> -</plugin> -------------------------------------------------------------------------------- - - Et pour récupérer le plugin et la librairie Nuiton I18n, il ne faut pas - oublier d'ajouter les dépots nuiton. - -------------------------------------------------------------------------------- -<repositories> - - <!-- depot des releases nuiton --> - - <repository> - <id>nuiton.release</id> - <name>NuitonReleaseRepository</name> - <url>http://maven.nuiton.org/release</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - <releases> - <enabled>true</enabled> - <checksumPolicy>warn</checksumPolicy> - </releases> - </repository> - - <!-- depot des snapshots nuiton --> - - <repository> - <id>nuiton.snapshot</id> - <name>NuitonSnapshotRepository</name> - <url>http://maven.nuiton.org/snapshot</url> - <snapshots> - <enabled>true</enabled> - <checksumPolicy>fail</checksumPolicy> - </snapshots> - <releases> - <enabled>false</enabled> - </releases> - </repository> - -</repositories> - -<pluginRepositories> - - <!-- depot des releases nuiton --> - - <pluginRepository> - - <id>nuiton.release</id> - <name>NuitonReleaseRepository</name> - <url>http://maven.nuiton.org/release</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - <releases> - <enabled>true</enabled> - <checksumPolicy>warn</checksumPolicy> - </releases> - </pluginRepository> - - <!-- depot des snapshots nuiton --> - - <pluginRepository> - <id>nuiton.snapshot</id> - <name>NuitonSnapshotRepository</name> - <url>http://maven.nuiton.org/snapshot</url> - <snapshots> - <enabled>true</enabled> - <checksumPolicy>fail</checksumPolicy> - </snapshots> - <releases> - <enabled>false</enabled> - </releases> - </pluginRepository> - -</pluginRepositories> -------------------------------------------------------------------------------- - -* Créons notre librairie - - Notre librairie, pour faire simple, ne contiendra qu'une classe et une - méthode statique - -------------------------------------------------------------------------------- -package org.myOrganisation.myLibrary; - -import static org.nuiton.i18n.I18n._; - -public class myLibrary { - - static public void myMethod(){ - System.out.println(_("My message to translate")); - } -} -------------------------------------------------------------------------------- - -* Premier build - - Lorsque vous buildez votre librairie pour la première fois avec la commande - mvn compile, vous devez obtenir la création de deux nouveaux fichiers de - ressource contenant chacun la chaîne à traduire sans traduction. - - Vous pouvez traduire la chaîne de charactère dans les deux langues, vous aurez - alors la traduction disponibles dans vos prochains builds. - -* Second build - - Si vous buildez de nouveau la librairie, puis l'intégrez dans une application - finale utilisant Nuiton I18n, le message sera affiché traduit. - -* Sources du tutoriel - - {{{./library-i18n.zip}Sources du tutoriel}} Copied: trunk/src/site/apt/library.apt.vm (from rev 1892, trunk/src/site/apt/library.apt) =================================================================== --- trunk/src/site/apt/library.apt.vm (rev 0) +++ trunk/src/site/apt/library.apt.vm 2011-03-24 13:24:18 UTC (rev 1893) @@ -0,0 +1,208 @@ +~~~ +~~ #%L +~~ I18n +~~ +~~ $Id$ +~~ $HeadURL$ +~~ %% +~~ Copyright (C) 2008 - 2010 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>. +~~ #L% +~~~ +Tutoriel de librairie utilisant Nuiton I18n (utilisation de Maven) + +* Pourquoi un tutoriel différent pour une librairie et pour une application +finale ? + + Lorsque l'on crée une application finale, au moment du build, on crée un + bundle regroupant les chaînes de l'application et de ses dépendances afin + d'optimiser le chargement de l'application (on peut ainsi économiser jusqu'à + plusieurs secondes au démarrage). Lorsque l'on crée une librairie, aucun + bundle n'est réalisé, l'utilisation et la configuration de la librairie est + donc plus simple. + +* Le tutoriel + + Dans ce tutoriel nous allons créer une librairie avec une classe unique qui va + juste afficher un message. C'est ce message qui sera traduit. + +* Créons le projet Maven et configurons le plugin Nuiton I18n + + Créons un projet Maven standard. Dans le pom.xml, nous allons configurer le + plugin Maven Nuiton I18n. + +------------------------------------------------------------------------------- +<plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>maven-i18n-plugin</artifactId> + <version>${projet.version}</version> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>gen</goal> + </goals> + </execution> + </executions> +</plugin> +------------------------------------------------------------------------------- + + Dans la configuration du plugin, nous spécifions les goals à effectuer. Le + goal parserJava extrait toutes les chaînes de charactère à traduire du code + java. Le goal gen récupère le fichier de ressources contenant les chaînes déjà + traduites et y ajoute les chaînes extraites par le goal parserJava qui ne sont + pas déjà présentes. Vous pouvez ensuite traduire les chaînes. + + Afin que le plugin fonctionne, il ne faut pas oublier d'ajouter la librairie + Nuiton I18n dans les dépendances. + +------------------------------------------------------------------------------- +<dependency> + <groupId>org.nuiton.i18n</groupId> + <artifactId>nuiton-i18n-api</artifactId> + <version>${projet.version}</version> + <scope>compile</scope> +</dependency> +------------------------------------------------------------------------------- + + Comme nous réalisons un import static, il faut configurer le plugin maven de + compilation + +------------------------------------------------------------------------------- +<plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.1</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + <encoding>UTF-8</encoding> + <showDeprecation>true</showDeprecation> + <showWarnings>true</showWarnings> + </configuration> +</plugin> +------------------------------------------------------------------------------- + + Et pour récupérer le plugin et la librairie Nuiton I18n, il ne faut pas + oublier d'ajouter les dépots nuiton. + +------------------------------------------------------------------------------- +<repositories> + + <!-- depot des releases nuiton --> + + <repository> + <id>nuiton.release</id> + <name>NuitonReleaseRepository</name> + <url>http://maven.nuiton.org/release</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + <checksumPolicy>warn</checksumPolicy> + </releases> + </repository> + + <!-- depot des snapshots nuiton --> + + <repository> + <id>nuiton.snapshot</id> + <name>NuitonSnapshotRepository</name> + <url>http://maven.nuiton.org/snapshot</url> + <snapshots> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </snapshots> + <releases> + <enabled>false</enabled> + </releases> + </repository> + +</repositories> + +<pluginRepositories> + + <!-- depot des releases nuiton --> + + <pluginRepository> + + <id>nuiton.release</id> + <name>NuitonReleaseRepository</name> + <url>http://maven.nuiton.org/release</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + <checksumPolicy>warn</checksumPolicy> + </releases> + </pluginRepository> + + <!-- depot des snapshots nuiton --> + + <pluginRepository> + <id>nuiton.snapshot</id> + <name>NuitonSnapshotRepository</name> + <url>http://maven.nuiton.org/snapshot</url> + <snapshots> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </snapshots> + <releases> + <enabled>false</enabled> + </releases> + </pluginRepository> + +</pluginRepositories> +------------------------------------------------------------------------------- + +* Créons notre librairie + + Notre librairie, pour faire simple, ne contiendra qu'une classe et une + méthode statique + +------------------------------------------------------------------------------- +package org.myOrganisation.myLibrary; + +import static org.nuiton.i18n.I18n._; + +public class myLibrary { + + static public void myMethod(){ + System.out.println(_("My message to translate")); + } +} +------------------------------------------------------------------------------- + +* Premier build + + Lorsque vous buildez votre librairie pour la première fois avec la commande + mvn compile, vous devez obtenir la création de deux nouveaux fichiers de + ressource contenant chacun la chaîne à traduire sans traduction. + + Vous pouvez traduire la chaîne de charactère dans les deux langues, vous aurez + alors la traduction disponibles dans vos prochains builds. + +* Second build + + Si vous buildez de nouveau la librairie, puis l'intégrez dans une application + finale utilisant Nuiton I18n, le message sera affiché traduit. + +* Sources du tutoriel + + * {{{./library-i18n.zip}Sources du tutoriel (zip)}} + + * {{{./library-i18n.tar.gz}Sources du tutoriel (tar.gz)}} Property changes on: trunk/src/site/apt/library.apt.vm ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/src/site/en/apt/application.apt =================================================================== --- trunk/src/site/en/apt/application.apt 2011-03-24 12:15:20 UTC (rev 1892) +++ trunk/src/site/en/apt/application.apt 2011-03-24 13:24:18 UTC (rev 1893) @@ -77,5 +77,7 @@ * Tutorial sources - {{{../application-i18n.zip}Tutorial sources}} + * {{{../application-i18n.zip}Tutorial sources (zip}} + * {{{../application-i18n.tar.gz}Tutorial sources (tar.gz}} + Modified: trunk/src/site/en/apt/helloWorld.apt =================================================================== --- trunk/src/site/en/apt/helloWorld.apt 2011-03-24 12:15:20 UTC (rev 1892) +++ trunk/src/site/en/apt/helloWorld.apt 2011-03-24 13:24:18 UTC (rev 1893) @@ -69,13 +69,14 @@ not know whiwh language to load. We will then modify our class adding the line ---- -org.nuiton.i18n.I18n.init(Locale.FRANCE); +org.nuiton.i18n.I18n.init(null, Locale.FRANCE); ---- before the first call to Nuiton I18n library. This will tell Nuiton I18n which - language to use (in this case french). Nuiton I18n looks in the classpath - for all the files i18n/?????fr_FR and loads them. + language to use (in this case french). We put null to the initializer, like + that Nuiton I18n looks in the classpath for all the files i18n/?????fr_FR and + loads them. To test, you just need to compile and launch the application again, you should obtain : @@ -105,6 +106,6 @@ Tutorial sources - This tutorial sources can be downloaded {{{../helloworld.zip}here}}. They are - packaged with the libraries needed for the compilation and execution of this - example. + This tutorial sources can be downloaded {{{../helloworld.zip}here (zip)}} or + {{{../helloworld.tar.gz}here (tar.gz)}}. They are packaged with the libraries + needed for the compilation and execution of this example. Deleted: trunk/src/site/en/apt/library.apt =================================================================== --- trunk/src/site/en/apt/library.apt 2011-03-24 12:15:20 UTC (rev 1892) +++ trunk/src/site/en/apt/library.apt 2011-03-24 13:24:18 UTC (rev 1893) @@ -1,204 +0,0 @@ -~~~ -~~ #%L -~~ I18n -~~ -~~ $Id$ -~~ $HeadURL$ -~~ %% -~~ Copyright (C) 2008 - 2010 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>. -~~ #L% -~~~ -Library using Nuiton I18n tutorial (using Maven) - -* Why a different tutorial for a library and a final application ? - - When you create a final application, at build time, we create a bundle - gathering all the strings of the application and its dependencies in order to - optimise the application loading (we can save several seconds this way). When - we create a library, no bundle is created, so the use and configuration of the - library is easier. - -* The tutorial - - In this tutorial, we will create a library with a unique class that will just - display a message. That is this message that will be translated. - -* Create the Maven project and configure the Nuiton I18n plugin - - We create a standard Maven project. In the pom.xml file, we will configure the - Maven Nuiton I18n plugin. - -------------------------------------------------------------------------------- -<plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>maven-i18n-plugin</artifactId> - <version>1.2.1</version> - <executions> - <execution> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> -</plugin> -------------------------------------------------------------------------------- - - In the plugin configuration, we secify the goals to execute. The parserJava - goal extract all the strings to translate from the java code. The gen goal - get the resource file that contains the translated strings and add the - extracted strings that are not already present in it. You can then translate - the strings. - - In order to work, the plugin needs to have the Nuiton I18n liibrary in the - project dependencies. - -------------------------------------------------------------------------------- -<dependency> - <groupId>org.nuiton.i18n</groupId> - <artifactId>nuiton-i18n-api</artifactId> - <version>1.2.1</version> - <scope>compile</scope> -</dependency> -------------------------------------------------------------------------------- - - We make static import in our code, so we need to configure the - maven-compiler-plugin - -------------------------------------------------------------------------------- -<plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.1</version> - <configuration> - <source>1.6</source> - <target>1.6</target> - <encoding>UTF-8</encoding> - <showDeprecation>true</showDeprecation> - <showWarnings>true</showWarnings> - </configuration> -</plugin> -------------------------------------------------------------------------------- - - And in order to get the plugin and library Nuiton I18n, we have to add the - nuiton repositories. - -------------------------------------------------------------------------------- -<repositories> - - <!-- depot des releases nuiton --> - - <repository> - <id>nuiton.release</id> - <name>NuitonReleaseRepository</name> - <url>http://maven.nuiton.org/release</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - <releases> - <enabled>true</enabled> - <checksumPolicy>warn</checksumPolicy> - </releases> - </repository> - - <!-- depot des snapshots nuiton --> - - <repository> - <id>nuiton.snapshot</id> - <name>NuitonSnapshotRepository</name> - <url>http://maven.nuiton.org/snapshot</url> - <snapshots> - <enabled>true</enabled> - <checksumPolicy>fail</checksumPolicy> - </snapshots> - <releases> - <enabled>false</enabled> - </releases> - </repository> - -</repositories> - -<pluginRepositories> - - <!-- depot des releases nuiton --> - - <pluginRepository> - - <id>nuiton.release</id> - <name>NuitonReleaseRepository</name> - <url>http://maven.nuiton.org/release</url> - <snapshots> - <enabled>false</enabled> - </snapshots> - <releases> - <enabled>true</enabled> - <checksumPolicy>warn</checksumPolicy> - </releases> - </pluginRepository> - - <!-- depot des snapshots nuiton --> - - <pluginRepository> - <id>nuiton.snapshot</id> - <name>NuitonSnapshotRepository</name> - <url>http://maven.nuiton.org/snapshot</url> - <snapshots> - <enabled>true</enabled> - <checksumPolicy>fail</checksumPolicy> - </snapshots> - <releases> - <enabled>false</enabled> - </releases> - </pluginRepository> - -</pluginRepositories> -------------------------------------------------------------------------------- - -* Crate our library - - Our library, to make it simple, will contain only one class and a static - method. - -------------------------------------------------------------------------------- -package org.myOrganisation.myLibrary; - -import static org.nuiton.i18n.I18n._; - -public class myLibrary { - - static public void myMethod(){ - System.out.println(_("My message to translate")); - } -} -------------------------------------------------------------------------------- - -* First build - - When you build your library for the first time with the command mvn compile, - you should see two new resource files containing each one a string to - translate without translation. - - You can now translate the string in both language, you will then have the - translation available for your next builds. - -* Second build - - If you build the library again, then integrate it in a final application using - I18n, the message will be displayed translated. - -* Tutorial sources - - {{{../library-i18n.zip}Tutorial sources}} Copied: trunk/src/site/en/apt/library.apt.vm (from rev 1892, trunk/src/site/en/apt/library.apt) =================================================================== --- trunk/src/site/en/apt/library.apt.vm (rev 0) +++ trunk/src/site/en/apt/library.apt.vm 2011-03-24 13:24:18 UTC (rev 1893) @@ -0,0 +1,206 @@ +~~~ +~~ #%L +~~ I18n +~~ +~~ $Id$ +~~ $HeadURL$ +~~ %% +~~ Copyright (C) 2008 - 2010 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>. +~~ #L% +~~~ +Library using Nuiton I18n tutorial (using Maven) + +* Why a different tutorial for a library and a final application ? + + When you create a final application, at build time, we create a bundle + gathering all the strings of the application and its dependencies in order to + optimise the application loading (we can save several seconds this way). When + we create a library, no bundle is created, so the use and configuration of the + library is easier. + +* The tutorial + + In this tutorial, we will create a library with a unique class that will just + display a message. That is this message that will be translated. + +* Create the Maven project and configure the Nuiton I18n plugin + + We create a standard Maven project. In the pom.xml file, we will configure the + Maven Nuiton I18n plugin. + +------------------------------------------------------------------------------- +<plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>maven-i18n-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>gen</goal> + </goals> + </execution> + </executions> +</plugin> +------------------------------------------------------------------------------- + + In the plugin configuration, we secify the goals to execute. The parserJava + goal extract all the strings to translate from the java code. The gen goal + get the resource file that contains the translated strings and add the + extracted strings that are not already present in it. You can then translate + the strings. + + In order to work, the plugin needs to have the Nuiton I18n liibrary in the + project dependencies. + +------------------------------------------------------------------------------- +<dependency> + <groupId>org.nuiton.i18n</groupId> + <artifactId>nuiton-i18n-api</artifactId> + <version>${project.version}</version> + <scope>compile</scope> +</dependency> +------------------------------------------------------------------------------- + + We make static import in our code, so we need to configure the + maven-compiler-plugin + +------------------------------------------------------------------------------- +<plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.1</version> + <configuration> + <source>1.6</source> + <target>1.6</target> + <encoding>UTF-8</encoding> + <showDeprecation>true</showDeprecation> + <showWarnings>true</showWarnings> + </configuration> +</plugin> +------------------------------------------------------------------------------- + + And in order to get the plugin and library Nuiton I18n, we have to add the + nuiton repositories. + +------------------------------------------------------------------------------- +<repositories> + + <!-- depot des releases nuiton --> + + <repository> + <id>nuiton.release</id> + <name>NuitonReleaseRepository</name> + <url>http://maven.nuiton.org/release</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + <checksumPolicy>warn</checksumPolicy> + </releases> + </repository> + + <!-- depot des snapshots nuiton --> + + <repository> + <id>nuiton.snapshot</id> + <name>NuitonSnapshotRepository</name> + <url>http://maven.nuiton.org/snapshot</url> + <snapshots> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </snapshots> + <releases> + <enabled>false</enabled> + </releases> + </repository> + +</repositories> + +<pluginRepositories> + + <!-- depot des releases nuiton --> + + <pluginRepository> + + <id>nuiton.release</id> + <name>NuitonReleaseRepository</name> + <url>http://maven.nuiton.org/release</url> + <snapshots> + <enabled>false</enabled> + </snapshots> + <releases> + <enabled>true</enabled> + <checksumPolicy>warn</checksumPolicy> + </releases> + </pluginRepository> + + <!-- depot des snapshots nuiton --> + + <pluginRepository> + <id>nuiton.snapshot</id> + <name>NuitonSnapshotRepository</name> + <url>http://maven.nuiton.org/snapshot</url> + <snapshots> + <enabled>true</enabled> + <checksumPolicy>fail</checksumPolicy> + </snapshots> + <releases> + <enabled>false</enabled> + </releases> + </pluginRepository> + +</pluginRepositories> +------------------------------------------------------------------------------- + +* Crate our library + + Our library, to make it simple, will contain only one class and a static + method. + +------------------------------------------------------------------------------- +package org.myOrganisation.myLibrary; + +import static org.nuiton.i18n.I18n._; + +public class myLibrary { + + static public void myMethod(){ + System.out.println(_("My message to translate")); + } +} +------------------------------------------------------------------------------- + +* First build + + When you build your library for the first time with the command mvn compile, + you should see two new resource files containing each one a string to + translate without translation. + + You can now translate the string in both language, you will then have the + translation available for your next builds. + +* Second build + + If you build the library again, then integrate it in a final application using + I18n, the message will be displayed translated. + +* Tutorial sources + + * {{{../library-i18n.zip}Tutorial sources (zip)}} + + * {{{../library-i18n.tar.gz}Tutorial sources (tar.gz)}} Property changes on: trunk/src/site/en/apt/library.apt.vm ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/src/site/resources/application-i18n.tar.gz =================================================================== (Binary files differ) Property changes on: trunk/src/site/resources/application-i18n.tar.gz ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/src/site/resources/application-i18n.zip =================================================================== (Binary files differ) Added: trunk/src/site/resources/helloworld.tar.gz =================================================================== (Binary files differ) Property changes on: trunk/src/site/resources/helloworld.tar.gz ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/src/site/resources/helloworld.zip =================================================================== (Binary files differ) Added: trunk/src/site/resources/library-i18n.tar.gz =================================================================== (Binary files differ) Property changes on: trunk/src/site/resources/library-i18n.tar.gz ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/src/site/resources/library-i18n.zip =================================================================== (Binary files differ)