Search code examples
angularjstranslateangular-translate

property translate in angular


i want to translate a property to fetch the data from array i have array like this:

<Country>
<Id>183</Id>
<Name_Ar>المملكة المتحدة</Name_Ar>
<Name_En>United Kingdom</Name_En>
</Country>
<Country>
<Id>1</Id>
<Name_Ar>أفغانستان</Name_Ar>
<Name_En>Afghanistan</Name_En>
</Country>

and i have select with ng-options or ng-repeat

 <select ng-model="employee.Nationality_Id"> <option ng-repeat="county in countries" value="{{county.Id}}">{{county.Name_En}}</option> </select>

i want to translate the property {{county.Name_En}} to {{county.Name_Ar}} to get the value based on current language


Solution

  • instead of fetching data like {{county.Name_En}} we can write this in different formula like {{county["{{'Name' | tranlsate}}"]}}

    then we will add translate variable in translation arrays en:

    Name: 'Name_En'
    

    Ar:

    Name: 'Name_Ar'