Hi Greg,

As per my testing it seems an empty bundle is ok. But if I have any problem I 
will remember to try with a single property inside.

Regards,

Julien




________________________________
De : Greg Lindholm <greg.lindh...@gmail.com>
À : Struts Users Mailing List <user@struts.apache.org>
Envoyé le : Lundi, 17 Août 2009, 15h25mn 13s
Objet : Re: Re : Re : Struts2 + I18N

Another thing you can do is create an "essentially" empty
default_en.properties file. When 'en' is requested it will find the
default_en.properties file and stop looking.  When it goes to retrieving
values it will look in the default_en.properties and not find it (since it
is empty) then fallback to the values in default.properties.

IIRC, default_en.properties cannot be completely empty, it needs to contain
at least one entry or this doesn't work. So I normally include
"properties_locale=en" so I can tell which properties file was selected when
debugging.

I worked on this issue a few years ago and some of the issue details are a
bit fuzzy now but since then I have adopted this pattern and it's always
worked for me.


On Fri, Aug 14, 2009 at 5:16 PM, Julien HENRY <henr...@yahoo.fr> wrote:

> After digging into Struts2 code, here is what I discovered: this bug is
> simply caused by the normal behavior of getBundle (
> http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html#getBundle(java.lang.String,%20java.util.Locale,%20java.lang.ClassLoader)<http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html#getBundle%28java.lang.String,%20java.util.Locale,%20java.lang.ClassLoader%29>
> )
>
> Here is the explanation
>
> In my Struts2 application I have the following language files:
>
>
> default_de.properties
> default_fr.properties
> default.properties (contains EN)
>
> JVM Defaut Locale: fr_FR
>
>
> Scenario 1:
> struts.locale not set so fr_FR is the default
> When hitting the first action, default_fr.properties is used
> OK
>
> Scenario2:
> Now I want to switch to English so I append ?request_locale=en to the URL
> According to getBundle algorithm:
>    1) default_en.properties is looked but not found
>    2) default_fr.properties is found and used
> KO
>
> Scenario 3:
> struts.locale is set to en_US
> When hitting the first action, we are in the same case as scenario 2
> because JVM default is still fr_FR
>
> The issue lay in LocalizedTextUtil.findResourceBundle(String
> bundleName, Locale locale) because here we only know that the user
> wants the given locale but we have no idea of what is the fallback
> locale.
>
> Proposed solutions:
>
> 1) default.properties should always match JVM language. Because an
> application may be developped for several country it means forcing default
> JVM with -Duser.language=XX. But this is not a good solution because the
> same JVM may host several applications with possibly different default
> Locale.
>
> 2) Force JVM default locale on Struts startup to be equal to struts.locale.
> The main concern is I'm not sure it will works fine with multi-threading and
> it will have many side effects (like changing language for stacktraces in
> the log)
>
> 3) Clean solution : have a clear separation between requested locale (with
> potentialy a default struts.default.request.locale) and default local (mean
> the locale that is contained in the resource bundle without extension). Then
> use the Java 1.6 feature (I know, I know, don't shout at me)
> ResourceBundle.Control that allow to change the fallback locale.
>
> Interesting read:
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5086301
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4303146
>
> It seems that JSF implements its own lookup algorithm. IMHO this is the
> only solution if you don't want to use the JDK 1.6 feature
> ResourceBundle.Control.
>
>
> Regards,
>
> Julien
>
>
>
>
> ________________________________
> De : "mailtolouis2020-str...@yahoo.com" <mailtolouis2020-str...@yahoo.com>
> À : Struts Users Mailing List <user@struts.apache.org>
> Envoyé le : Vendredi, 14 Août 2009, 18h12mn 52s
> Objet : Re: Re : Struts2 +  I18N
>
> Not long ago, someone also got similar problem:
>
>
> http://markmail.org/message/mozukqgrnhfbq7od?q=s2+and+default+locale/language+list:org.apache.struts.users/
>
>
>
>
> ________________________________
> From: Julien HENRY <henr...@yahoo.fr>
> To: Struts Users Mailing List <user@struts.apache.org>
> Sent: Friday, August 14, 2009 4:52:28 PM
> Subject: Re : Struts2 +  I18N
>
> Hi,
>
> AFAIK this is the same as adding <constant name="struts.locale" value="en"
> /> in struts.xml.
>
> BTW I tried your suggestion without much improvement.
>
> I even tried to rename default.properties in default_en.properties => still
> no english.
>
>
>
>
> ________________________________
> De : BALAJI CRB <balaji_...@spanservices.com>
> À : Struts Users Mailing List <user@struts.apache.org>
> Envoyé le : Vendredi, 14 Août 2009, 17h47mn 37s
> Objet : RE: Struts2 +  I18N
>
> Hi,
>
>
>
> Use struts.locale=en   in your struts.properties file. Hope this works.
>
> Regards,
>
> Balaji C R B
>
>
>
> -----Original Message-----
> From: Julien HENRY [mailto:henr...@yahoo.fr]
> Sent: Friday, August 14, 2009 9:11 PM
> To: user@struts.apache.org
> Subject: Struts2 + I18N
>
>
>
> Hi,
>
>
>
> In my Struts2 application I have the following language files:
>
>
>
> default_de.properties
>
> default_fr.properties
>
> default.properties (contains EN)
>
>
>
> When I start my application, the application is in French (probably because
> JVM default locale is french). Then I tried to change language by appending
> ?request_locale=XX in the URL.
>
>
>
> Adding ?request_locale=de works fine. All texts are in German.
>
>
>
> Adding ?request_locale=en doesn't work. All texts are in French.
>
>
>
> I tried to add
>
> <constant name="struts.locale" value="en" />
>
> to struts.xml but no luck.
>
>
>
> How can I tell Struts that the default.properties file is English?
>
>
>
> Thanks,
>
>
>
> Julien
>
>
>
>
>
>
>
>
> DISCLAIMER:
>
> This email message and all attachments are  confidential and may contain
> information that
> is privileged,  confidential or exempt from  disclosure under applicable
> law.  If you are
> not  the intended  recipient,  you  are notified  that any dissemination,
> distribution or
> copying  of this email  is strictly prohibited. If you have received this
> email in error,
> please notify us immediately by return email or to
> mailad...@spanservices.com and destroy
> the original message.
>
> Opinions, conclusions, and other  information in  this message that  do not
> relate to the
> official business of SPAN, shall be understood to be neither given nor
> endorsed by SPAN.
>
>
>



      

Reply via email to