You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jacopo Cappellato <ja...@libero.it> on 2001/10/05 16:06:47 UTC

Re: LocalisationService

Hi Heiko,

I'm using properties files as bundles and all works well.
My bundles properties files are in WEB-INF/classes folder.
If you, or someone else, is interested in localization stuff, I have written
a Turbine Pull Tool for localization: it is very simple but, I think, very
usefull for getting localized text in templates (let me know if you want the
source files).
Good luck,

Jacopo


----- Original Message -----
From: Heiko Braun <he...@fork.de>
To: Turbine List <tu...@jakarta.apache.org>
Sent: Friday, October 05, 2001 4:26 PM
Subject: LocalisationService


> hi,
>
> while trying to implement the Localisation service
> i always get a MissingResourceException, although
> my classes have the right permissions and are placed
> in the classpath.
>
> while looking for an answer i found something
> on the cocoon mailing list, where people mentioned
> problems with tomcat's classloader under jdk 1.3.
>
> has anyone experienced similar problems?
>
> i am using j2sdk 1.3 on linux
> with tdk2.1 + tomcat-4 b6.
>
> thanks in advance,
>
>  --
>  heiko braun, fork unstable media
>  http://www.unstablemedia.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: LocalisationService

Posted by Daniel Rall <dl...@finemaltcoding.com>.
"Jacopo Cappellato" <ja...@libero.it> writes:

> Hi Heiko,
>
> I'm using properties files as bundles and all works well.
> My bundles properties files are in WEB-INF/classes folder.
> If you, or someone else, is interested in localization stuff, I have written
> a Turbine Pull Tool for localization: it is very simple but, I think, very
> usefull for getting localized text in templates (let me know if you want the
> source files).

Another such pull tool is checked into the Turbine 3 repository
(LocalizationTool).  To use, one configures TR.props and add it to the
context using a per-request scoping:

$l10n.HELLO_WORLD  ->  Hello World


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Localisation Pull Tool

Posted by John McNally <jm...@collab.net>.
Unfortunately I do not think there is a way to register an alternative
property file ResourceBundle.  The getBundle method looks for a class
according to the naming scheme and if it does not find one looks for a
property file and instantiates a PropertyResourceBundle if it finds
one.  (This is from the javadoc.)

So it appears if you want better behavior than available from
PropertyResourceBundle, you are stuck having to write a class per
property file.  I think it should be possible that these classes could
be empty, so it is not out of the question to go this route.

Other than that you are stuck having to implement a complete
localization implementation independent of ResourceBundles.

john mcnally

Daniel Rall wrote:
> 
> John McNally <jm...@collab.net> writes:
> 
> > Off the top of my head, I would say you will need to write an
> > implementation of ResourceBundle that will reload the properties file if
> > its modified date is greater than the last loaded date.  Quite a bit of
> > work.  Alternatively, if you have class reloading turned on (using
> > tomcat), try forcing a compile of one of the java classes in your app.
> > It should trigger a reload of the properties file, but I am not 100%
> > positive on that.
> 
> I'm also going to need an alternate ResourceBundle implementation.
> The PropertyResourceBundle implementation in the JDK 1.3.1 from Sun
> uses a Hashtable internally for storage.  For a web app, where the
> common use case is many concurrent reads, use of synchronized storage
> for property lookups is definitely not the best design decision.
> 
> Does anyone know how to "register" a ResourceBundle extension so that
> it would be used instead of PropertyResourceBundle when
> ResourceBundle.getBundle() is called?  (I admit I looked around for a
> way to do this only briefly.)  I'd like to write such an extension and
> include it with the LocalizationService--it will yield much higher
> read performance in a web application.
> 
>                                 Daniel
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-dev-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Localisation Pull Tool

Posted by Daniel Rall <dl...@finemaltcoding.com>.
John McNally <jm...@collab.net> writes:

> Off the top of my head, I would say you will need to write an
> implementation of ResourceBundle that will reload the properties file if
> its modified date is greater than the last loaded date.  Quite a bit of
> work.  Alternatively, if you have class reloading turned on (using
> tomcat), try forcing a compile of one of the java classes in your app. 
> It should trigger a reload of the properties file, but I am not 100%
> positive on that.

I'm also going to need an alternate ResourceBundle implementation.
The PropertyResourceBundle implementation in the JDK 1.3.1 from Sun
uses a Hashtable internally for storage.  For a web app, where the
common use case is many concurrent reads, use of synchronized storage
for property lookups is definitely not the best design decision.

Does anyone know how to "register" a ResourceBundle extension so that
it would be used instead of PropertyResourceBundle when
ResourceBundle.getBundle() is called?  (I admit I looked around for a
way to do this only briefly.)  I'd like to write such an extension and
include it with the LocalizationService--it will yield much higher
read performance in a web application.

                                Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Localisation Pull Tool

Posted by Daniel Rall <dl...@finemaltcoding.com>.
John McNally <jm...@collab.net> writes:

> Off the top of my head, I would say you will need to write an
> implementation of ResourceBundle that will reload the properties file if
> its modified date is greater than the last loaded date.  Quite a bit of
> work.  Alternatively, if you have class reloading turned on (using
> tomcat), try forcing a compile of one of the java classes in your app. 
> It should trigger a reload of the properties file, but I am not 100%
> positive on that.

I'm also going to need an alternate ResourceBundle implementation.
The PropertyResourceBundle implementation in the JDK 1.3.1 from Sun
uses a Hashtable internally for storage.  For a web app, where the
common use case is many concurrent reads, use of synchronized storage
for property lookups is definitely not the best design decision.

Does anyone know how to "register" a ResourceBundle extension so that
it would be used instead of PropertyResourceBundle when
ResourceBundle.getBundle() is called?  (I admit I looked around for a
way to do this only briefly.)  I'd like to write such an extension and
include it with the LocalizationService--it will yield much higher
read performance in a web application.

                                Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org


Re: Localisation Pull Tool

Posted by John McNally <jm...@collab.net>.
Off the top of my head, I would say you will need to write an
implementation of ResourceBundle that will reload the properties file if
its modified date is greater than the last loaded date.  Quite a bit of
work.  Alternatively, if you have class reloading turned on (using
tomcat), try forcing a compile of one of the java classes in your app. 
It should trigger a reload of the properties file, but I am not 100%
positive on that.

john mcnally

Juraj Buma wrote:
> 
> Hi !
> 
> I'm using Turbine 2.1 with my LocalizationTool  similar to that one in
> Turbine 3 CVS. I'm using it as request tool from my VM templates. My
> problem is that whenever I change MyBundle.properties during development
> I must restart Turbine to display changes.
> Since request tools can be pooled,  is solution to implement Recyclable
> interface and if so, how?
> 
> Many thanks.
> 
> Juraj.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Localisation Pull Tool

Posted by Juraj Buma <bu...@utcru.sk>.
Hi !

I'm using Turbine 2.1 with my LocalizationTool  similar to that one in 
Turbine 3 CVS. I'm using it as request tool from my VM templates. My 
problem is that whenever I change MyBundle.properties during development 
I must restart Turbine to display changes.
Since request tools can be pooled,  is solution to implement Recyclable 
interface and if so, how?

Many thanks.

Juraj.


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: LocalisationService

Posted by Jacopo Cappellato <ja...@libero.it>.
Hi John,

I'm not a Turbine expert at all and I'm only studing the Turbine
framework... version 2. I don't know nothing about Turbine 3

I'm happy to see that exists a LocalizationTool and I'm going to give a look
at it.
By the meantime I send you my (poor) Tool...

Jacopo
******************************************************
package it.sastau.turbine.util;

import java.util.Locale;

import org.apache.velocity.context.Context;

import org.apache.turbine.util.RunData;
import org.apache.turbine.util.pool.Recyclable;
import org.apache.turbine.util.Log;
import org.apache.turbine.services.pull.ApplicationTool;
import org.apache.turbine.services.localization.Localization;
import org.apache.turbine.services.resources.TurbineResources;


/**
 * The pull api for templates' localization
 *
 * @author <a href="mailto:jacopo.cappellato@sastau.it">Jacopo
Cappellato</a>
 */
public class LocalizationTool
    implements Recyclable, ApplicationTool
{
    /**
     * The object containing request Locale
     */
    private Locale locale;

    /**
     * The name of the key for user locale in user session
     */
    private String localeName;

    /**
     * The label returned if the key in the bundle doesn't exist
     */
    private String errorLabel;

    /**
     * The current prefix of the key in the bundle
     */
    private String prefix;

    /**
     * Constructor does initialization stuff:
     * it retrieves the following parameters:
     * tool.loc.localekey -> the name of the locale stored in the user's
session
     * tool.loc.errorlabel -> the label returned if the key in the bundle
doesn't exist
     */
    public LocalizationTool()
    {
   localeName = TurbineResources.getString("tool.loc.localekey", "locale");
   errorLabel = TurbineResources.getString("tool.loc.errorlabel",
"UNKNOWN");
    }

    /**
     * Sets the locale according to the value retrieved from user's
permanent storage
     * or, if this is not found, from the RunData object.
     */
    public void init(Object data)
    {
        Locale loc;
        // OLD trys to retrieve the locale from the user's session
   // OLD loc =
(Locale)(((RunData)data).getSession().getAttribute(localeName));
        // trys to retrieve the locale from the RunData (user) permanent
stuff
        loc = (Locale)(((RunData)data).getUser().getPerm(localeName));
        // if not founded, trys to retrieve the locale from the application
context
   if (loc == null) {
            loc =
(Locale)(((RunData)data).getServletContext().getAttribute(localeName));
        }
        // if not founded again, takes the locale from the RunData object
        this.locale = (loc == null? ((RunData)data).getLocale(): loc);
    }

    /**
     * nulls out the issue and user objects
     */
    public void refresh()
    {
        // do not need since it is a request tool
    }

    // ****************** Recyclable implementation ************************

    private boolean disposed;

    /**
     * Recycles the object for a new client. Recycle methods with
     * parameters must be added to implementing object and they will be
     * automatically called by pool implementations when the object is
     * taken from the pool for a new client. The parameters must
     * correspond to the parameters of the constructors of the object.
     * For new objects, constructors can call their corresponding recycle
     * methods whenever applicable.
     * The recycle methods must call their super.
     */
    public void recycle()
    {
        disposed = false;
    }

    /**
     * Disposes the object after use. The method is called
     * when the object is returned to its pool.
     * The dispose method must call its super.
     */
    public void dispose()
    {
        locale = null;
        prefix = null;
        disposed = true;
    }

    /**
     * Checks whether the recyclable has been disposed.
     * @return true, if the recyclable is disposed.
     */
    public boolean isDisposed()
    {
        return disposed;
    }


    // ****************** Methods usefull in templates
************************

    /**
     * Sets the prefix of the keys for the bundle
     */
    public void setPage(String prefix) {
   this.prefix = prefix;
    }

    /**
     * Gets the text keyed textKey from the bundle (prefixed, if the prefix
is set)
     */
    public String text(String textKey)
    {
            return getText((prefix == null? textKey: prefix + "_" +
textKey), null);
    }
    /**
     * Gets the text keyed textKey from the bundle with the prefix pageName
     */
    public String text(String pageName, String textKey)
    {
        return getText(pageName + "_" + textKey, null);
    }
    /**
     * Gets the text keyed textKey from the bundle (prefixed, if the prefix
is set)
     */
    public String textd(String textKey, String defaultText)
    {
            return getText((prefix == null? textKey: prefix + "_" +
textKey), defaultText);
    }
    /**
     * Gets the text keyed textKey from the bundle with the prefix pageName
     */
    public String textd(String pageName, String textKey, String defaultText)
    {
        return getText(pageName + "_" + textKey, defaultText);
    }
    /**
     * Here all the magic happens
     */
    private String getText(String textKey, String defaultText)
    {
        String text;
   try {
            text = get(textKey);
        }
        catch (Exception e) {
   text = (defaultText == null? errorLabel + " (" + textKey + ") ":
defaultText);
        }
        return text;
    }
    /**
     * Here all the magic happens
     */
    private String get(String textKey) throws Exception {
        return Localization2.getString(textKey, locale);
    }
}

*******************************************************************

----- Original Message -----
From: John McNally <jm...@collab.net>
To: <tu...@jakarta.apache.org>
Sent: Friday, October 05, 2001 4:53 PM
Subject: Re: LocalisationService


> Can you compare your tool to the one in turbine?
>
>
<http://cvs.apache.org/viewcvs/jakarta-turbine-3/src/tool/org/apache/turbine
/tool/LocalizationTool.java?rev=1.6&content-type=text/vnd.viewcvs-markup>
>
> Is there something that you think could be added to this?
>



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: LocalisationService

Posted by John McNally <jm...@collab.net>.
Can you compare your tool to the one in turbine?

<http://cvs.apache.org/viewcvs/jakarta-turbine-3/src/tool/org/apache/turbine/tool/LocalizationTool.java?rev=1.6&content-type=text/vnd.viewcvs-markup>

Is there something that you think could be added to this?

Jacopo Cappellato wrote:
> 
> Hi Heiko,
> 
> I'm using properties files as bundles and all works well.
> My bundles properties files are in WEB-INF/classes folder.
> If you, or someone else, is interested in localization stuff, I have written
> a Turbine Pull Tool for localization: it is very simple but, I think, very
> usefull for getting localized text in templates (let me know if you want the
> source files).
> Good luck,
> 
> Jacopo
> 
> ----- Original Message -----
> From: Heiko Braun <he...@fork.de>
> To: Turbine List <tu...@jakarta.apache.org>
> Sent: Friday, October 05, 2001 4:26 PM
> Subject: LocalisationService
> 
> > hi,
> >
> > while trying to implement the Localisation service
> > i always get a MissingResourceException, although
> > my classes have the right permissions and are placed
> > in the classpath.
> >
> > while looking for an answer i found something
> > on the cocoon mailing list, where people mentioned
> > problems with tomcat's classloader under jdk 1.3.
> >
> > has anyone experienced similar problems?
> >
> > i am using j2sdk 1.3 on linux
> > with tdk2.1 + tomcat-4 b6.
> >
> > thanks in advance,
> >
> >  --
> >  heiko braun, fork unstable media
> >  http://www.unstablemedia.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: LocalisationService

Posted by Heiko Braun <he...@fork.de>.
hi jacopo,

that might be an idea to use resource properties
instead of listbundles, i am going to try it that way.

regarding the pull tool you mentioned,
it would be really nice if can take a look at it.
for now i didnt touch the pull mechanism,
but it might be a good starting point.

thanks so far,

heiko

On Fri, 5 Oct 2001, Jacopo Cappellato wrote:

> Hi Heiko,
>
> I'm using properties files as bundles and all works well.
> My bundles properties files are in WEB-INF/classes folder.
> If you, or someone else, is interested in localization stuff, I have written
> a Turbine Pull Tool for localization: it is very simple but, I think, very
> usefull for getting localized text in templates (let me know if you want the
> source files).
> Good luck,
>
> Jacopo
>
>
> ----- Original Message -----
> From: Heiko Braun <he...@fork.de>
> To: Turbine List <tu...@jakarta.apache.org>
> Sent: Friday, October 05, 2001 4:26 PM
> Subject: LocalisationService
>
>
> > hi,
> >
> > while trying to implement the Localisation service
> > i always get a MissingResourceException, although
> > my classes have the right permissions and are placed
> > in the classpath.
> >
> > while looking for an answer i found something
> > on the cocoon mailing list, where people mentioned
> > problems with tomcat's classloader under jdk 1.3.
> >
> > has anyone experienced similar problems?
> >
> > i am using j2sdk 1.3 on linux
> > with tdk2.1 + tomcat-4 b6.
> >
> > thanks in advance,
> >
> >  --
> >  heiko braun, fork unstable media
> >  http://www.unstablemedia.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org