← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11313: Step two in login page i18n. Made it possible to retrieve internationalized strings based on a ex...

 

------------------------------------------------------------
revno: 11313
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-07-02 20:21:13 +0200
message:
  Step two in login page i18n. Made it possible to retrieve internationalized strings based on a explicit locales provided as query paramters.
added:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/loginStrings.vm
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetStringsFromLocaleAction.java
modified:
  dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java
  dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/action/LoginAction.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java'
--- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java	2013-03-13 14:14:24 +0000
+++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/DefaultI18nManager.java	2013-07-02 18:21:13 +0000
@@ -64,25 +64,27 @@
     // I18nManager implementation
     // -------------------------------------------------------------------------
 
+    @Override
     public I18n getI18n( Class<?> clazz )
         throws I18nManagerException
     {
         return new I18n( getGlobalResourceBundle(), getSpecificResourceBundle( clazz.getName() ) );
     }
 
-    /**
-     * Used to send a specific clazzName (path) to the resource bundler.
-     *
-     * @param clazzName Path to use for getting i18n prop file
-     * @return I18n object
-     * @throws I18nManagerException
-     */
+    @Override
+    public I18n getI18n( Class<?> clazz, Locale locale )
+        throws I18nManagerException
+    {
+        return new I18n( getGlobalResourceBundle(), getSpecificResourceBundle( clazz.getName() ) );
+    }
+
     @Override
     public I18n getI18n( String clazzName ) throws I18nManagerException
     {
         return new I18n( getGlobalResourceBundle(), getSpecificResourceBundle( clazzName ) );
     }
-
+    
+    @Override
     public I18nFormat getI18nFormat()
         throws I18nManagerException
     {

=== modified file 'dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java'
--- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java	2013-02-03 07:37:12 +0000
+++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java	2013-07-02 18:21:13 +0000
@@ -1,5 +1,7 @@
 package org.hisp.dhis.i18n;
 
+import java.util.Locale;
+
 /*
  * Copyright (c) 2004-2012, University of Oslo
  * All rights reserved.
@@ -38,6 +40,8 @@
 
     I18n getI18n( Class<?> clazz ) throws I18nManagerException;
 
+    public I18n getI18n( Class<?> clazz, Locale locale ) throws I18nManagerException;
+    
     I18n getI18n( String clazzName ) throws I18nManagerException;
 
     I18nFormat getI18nFormat() throws I18nManagerException;

=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/loginStrings.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/loginStrings.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/loginStrings.vm	2013-07-02 18:21:13 +0000
@@ -0,0 +1,9 @@
+{
+"create_an_account": "$!i18nObject.getString( "create_an_account" )",
+"login_password": "$!i18nObject.getString( "login_password" )",
+"login_username": "$!i18nObject.getString( "login_username" )",
+"forgot_password": "$!i18nObject.getString( "forgot_password" )",
+"create_an_account": "$!i18nObject.getString( "create_an_account" )",
+"wrong_username_or_password": "$!i18nObject.getString( "wrong_username_or_password" )",
+"powered_by": "$!i18nObject.getString( "powered_by" )"
+}

=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetStringsFromLocaleAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetStringsFromLocaleAction.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/i18n/action/GetStringsFromLocaleAction.java	2013-07-02 18:21:13 +0000
@@ -0,0 +1,94 @@
+package org.hisp.dhis.i18n.action;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Locale;
+import java.util.Locale.Builder;
+
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nManager;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class GetStringsFromLocaleAction
+    implements Action
+{
+    @Autowired
+    private I18nManager manager;
+    
+    private String language;
+    
+    public void setLanguage( String language )
+    {
+        this.language = language;
+    }
+
+    private String country;
+
+    public void setCountry( String country )
+    {
+        this.country = country;
+    }
+
+    private I18n i18nObject;
+
+    public I18n getI18nObject()
+    {
+        return i18nObject;
+    }
+
+    // -------------------------------------------------------------------------
+    // Action implementation
+    // -------------------------------------------------------------------------
+
+    public String execute()
+        throws Exception
+    {
+        Builder builder = new Locale.Builder();
+        
+        if ( language != null )
+        {
+            builder.setLanguage( language );
+        }
+        
+        if ( country != null )
+        {
+            builder.setRegion( country );
+        }
+        
+        Locale locale = builder.build();
+        
+        i18nObject = manager.getI18n( this.getClass(), locale );
+        
+        return SUCCESS;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/action/LoginAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/action/LoginAction.java	2012-10-29 14:37:17 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/security/action/LoginAction.java	2013-07-02 18:21:13 +0000
@@ -27,7 +27,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
 import org.apache.struts2.ServletActionContext;
+import org.hisp.dhis.i18n.resourcebundle.ResourceBundleManager;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.mobile.device.Device;
 import org.springframework.mobile.device.DeviceResolver;
 
@@ -49,6 +55,9 @@
     {
         this.deviceResolver = deviceResolver;
     }
+    
+    @Autowired
+    private ResourceBundleManager resourceBundleManager;
 
     // -------------------------------------------------------------------------
     // Input & Output
@@ -65,6 +74,13 @@
     {
         return failed;
     }
+    
+    private List<Locale> availableLocales;
+
+    public List<Locale> getAvailableLocales()
+    {
+        return availableLocales;
+    }
 
     // -------------------------------------------------------------------------
     // Action implementation
@@ -72,6 +88,7 @@
 
     @Override
     public String execute()
+        throws Exception
     {
         Device device = deviceResolver.resolveDevice( ServletActionContext.getRequest() );
 
@@ -82,6 +99,8 @@
             return "mobile";
         }
 
+        availableLocales = new ArrayList<Locale>( resourceBundleManager.getAvailableLocales() );
+        
         return "standard";
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2013-06-18 17:25:23 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml	2013-07-02 18:21:13 +0000
@@ -275,6 +275,8 @@
     <property name="identifiableObjectManager" ref="org.hisp.dhis.common.IdentifiableObjectManager" />
   </bean>
 
+  <bean id="org.hisp.dhis.i18n.action.GetStringsFromLocaleAction" class="org.hisp.dhis.i18n.action.GetStringsFromLocaleAction"/>
+
   <!-- About -->
 
   <bean id="org.hisp.dhis.about.action.AboutAction" class="org.hisp.dhis.about.action.AboutAction" scope="prototype">

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2013-03-22 09:20:24 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml	2013-07-02 18:21:13 +0000
@@ -118,6 +118,10 @@
       <param name="onExceptionReturn">plainTextError</param>
     </action>
 
+    <action name="loginStrings" class="org.hisp.dhis.i18n.action.GetStringsFromLocaleAction">
+      <result name="success" type="velocity-json">/dhis-web-commons/security/loginStrings.vm</result>
+    </action>
+
     <action name="account" class="org.hisp.dhis.useraccount.action.IsSelfRegistrationAllowedAction">
       <result name="success" type="velocity">/dhis-web-commons/useraccount/account.vm</result>
       <result name="error" type="redirect">login.action</result>
@@ -132,7 +136,7 @@
       <result name="success" type="velocity">/dhis-web-commons/useraccount/restore.vm</result>
       <result name="error" type="redirect">login.action</result>
     </action>
-
+    
   </package>
 
   <!-- Organisation Unit Selection Tree -->