I am currently developing a project with Angular Js and incorporating the Angular-translate module
In a specific scenario, I encountered an issue where the translation key needed to be stored as a variable. To address this, I created an object within the translations object that contains all potential variables.
When utilizing dot notation like translate='status.awaiting'
, everything functions as expected. However, when attempting to use bracket notation such as translate='status[status]'
, it fails to work altogether!
Below is a simplified example of the situation at hand. Any assistance would be greatly appreciated!
angular.module('myApp',['pascalprecht.translate'])
.config(function($translateProvider){
$translateProvider.useSanitizeValueStrategy(null);
$translateProvider
.translations('ar', {
status:{
"new":"جديد",
"awaiting":"منتظر",
"confirmed":"مؤكد",
"shipped":"مشحون",
"delivered":"مستلم",
"returned":"مرتجع",
"canceled":"ملغى"
}
})
.preferredLanguage('ar');
})
.controller('myCtrl',function($scope){
$scope.current_status = 'awaiting';
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate/2.15.1/angular-translate.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<div translate='status.awaiting'> </div>
<div>{{current_status}} </div>
<div translate='status[current_status]'> </div>
</div>