-
1. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 8, 2006 7:15 PM (in response to andy.2003)Doesn't the JVM cache loaded resource bundles?!
You have a great point about the Seam resourceBundle component. I should certainly make this a session-scoped component and use the browser locale, not a global locale.
I suck at i18n stuff :-)
Thanks! -
2. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 8, 2006 9:18 PM (in response to andy.2003)Yes, Java caches ResourceBundles, so you don't need to worry about caching them yourself.
I have reworked the resourceBundle component as a SESSION scoped component, that uses the client locale, instead of letting you to set the locale in seam.properties.
This is of course the correct way to do it. duh. -
3. Re: RessourceBundle for all Locals in APP-Scope
andy.2003 Mar 9, 2006 3:20 AM (in response to andy.2003)"gavin.king@jboss.com" wrote:
... I have reworked the resourceBundle component as a SESSION scoped component ...
but if you store the resourceBundle in session scope, does seam load the resourceBundle for each Session, isn't it? So this shouldn't be very good for the memory usage (if each session stores the bundle)
-Andreas -
4. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 9, 2006 3:23 AM (in response to andy.2003)Well, I'm not absolutely certain, but I suppose that since the JVM is caching the resource bundle, all sessions are sharing the same instance.
Check if you like, but I would be very surprised if this was not what happens.... -
5. Re: RessourceBundle for all Locals in APP-Scope
andy.2003 Mar 9, 2006 8:13 AM (in response to andy.2003)You're right the JVM cache works very well! (Didn't know that Java caches the resources)
-
6. Re: RessourceBundle for all Locals in APP-Scope
perwik Mar 9, 2006 10:58 AM (in response to andy.2003)Gavin,
Using the browser locale is of course better than just using a default value, but what if the user wants to change the locale? I don't speak a word of french but when I'm on holiday and sit in front of a computer with a french version of Firefox I would at least want to be able to click a button on the site and change the language to English. This would be a lot easier to do if the Seam ResourceBundle could handle that. I posted a patch in http://jira.jboss.com/jira/browse/JBSEAM-149. This does not include your new additions but I think some kind of merge of the current version and mine should give a result.
Just adding apublic void setBundle(Locale locale) { bundle = java.util.ResourceBundle.getBundle( bundleName, locale, Thread.currentThread().getContextClassLoader() ); }
would do the trick I guess, but it would perhaps be nice to be able to just input a language or country code as well. -
7. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 9, 2006 5:18 PM (in response to andy.2003)But this would still be a per-client setting, right?
If so, I am +1 on adding this capability. -
8. Re: RessourceBundle for all Locals in APP-Scope
andy.2003 Mar 9, 2006 5:23 PM (in response to andy.2003)yes the client should be able to set his language and it should be stored in the session scope (maybe you can create a nice component for this...)
- Andreas -
9. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 9, 2006 7:56 PM (in response to andy.2003)Sure, that is easy to do.
-
10. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 10, 2006 2:02 AM (in response to andy.2003)OK, this is now in CVS:
<h:selectOneMenu value="#{localeSelector.language}"> <f:selectItem itemLabel="English" itemValue="en"/> <f:selectItem itemLabel="Deutsch" itemValue="de"/> <f:selectItem itemLabel="French" itemValue="fr"/> </h:selectOneMenu> <h:commandButton action="#{localeSelector.select}" value="#{messages.Switch}"/>
-
11. Re: RessourceBundle for all Locals in APP-Scope
perwik Mar 10, 2006 8:03 PM (in response to andy.2003)Thanks, this works great. Just as my own version, that I wrote before I saw that there was a reply to the thread :-) well, I guess it's always good to use the thinking cap, or something.
One problem though:
When setting the language to "sv" using this component (no country or variant selected) java will choose "messages.properties" before "messages_sv_SE.properties". Changing the filename to "messages_sv.properties" gets the job done, but that's not the way I want it.
An other thing:
It would be nice if setLocale() updated the country, language, and variant properties when it sets the default locale, so the correct language is selected in the list.private void setLocale() { ... this.language = locale.getLanguage; this.country = locale.getCountry(); this.variant = locale.getVariant }
Thing number three:
I think localeSelector could have apublic void setLocale(java.util.Locale locale) { this.locale = locale; }
This would make it easier to change to a locale when you have an instance of Locale.
Thing number four (I hope someone's still reading :-)
The ultimate localeSelector would be if the list automagically displayed the supported locales listed in faces-config.xml and used Locale.getDisplayLanguage() for the itemLabel. When doing this I would vote for using locale.getDisplayLanguage(locale) so that the language is displayed in the language of the locale. Someone wanting to change the language of a site should have an easier time locating his preferred language if it is displayed in, you guessed it, his preferred language. -
12. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 11, 2006 2:32 AM (in response to andy.2003)"perwik" wrote:
One problem though:
When setting the language to "sv" using this component (no country or variant selected) java will choose "messages.properties" before "messages_sv_SE.properties". Changing the filename to "messages_sv.properties" gets the job done, but that's not the way I want it.
THat's the way Java's lookup algorithm works, not ours.It would be nice if setLocale() updated the country, language, and variant properties when it sets the default locale, so the correct language is selected in the list.
OK, makes sense. -
13. Re: RessourceBundle for all Locals in APP-Scope
gavin.king Mar 11, 2006 4:42 AM (in response to andy.2003)done
-
14. Re: RessourceBundle for all Locals in APP-Scope
perwik Mar 11, 2006 8:45 AM (in response to andy.2003)"gavin.king@jboss.com" wrote:
THat's the way Java's lookup algorithm works, not ours.
Ok, I think I can live with that until I actually develop something that needs two different locales depending on country. I don't think it's that often. Although it should be easy enough to have a setLocaleString() like thispublic void setLocaleString(String localeString) { String[] localeParts = localeString.split("_"); if (localeParts.length() > 0) { this.language = localeParts[0]; } if (localeParts.length() > 1) { this.country = localeParts[1]; } if (localeParts.length() > 2) { this.variant = localeParts[2]; } }
and apublic String getLocaleString() { return this.locale.toString() }
and then<h:selectOneMenu value="#{localeSelector.localeString}"> <f:selectItem itemLabel="English" itemValue="en_US"/> <f:selectItem itemLabel="Deutsch" itemValue="de"/> <f:selectItem itemLabel="French" itemValue="fr_CH"/> <f:selectItem itemLabel="French" itemValue="fr_FR"/> </h:selectOneMenu> <h:commandButton action="#{localeSelector.select}" value="#{messages.Switch}"/>