2

I want to format all numbers in my app to arabic numbers (١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩) so I thought about setting the locale to a combination of arabic and region : Egypt instead of only arabic but unfortunately for a reason or another, the locale is not set.

I set my locale like so:

Locale myLocale = new Locale("ar_EG");
Locale.setDefault(myLocale);
Configuration config = new Configuration();
config.locale = myLocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());

And my strings.xml is put in a folder named "values-ar-rEG".

What am I getting wrong?

Thank you very much in advance.

Alnamt
  • 21
  • 1
  • Indeed we have only arabic language, we don't have ar_eg or ar_sau, It's only "ar" and "values-ar". –  Jan 09 '18 at 21:45
  • check this it might help https://stackoverflow.com/questions/34266789/arabic-number-in-arabic-text-in-android – Space-A Jan 09 '18 at 22:21

1 Answers1

3

Locale class can receive 1,2 or 3 parameters, but it is better to use 2 parameters (language, country) to change text and numbers format and direction for right to left languages (i.e.).

I resolved it in this way:

 Locale myLocale = new Locale("ar","EG");
    Locale.setDefault(myLocale);
    Resources res = getApplicationContext().getResources();
    DisplayMetrics dm = res.getDisplayMetrics();
    Configuration conf = res.getConfiguration();
    conf.setLayoutDirection(myLocale);
    conf.locale = myLocale;
    res.updateConfiguration(conf, dm);
creyD
  • 1,972
  • 3
  • 26
  • 55
Milad Mohamadi
  • 127
  • 1
  • 10
  • 1
    Can you explain what you did in more detail please? That way people with similar problems can resolve their issues too. – creyD Jun 20 '19 at 10:26
  • sure, Locale class can receive 1,2 or 3 parameters ,that is better to use 2 parameters (language, country) to change text and numbers format and direction for Right to left languages – Milad Mohamadi Jun 20 '19 at 10:46
  • If more explanation is needed ask me in detail – Milad Mohamadi Jun 20 '19 at 10:53