Search code examples
androidlocalearabic

Arabic numbers with ar-ae and ar-sa locale in Android


As I asked in the following question:

Arabic number in Arabic text in Android

if I use the arabic locale ar-ae or ar-sa the numbers are shown using Hindu-Arabic numbers. I need to show the digits like in English: "1234567890".

I used to use the trick of setting the numeral extension

Locale.Builder builder = new Locale.Builder();
builder.setLocale(savedLocale).setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-latn");
Locale locale = builder.build();

The problem is that after you do that the resource lookup gets broken and with Nougat it just does not work anymore.

Is there a way to see the "normal" digits even using the Arabic locale for ae and sa?


Solution

  • One workaround is to replace the font for the digit characters. You'll be able to keep your original font for the text.

    I would recommend to do that in a clean way by extending TypeFaceSpan. Take a look at this question.

    If you need some code, let me know and I'll update this answer.