Search code examples
javascripthtmlangularjslocalizationangular-translate

Currency translation -- changing an elements place with angularjs


I am using angular-translate in my project and I have 2 languages in it(Turkish&English).

In Turkish, price of an item is written like this: 36₺, but in the US, it's like: $9.

I don't want to use ng-if for every price in my project(there are lots of them) to change money sign's place.

So is there a shorter way to accomplish that?


Solution

  • Consider creating a custom filter that uses Number.prototype.toLocaleString()

    console.log(Number(8).toLocaleString('en',{style: 'currency', currency: 'USD'}))
    console.log(Number(8).toLocaleString('de',{style: 'currency', currency: 'EUR'}))