← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21919: translate options of optionsets if translation is enabled

 

------------------------------------------------------------
revno: 21919
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-02-10 08:58:36 +0700
message:
  translate options of optionsets if translation is enabled
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/OptionSetController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/OptionSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/OptionSetController.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/OptionSetController.java	2016-02-10 01:58:36 +0000
@@ -28,11 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.dxf2.common.TranslateParams;
 import org.hisp.dhis.option.OptionSet;
 import org.hisp.dhis.schema.descriptors.OptionSetSchemaDescriptor;
+import org.hisp.dhis.webapi.webdomain.WebOptions;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -41,4 +46,33 @@
 public class OptionSetController
     extends AbstractCrudController<OptionSet>
 {
+    @Override
+    protected void postProcessEntities( List<OptionSet> optionSets, WebOptions options, Map<String, String> parameters, TranslateParams translateParams )
+    {
+        if ( translateParams.isTranslate() )
+        {
+            optionSets.forEach( o -> translateOptions( o, translateParams ) );
+        }
+    }
+
+    @Override
+    protected void postProcessEntity( OptionSet optionSet, WebOptions options, Map<String, String> parameters, TranslateParams translateParams ) throws Exception
+    {
+        if ( translateParams.isTranslate() )
+        {
+            translateOptions( optionSet, translateParams );
+        }
+    }
+
+    private void translateOptions( OptionSet optionSet, TranslateParams translateParams )
+    {
+        if ( translateParams.defaultLocale() )
+        {
+            i18nService.internationalise( optionSet.getOptions() );
+        }
+        else
+        {
+            i18nService.internationalise( optionSet.getOptions(), translateParams.getLocale() );
+        }
+    }
 }