dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #26224
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12988: added i18n-controller, available at /api/i18n, POST json array with keys, and receive a map with ...
------------------------------------------------------------
revno: 12988
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-11-20 14:10:13 +0100
message:
added i18n-controller, available at /api/i18n, POST json array with keys, and receive a map with key => i18n_value
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/I18nController.java
modified:
dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java
--
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/I18nManager.java'
--- dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-i18n/src/main/java/org/hisp/dhis/i18n/I18nManager.java 2013-11-20 13:10:13 +0000
@@ -41,8 +41,8 @@
I18n getI18n( Class<?> clazz ) throws I18nManagerException;
- public I18n getI18n( Class<?> clazz, Locale locale ) throws I18nManagerException;
-
+ 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-api/src/main/java/org/hisp/dhis/api/controller/I18nController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/I18nController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/I18nController.java 2013-11-20 13:10:13 +0000
@@ -0,0 +1,50 @@
+package org.hisp.dhis.api.controller;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Controller
+@RequestMapping( value = "/i18n" )
+public class I18nController
+{
+ @Autowired
+ private I18nManager i18nManager;
+
+ @RequestMapping( method = RequestMethod.POST )
+ public void postI18n( OutputStream outputStream, InputStream inputStream ) throws Exception
+ {
+ I18n i18n = i18nManager.getI18n( "org.hisp.dhis" );
+ Map<String, String> output = new HashMap<String, String>();
+
+ List<String> input = JacksonUtils.getJsonMapper().readValue( inputStream, new TypeReference<List<String>>()
+ {
+ } );
+
+ for ( String key : input )
+ {
+ String value = i18n.getString( key );
+
+ if ( value != null )
+ {
+ output.put( key, value );
+ }
+ }
+
+ JacksonUtils.getJsonMapper().writeValue( outputStream, output );
+ }
+}