Thank you for your help. I will try to use the code.
Regards, S�bastien Dui [EMAIL PROTECTED] -----Message d'origine----- De : Panu H�llfors [mailto:[EMAIL PROTECTED]] Envoy� : mar. 23 juillet 2002 10:54 � : Velocity Users List Objet : Re: Handling multiple languages On Tue, Jul 23, 2002 at 10:39:25AM +0200, S�bastien Dui wrote: > I was curious if any did have any experience parsing multiple > languages for a same website with Velocity ? My first taught was to use We use Turbine with Velocity and we created a simple ApplicationTool (a pull tool) to retrieve localized strings from a resource bundle using the Localization service of Turbine. (See more in the javadoc below) We haven't tested how fast this is but however it's a lot more convenient way to do it than administrating a bunch of different vm files (at least for now, we may look into using a tool to automatically generate localized templates in future). I'm pasting the source code here, I hope it's useful to someone: ------------------------------------------------------- package fi.viloke.tools.turbine.services.pull; /* * * Copyright (c) 2002, Viloke Oy * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - Neither the name of Viloke Oy nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * */ import org.apache.turbine.services.pull.ApplicationTool; import org.apache.turbine.services.localization.Localization; /** * Implements a bridge from Velocity context to Turbine Localization * service. That is - this provides a pull tool that may be automatically * instantiated by Turbine in Velocity context. The tool contains * methods that call the methods of *{@link org.apache.turbine.services.localization.Localization} * <p> * Applies to Turbine 2. * <p> * To use this service you will first have to make sure that the pull * service is enabled in the Turbine configuration * (<tt>TurbineResources.conf</tt>): The line * <pre> * services.PullService.classname=org.apache.turbine.services.pull.TurbinePullS ervice * </pre> * should be uncommented.<br> * Secondly, add the following line in the configuration file * (most likely in the <i>Pull service</i> section): * <pre> * tool.global.L=fi.viloke.tools.turbine.services.pull.LocalizationPullService * </pre> * This makes Turbine instantiate LocalizationPullService globally for * all requests as <b>$L</b> in Velocity context. * <p> * This is, you will be able to use * <tt>$L.getString("your.message")</tt>, or in the abbreviated form, * <tt>$L.s("your.message")</tt> to retrieve messages from Turbine's * Localization service, as if you called * Localization.getString("your.message") in Java source code. *<p> * The class has no internal state, so the object may be safely * shared. * * @author <a href="mailto:[EMAIL PROTECTED]">Panu Hällfors</a> */ public class LocalizationPullService extends Localization implements ApplicationTool { /** * Implementing ApplicationTool:<br> * For a global tool as we are, the init param is null, so there's * nothing we do here */ public void init(Object data) { } /** * Implementing ApplicationTool:<br> * We have no internal state so nothing's done here */ public void refresh() { } /** * A short for getString() - calls that function with same * arguments */ public static String s(String str) { return getString(str); } /** * A short for getString() - calls that function with same * arguments */ public static String s(String str, String lang) { return getString(str, lang); } } --------------------------------------------------------- Panu -- Panu H�llfors, [EMAIL PROTECTED]|CS Student, Helsinki University of Technology http://panu.hallfors.com | Internet Application Developer, Viloke Oy -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
