Tapan Bavaliya
Tapan Bavaliya

Reputation: 155

translate using https://angular-translate.github.io/

i am using https://angular-translate.github.io/ module for translation

my key array is

$scope.array = [
    "full_name",
    "email",
    "phone_no"
]; 

and my translation for that is

$translateProvider.translations('en', {
        full_name:'full name',
        email:'email',
        phone_no:'phone no'
});

and have code like this

<div ng-repeat="item in array">
  {{item | translate}}
</div>

but i can't get translation. can anyone help to do proper way ??

Upvotes: 0

Views: 64

Answers (2)

Mikko Viitala
Mikko Viitala

Reputation: 8394

This should do it

angular.module('app', ['pascalprecht.translate'])

  .config(function($translateProvider) {
    $translateProvider.translations('en', {
      full_name: 'Full name',
      email:     'Email address',
      phone_no:  'Phone number'
    });

    $translateProvider.preferredLanguage('en');
    $translateProvider.fallbackLanguage(['en']);
  })

  .controller('MainCtrl', function($scope) {
    $scope.array = ['full_name','email','phone_no']; 
});


imgur

Upvotes: 1

A. Rodas
A. Rodas

Reputation: 20689

Have you set the preferred language in the configuration? If you don't do so, the 'en' translations won't be applied.

.config(function($translateProvider) {
  $translateProvider.translations('en', {
    /* ... */
  });
  $translateProvider.preferredLanguage('en');
});

Live demo

Upvotes: 1

Related Questions