0

I developed an app on spanish and later translate it to catalan. But they told me to make catalan the default language.

I have a values folder with the strings.xml (Catalan) and a values-es folder with strings.xml (Spanish). I assumed the app would load the first language but it launches in spanish.

On the preferences xml I set the default to be "ca":

<ListPreference
        android:key="pref_idioma"
        android:title="@string/idioma"
        android:summary="@string/selecciona_idioma"
        android:dialogTitle="@string/idioma"
        android:defaultValue="ca"
        android:entries="@array/idiomas"
        android:entryValues="@array/idiomasinterno" />

I use Shared Preferences so the user can chose the language he wants and that works. If he choses Catalan, the language loads correctly.

 if(preference.getKey().equals("pref_idioma")){
            Locale myLocale = new Locale(newValue.toString());
            Locale.setDefault(myLocale);
            Resources res = getResources();
            DisplayMetrics dm = res.getDisplayMetrics();
            Configuration conf = new Configuration();//res.getConfiguration();
            conf.locale = myLocale;
            res.updateConfiguration(conf, dm);
            ClassCOM.setIdioma(getApplicationContext(), newValue.toString());
            finish();
            startActivity(getIntent());
        }

It just bothers me that when the user installs the app, it's in spanish and I can't see why.

Thank you.

Yluna
  • 103
  • 2
  • 15
  • 1
    It will launch in whatever language the phone is set to. If your phone is set to Spanish, it will launch in Spanish. Which is the correct behavior- your app should follow the user phone's locale. – Gabe Sechan Sep 14 '18 at 14:56
  • Can't I force it to launch in other language? – Yluna Sep 14 '18 at 14:58
  • No. Nor should you want to. The user has decided what language he wants his phone's apps to be in. Respect it. With Catalan and Spanish its likely he speaks/reads both, but he may not. Why would you want to launch the app in a language he may not use? – Gabe Sechan Sep 14 '18 at 14:59
  • You could just do a settings screen to change language? or choose your language on first startup..? – Emanuel Graf Sep 14 '18 at 15:00
  • @Yluna You can forcefully set language of your choice but it is not good user-experience. please follow this thread for more infomation : https://stackoverflow.com/questions/2900023/change-app-language-programmatically-in-android – Vikasdeep Singh Sep 14 '18 at 15:02
  • I do have a settings screen where the user can chose between Spanish and Catalan. So in the end I'm not forcing anything, just the first impression. – Yluna Sep 14 '18 at 15:06

0 Answers0