Search code examples
angularjsangular-translate

How to store Angular translation strings in an array


I use angular-translate to localise my app and display my string inside brackets {{"TEA_BREAK" | translate}} . Now, I want to store those strings {{"TEA_BREAK" | translate}} inside an array:

array = [ "{{'TEA_BREAK' | translate}}", "{{'TEA2_BREAK' | translate}}"];

Obviously that doesn't work. I did try different variations, with brackets, without brackets etc. Nothing works. I wonder what would be the best way to do that?


Solution

  • I think you should use $filter service to translate these text.

    Inject $filter service

    function MyController($filter)
    

    Then translate your text like this:

    array.push($filter('translate')('TEA_BREAK'));