Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  146] [ 2]  / answers: 1 / hits: 16476  / 7 Years ago, thu, september 21, 2017, 12:00:00

I'm trying to translate my project into another language. I used angular translate library and provided an external JSON file with the translations. It looks like this:



{
hello_world: Hola Mundo
}


When I'm using it with simple hardcoded strings it works just fine and I get my correct translations:



<p>{{ hello_world | translate }}</p>


But how to deal with the ternary operator in code like this?



<button> {{ conditionValue ? 'Show' : 'Hide' }} </button>


How to change those 'Show' and 'Hide' values into a translation filter with Angular Translate? I tried different ways but I got an invalid syntax errors.
Thanks!


More From » angularjs

 Answers
37

I think if you wrap the ternary operator into (), it will work.



<button> {{ ( conditionValue ? 'Show' : 'Hide' ) | translate }} </button>

[#56421] Tuesday, September 19, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;