I have been wanting the ability to be able to dynamically change a user's
locale.  Here is the use case:

    User is using a computer owned by someone else and cannot modify
settings.
    User wishes to view psmls in his or her own language (if possible) which
is different from owner of computer.
    User should be able to switch locale to see psmls in own language as
well as internationalized messages.

Currently, Jetspeed determines the locale by examining the header
information sent by the browser. If a user wishes to view a page in a
certain languge/country without specifying the exact language and country on
the url, it cannot happen.

Looking at the code, Jetspeed tends to continually reset the locale during
session validation and the locating of templates. I would propose the
attached patch to allow for the ability to change the locale dynamically.
Once that patch is applied, an action could be written that could change the
locale without it getting reset by Jetspeed.

There is another message in regards to this topic:

http://www.mail-archive.com/jetspeed-dev%40jakarta.apache.org/msg04921.html

This deals with the ability to change the l10n messages dynamically.  I do
not believe that the code attached in the message relies on the locale
object stored in the user's temporary storage though. Perhaps this could be
the basis of the action to change the user's locale for viewing different
psmls, as well as the l10n messages.

Does anyone have any thoughts?

Thanks,

Jeremy Ford


Index: JetspeedSessionValidator.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/modules/actions/JetspeedSessionValidator.java,v
retrieving revision 1.19
diff -u -r1.19 JetspeedSessionValidator.java
--- JetspeedSessionValidator.java       28 Jun 2002 05:37:28 -0000      1.19
+++ JetspeedSessionValidator.java       1 Nov 2002 03:05:11 -0000
@@ -146,15 +146,18 @@
             return;
         }
         
-        // Get the locale store it in the user object
-        Locale locale = LocaleDetector.getLocale(data);
-        if (locale == null) {
-            locale = new Locale(
-                     TurbineResources.getString("locale.default.language", "en"),
-                     TurbineResources.getString("locale.default.country", "US"));
-        }
+        Locale locale = (Locale)data.getUser().getTemp("locale");
+        if(locale == null) {        
+               // Get the locale store it in the user object
+               locale = LocaleDetector.getLocale(data);
+               if (locale == null) {
+                   locale = new Locale(
+                            TurbineResources.getString("locale.default.language", 
+"en"),
+                            TurbineResources.getString("locale.default.country", 
+"US"));
+               }
         
-        data.getUser().setTemp("locale", locale);
+               data.getUser().setTemp("locale", locale);
+        }
 
         // if a portlet is referenced in the parameters request, store it
         // in the RunData object


Index: JetspeedTemplateLocatorService.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/services/template/JetspeedTemplateLocatorService.java,v
retrieving revision 1.12
diff -u -r1.12 JetspeedTemplateLocatorService.java
--- JetspeedTemplateLocatorService.java 24 Oct 2002 16:17:21 -0000      1.12
+++ JetspeedTemplateLocatorService.java 1 Nov 2002 03:05:26 -0000
@@ -393,7 +393,7 @@
      */
     public String locateEmailTemplate(RunData data, String template)
     {
-      return locateEmailTemplate( data, template, LocaleDetector.getLocale(data));
+      return locateEmailTemplate( data, template, 
+(Locale)data.getUser().getTemp("locale"));
     }
 
     /**
@@ -588,23 +588,25 @@
      */
     private String localizeTemplateName(RunData data, Locale inLocale)
     {
-        Locale tmplocale = null;
+        Locale tmplocale = (Locale)data.getUser().getTemp("locale");
         if (inLocale != null)
         {
           tmplocale = inLocale;
         }
-        else
+        
+               if(tmplocale == null)
         {
-          tmplocale = LocaleDetector.getLocale(data);
-        }
-        // Get the locale store it in the user object
-        if (tmplocale == null) {
-            tmplocale = new Locale(
-                     TurbineResources.getString("locale.default.language", "en"),
-                     TurbineResources.getString("locale.default.country", "US"));
-        }
+               tmplocale = LocaleDetector.getLocale(data);
+        
+               // Get the locale store it in the user object
+               if (tmplocale == null) {
+                   tmplocale = new Locale(
+                            TurbineResources.getString("locale.default.language", 
+"en"),
+                            TurbineResources.getString("locale.default.country", 
+"US"));
+               }
 
-        data.getUser().setTemp("locale", tmplocale);
+               data.getUser().setTemp("locale", tmplocale);
+        }
 
         StringBuffer templatePath = new StringBuffer();
                                                    

--
To unsubscribe, e-mail:   <mailto:jetspeed-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:jetspeed-dev-help@;jakarta.apache.org>

Reply via email to