jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r690545 - /incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/preferences/Preferences.java
Date Sat, 30 Aug 2008 18:44:42 GMT
Author: jalkanen
Date: Sat Aug 30 11:44:41 2008
New Revision: 690545

URL: http://svn.apache.org/viewvc?rev=690545&view=rev
Log:
JSPWIKI-333: Now parses the system setting properly.

Modified:
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/preferences/Preferences.java

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/preferences/Preferences.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/preferences/Preferences.java?rev=690545&r1=690544&r2=690545&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/preferences/Preferences.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/preferences/Preferences.java Sat Aug 30
11:44:41 2008
@@ -29,6 +29,7 @@
 import javax.servlet.http.HttpSession;
 import javax.servlet.jsp.PageContext;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 import org.json.JSONObject;
 
@@ -207,17 +208,38 @@
     {
         Locale loc = null;
         
-        String language = Preferences.getPreference( context, "Language" );
-
-        if( language != null)
-            loc = new Locale(language);
-
-        if( loc == null) 
+        String langSetting = Preferences.getPreference( context, "Language" );
+        
+        //
+        // parse language and construct valid Locale object
+        //
+        if( langSetting != null)
+        {
+            String language = "";
+            String country  = "";
+            String variant  = "";
+            
+            String[] res = StringUtils.split( langSetting, "-_" );
+            
+            if( res.length > 2 ) variant = res[2];
+            if( res.length > 1 ) country = res[1];
+            
+            if( res.length > 0 )
+            {
+                language = res[0];
+            
+                loc = new Locale( language, country, variant );
+            }
+        }
+        
+        // otherwise try to find out the browser's preferred language setting, or use the
JVM's default
+        if( loc == null)
         {    
             HttpServletRequest request = context.getHttpRequest();
             loc = ( request != null ) ? request.getLocale() : Locale.getDefault();
         }
-                
+
+        log.info( "using locale "+loc.toString() );
         return loc;
     }
 



Mime
View raw message