Android getString() with multilingual not working

1.2k views Asked by At

I've create a short test Application with the following pre conditions:

My Smartphone run on 7.0 (and up). I've setup multiple languages in my settings English (United States) & Deutsch (Deutschland).

This is my App setup:

compile-, target-, min-SdkVersion 24

String-Resources:

enter image description here

The content from strings.xml ("default") is:

<resources>
    <string name="app_name">Test</string>
    <string name="test">default</string>
</resources>

And the content from string.xml (values-en-rGB) is:

<resources>
    <string name="test">GB Fallback!</string>
</resources>

The MainActivity have only a onCreate() with the following code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final String string = getString(R.string.test);
    Log.d("TestString", string);

    final LocaleList locaList = LocaleList.getDefault();
    for (int i = 0; i < locaList.size(); i++) {
        Log.d("AvailableLocale", locaList.get(i).toLanguageTag());
    }
}

When I run my App I expect the output from "TestString" is GB Fallback!. Why? Because Android 7.0 support multilingual. * (See update)

Instead of GB Fallback! I get always the default output. That means default.

The output from AvailableLocale is always up to date with the setup from my phone settings.

So. Why I got default from getString(R.string.test). Do I miss understand something with the multilingual stuff from the Android docs?

* Update

Why I claim I got GB Fallback!. The reason is the multilingual feature. The documentation shows a nice table: enter image description here I will try it to map it to my situation:

(Sorry, my Image is wrong. I don't mean de-GB. It's en-GB of course) enter image description here

So, what is wrong here?

0

There are 0 answers