a patch for struts2 i18n

View: New views
2 Messages — Rating Filter:   Alert me  

a patch for struts2 i18n

by Roberto Nunnari-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

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);

-------------------------------------------------------------------------
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@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user

Re: a patch for struts2 i18n

by Anjani Shrivastava :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

sir
i want to home page desing in struts framework then how i will do pls give also sample code
 
 
in advance thank u

 
On 1/20/08, Roberto Nunnari <robi@...> wrote:
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

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);

-------------------------------------------------------------------------
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@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user



-------------------------------------------------------------------------
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@...
https://lists.sourceforge.net/lists/listinfo/struts-menu-user
LightInTheBox - Buy quality products at wholesale price