4

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?

Community
  • 1
  • 1
kingston
  • 11,053
  • 14
  • 62
  • 116

3 Answers3

3

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.

Community
  • 1
  • 1
  • Do you mean that I would need to set two different spans everytime I write numbers? In that case it would be simpler to use String.valueOf() and convert the number in an ASCII string – kingston Jan 19 '17 at 17:02
  • Mmm I'm not sure I've understood what you mean. In the linked question the idea is to use CustomTypefaceSpan to set a different font in two different spans – kingston Jan 19 '17 at 17:11
  • please see also the other answer here: https://stackoverflow.com/a/41744973/987753 – kingston Jul 13 '22 at 08:53
1

For now what I did is to use a custom font and to replace in the file for the custom font the digits with the Hindu-Arabic numbers with the correspondent char for the "western-Arabic" number.

Please check how to remove characters from a font file?

EDIT

It is now possible to use a locale like for example:

<item>ar-AE-u-nu-latn</item> <!-- Arabic (United Arab Emirates, Western Digits) -->

This is taken from here

kingston
  • 11,053
  • 14
  • 62
  • 116
1

You should trust the locale you are using. If you are specifically targetting ar_SA then you should let it render things the way it's meant to for that country. If you just want Arabic language but want the western Arabic numbers then try a locale from one of the western Arab countries, ar_MA for example.

Sarmad
  • 44
  • 1