2

I'm working on an Arabic site and I need to support arabic locale for showing numbers. I tried using the arabic angular locale file but it does not entail changing the number from EN to AR.

For example, the number 120 in EN is ١٢٠ in AR. Is there way to get this angular? (and then do calculations).

Demo

Prakhar
  • 3,486
  • 17
  • 44
  • 61
  • Could you not just use an arabic font? – ivarni Jul 06 '14 at 08:41
  • @ivarni, Arabic fonts still use the same western symbols used in English (1, 2, 3) for the unicode code points for those numbers. There are unique separate unicode code points for the corresponding Easter Arabic representations. In order to display them, you need to translate in code, not just use a different font. This is difficult without a framework to support it. – Samuel Neff Jul 06 '14 at 20:58
  • @ivarni, here's a great post with a long explanation and a few options (though none great, and not angular-specific). http://stackoverflow.com/questions/13757310/numbers-localization-in-web-applications – Samuel Neff Jul 06 '14 at 21:03

2 Answers2

1

In case someone else is also looking into this now (2017), calling toLocaleString on a number object should return the number string in the given locale.

let numbers = 1234567890;
console.log(numbers.toLocaleString('ar-EN'));

will log

١٬٢٣٤٬٥٦٧٬٨٩٠

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString

Stefan
  • 14,826
  • 17
  • 80
  • 143
user73657
  • 599
  • 5
  • 11
0

I decided to go ahead with writing a custom filter that just displays the number in arabic. Thanks for the link @Samuel Neff.

Prakhar
  • 3,486
  • 17
  • 44
  • 61
  • You should use a number formatter. It is not a best practice to hard code it. http://l10ns.org have a number formatter built in. – einstein Oct 30 '14 at 02:48