David,

I have implemented a portlet which allows a user to change his/her locale.
It is based on the this proposal I made earlier
(http://www.mail-archive.com/jetspeed-dev%40jakarta.apache.org/msg04936.html
).

I have attache the xreg, the source file, and the vm necessary to use the
portlet.  In order for the portlet action to actually change the locale, the
patch that I have attached is required.

Known Issues:
1) VM is not internationalized.
2) The are not that many languages and countries to choose from currently.
They are set in the velocity.  Any ideas on better ways to do this would be
appreciated.
3) Settings are not permanent.  User would need to change locale each time
he/she logs in.  Not known if this is needed.
4) Implementation as portlet requires you to add it to a psml file to
actually use it.  Perhaps it should just be a standard VelocityAction and
template screen. (should be easy enough to convert)

If you have any thoughts, suggestions, or questions, let me know.

Jeremy Ford



----- Original Message -----
From: "David Sean Taylor" <[EMAIL PROTECTED]>
To: "Jetspeed Developers List" <[EMAIL PROTECTED]>
Sent: Thursday, November 14, 2002 2:00 PM
Subject: ChangeLanguage Portlet


> Massimiliano,
>
> I attempted to build the ChangeLanguage portlet and the associated
> localization service that you sent us a while back.
> It had syntax errors and wouldn't compile.
> Please compile your code before submitting it to the list.
>
>  if (user=="null")
>
> where user is a JetspeedUser. Which Java compiler are you using?
>
> Please don't dump code on us and expect the committers to clean up after
> you.
>
> After cleaning the syntax errors, I found:
>
> The ConstructorHtml class needed cleaning up, it wasn't handling
> JetspeedLinks correctly. (see the cvs head)
> It could still use a lot of improvement. Don't recommend hard-coding HTML
> into Java code, better to use Velocity or JSP.
>
> These two params are passed in, but are not used:
>
> String linguaAttuale, String linguaRichiesta
>
> Please review the Java coding standards on the Jetspeed website.
> Make sure that it passes CheckStyle. Use 4 space tabs.
>
> When is the service used? I thought it would be called by the portlet
> somehow. Perhaps its just not obvious to me.
>
> As for the functionality, what is it supposed to do?
> I thought it would immediately change the language on the fly....
>
> I guess I'll check it in, I think it could be useful if you are willing to
> clean it up and submit patches, I'll work with you on it.
>
> David
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:jetspeed-dev-unsubscribe@;jakarta.apache.org>
> For additional commands, e-mail:
<mailto:jetspeed-dev-help@;jakarta.apache.org>
>

Attachment: ChangeLocale.xreg
Description: Binary data

Attachment: CustomizeLocale.java
Description: Binary data

Attachment: customize-locale.vm
Description: Binary data

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