wtorek, 22 sierpnia 2017

How to add translated string to JHipster AngularJS controller

Let’s assume we have already language files in /src/main/webapp/i18n/ and reference for it in state.js.


In controller add $translate to inject section:


1
2
3
4
5
    ManagerSubstituteDialogController.$inject = ['$timeout', '$scope', '$stateParams', '$translate', '$uibModalInstance', 'entity', 
                                                 'ProductSold', 'Product', 'ProductOnStock', 'ManagerSubstitute'];

    function ManagerSubstituteDialogController ($timeout, $scope, $stateParams, $translate, $uibModalInstance, entity, 
               ProductSold, Product, ProductOnStock, ManagerSubstitute) {


Then translated string is:


1
var substituteString=$translate.instant("barfitterApp.productSold.substitute");