Reputation: 21
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.
Upvotes: 2
Views: 1326
Reputation: 135
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);
Upvotes: 3