2

In my app, i am asking for language, can be either English or German. The selected language and its iso code is saved into preferences. On the basis of selected language i need to change all the texts into corresponding language.

For this, i have created res/values and res/values-de; each folder containing a strings.xml file. Issues are: 1) I am opening camera as well as a screen using opengl. After navigating via both of them, the texts does not change completely into german(if was chosen). Some text values change into German, rest not even on the same page. 2) Even without going through camera and opengl screens, the results are not achieved 100% always but gives a better result always as compared to case 1.

My implementations: 1) in onResume() of splash screen, i am changing locale based on preferences with the help of config.locale(). 2) in manifest file, each activity is set with activity:configChanges="locale". 3) in camera activity and opengl activity, onConfigurationChanged() is overridden in which i am again setting locale as per preferences.

please guide how to solve the locale issue.

3 Answers3

0
  • Check Point 1: Partial updation of resources. Make sure you have resources named correctly in all your languages.
  • Also, you can give this code a try. It is how i update locale of my app:

     public void updateLocale(String language) {
        Locale myLocale = new Locale(language);
        Locale.setDefault(myLocale);
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = myLocale;
        res.updateConfiguration(conf, dm);
    }
    

Let me know if it helps !

Gaurav Arora
  • 17,124
  • 5
  • 33
  • 44
  • #1) is fine as i have already mentioned that this is a random problem. At times a few or all text boxes shows correct i.e. German text, at times they don't. – user2309901 Apr 23 '13 at 07:32
  • #2) Tried this code as well though not much different than mine. Current situation is: i explicitly set the strings to text boxes in each onCreate of activity. By this, now i am succeeded in getting correct texts if i try to access those screens without going via camera or opengl screens. But the problem is as per the flow of the app, those screens need to be navigated via camera or opengl only. Now i am believing more that it has something related to opening camera/opengl both. Any suggestions? – user2309901 Apr 23 '13 at 07:36
0

I believe you need to add something to your AndroidManifest file indicating locale change. Here is an example: http://android.programmerguru.com/android-localization-at-runtime/

openrijal
  • 583
  • 6
  • 22
0

I had a similar problem with my app. App has force language changing option between Turkish and English. If my device language is English and if I use the app in Turkish, I can easily convert the language with the code below:

public void setAppLanguage(String languageCode) {

        String countryCode;

        if (languageCode.equals("tr")){
            countryCode = "TR";
        }else{
            countryCode = "US";
        }

        Locale locale = new Locale(languageCode, countryCode);
        Locale.setDefault(locale);
        Resources res = getResources();
        DisplayMetrics dm = res.getDisplayMetrics();
        Configuration conf = res.getConfiguration();
        conf.locale = locale;
        res.updateConfiguration(conf, dm);

        loginPrefsEditor.putString("uLang",languageCode);
        loginPrefsEditor.apply();


    }

However, when I open the camera and return from it, app language changes back to default phone language. App kills my activity when I open the camera. After return from the camera, it refreshes everything. So in order to solve this problem, I put my force change language method in onResume() method of every activity.

By doing this I would be able to solve this issue.

Can Uludağ
  • 705
  • 8
  • 14