Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change Locale? Not working on some Devices

I'm writing app that support two language and I'm changing language with Change app Locale here my code :

 Locale locale = new Locale("fa");
            Locale.setDefault(locale);
            Configuration configs = new Configuration();
            configs.locale = locale;
            getBaseContext().getResources().updateConfiguration(configs, getBaseContext().getResources().getDisplayMetrics());

And

in manifest I'm set android:supportsRtl="true"

These codes working in many Devices but in some devices not working . for example Texts not Translating but Direction change .

Tested Devices :

  • Samsung J5Pro 2018 (android = 7.1): Worked
  • Pixel 2 API 26 : Worked
  • Samsung J7 2017 (android = 7): Worked
  • Nexus 5 (android = 6) : Not Worked
  • Samsung Galaxy G531 (android < lollipop) : Not Worked
like image 951
The Jake Avatar asked Oct 24 '18 08:10

The Jake


1 Answers

i have found my solution , my problem was i'm inserted "fa" in Locale and my String Values Directory name was values-fa-rlIR, so names are different so not worked ,i'm wondering why it's working on some devices!

I'm just change the String Values Directory name from values-fa-rlIR to values-fa and it's working well.

like image 132
The Jake Avatar answered Oct 18 '22 03:10

The Jake