a patch for struts2 i18n

Roberto Nunnari <[email protected]> Sun, 20 Jan 2008 15:01:25 +0100
Newsgroups gmane.comp.java.struts-menu.user
Message-ID <[email protected]>
Hello.

It seams that my previous emails of december didn't go through..
so here it comes again.

Hi guys.

This is a patch to let switching locale in struts2..

if you store the ResourceBundle and then check for null,
it doesn't let the user switch Locale afterword,
as switching Locale requires calling ResourceBundle.getBundle()
with the desired Locale as a parameter.

Thank you for this great library!

Best regards and Happy New Year!

-- 
Robi

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
struts-menu-user mailing list
struts-menu-user-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/struts-menu-user
struts-menu.patch (text/plain, 1.7 KB)
Index: src/java/net/sf/navigator/taglib/UseMenuDisplayerTag.java
===================================================================
RCS file: /cvsroot/struts-menu/navigator/src/java/net/sf/navigator/taglib/UseMenuDisplayerTag.java,v
retrieving revision 1.16
diff -u -r1.16 UseMenuDisplayerTag.java
--- src/java/net/sf/navigator/taglib/UseMenuDisplayerTag.java	4 Oct 2006 22:26:02 -0000	1.16
+++ src/java/net/sf/navigator/taglib/UseMenuDisplayerTag.java	1 Jan 2008 17:54:05 -0000
@@ -189,9 +189,12 @@
             Locale locale;
 
             if (localeKey == null) {
-                // default to Struts locale
-                locale = 
-                    (Locale) pageContext.findAttribute("org.apache.struts.action.LOCALE");
+                // default to Struts2 locale
+                locale = (Locale) pageContext.findAttribute("WW_TRANS_I18N_LOCALE");
+                if (locale == null) {
+                    // first fallback to Struts1 locale
+                    locale = (Locale) pageContext.findAttribute("org.apache.struts.action.LOCALE");
+                }
                 if (locale == null) {
                     locale = pageContext.getRequest().getLocale();
                 }
@@ -200,9 +203,6 @@
             }
             mrDisplayerInstance.setLocale(locale);
             
-            if (rb != null) {
-                mrDisplayerInstance.setMessageResources(rb);
-            } else {
                 Object resources = pageContext.findAttribute(bundleKey);
                 
                 if (resources == null) {
@@ -216,7 +216,6 @@
                 } else {
                      mrDisplayerInstance.setMessageResources(resources);   
                 }
-            }
         }
 
         displayerInstance.setConfig(config);