Search code examples
angularjsangular-gettext

angular-gettext and translating strings in ternary conditions


Before I start rewriting my code:

Using angular-gettext, is there anyway to deal with these type of inline ternary condition? Applying the translate filter doesn't seem to be an option here...

<a uib-tooltip="{{favourite?'remove from favourites':'add to favourites'}}" ng-click="someaction()">something</a>

Thanks in advance!


Solution

  • I would just move the strings to the controller (see the ng-gettext docs):

    angular.module("someApp").controller("someController", ['gettext', function (gettext) {
        $scope.favoriteRemove = gettext("remove from favorites"),
        $scope.favoriteAdd = gettext("add to favorites");
    }]);
    

    HTML

    <a uib-tooltip="{{favourite?favoriteRemove:favoriteAdd}}" ng-click="someaction()">something</a>