EDIT
I'm porting my app to Arabic locale. I have some getString() with parameters like:
getString(R.string.distance, distance)
where <string name="distance">%1d km</string>
The requirement is that in Arabic I should show it like this: "2.3 كم".
If I set as the locale for Saudi Arabia (country = "sa") or UAE (country = "ae") the number are shown in Eastern-Arabic but my client wants them in Western-Arabic.
The solution here is to use Egypt as a country in the locale but this is not possible for me.
I tried:
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void setAppContextLocale(Locale savedLocale) {
Locale.Builder builder = new Locale.Builder();
builder.setLocale(savedLocale).setExtension(Locale.UNICODE_LOCALE_EXTENSION, "nu-latn");
Locale locale = builder.build();
Configuration config = new Configuration();
config.locale = locale;
config.setLayoutDirection(new Locale(savedLocale.getLanguage()));
mAppContext.getResources().updateConfiguration(config, mContext.getResources().getDisplayMetrics());
}
as suggested in this question but after that the country is ignored so both SA and AE locales use the strings in the default file.
There's such issue in Google's bugtracker: Arabic numerals in arabic language intead of Hindu-Arabic numeral system
If particularly Egypt locale doesn't work due to some customer's issue(I can understand it), then you can format your string to any other western locales. For example:
If solution with new
Locale
doesn't work at all, there's an ugly workaround:(and variations around it with Unicodes matching (U+0661,U+0662,...). See more similar ideas here)
Upd1: To avoid calling formatting strings one by one everywhere, I'd suggest to create a tiny Tool method:
Or to override the default
TextView
and handle it insetText(CharSequence text, BufferType type)
I hope, it helps
There is an easy way. Taking your integer number and format it to string, and it will apply localization implicitly to numbers by this method:
So 123 will become ١٢٣ and so on.
For more information see section "Format numbers" at: https://developer.android.com/training/basics/supporting-devices/languages
Set your TypeFace as per below for Arabic
abcd is Arabic font.