HyunChul Kim
HyunChul Kim

Reputation: 1

Multi lingual support for Android 7.0 and above does not work

Starting in Android 7.0, Android language and locale support for multilingual users was improved.

https://developer.android.com/guide/topics/resources/multilingual-support.html

But it does not work exactly what I thought.

Here is res/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.tistory.httphckim999.languageprioritytest.MainActivity"
    android:orientation="vertical">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/first_test" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/second_test" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/third_test" />
</LinearLayout>

Here is res/values/strings.xml

<resources>
    <string name="app_name">Language Priority Test</string>
    <string name="first_test">first default</string>
    <string name="second_test">second default</string>
    <string name="third_test">third default</string>
</resources>

Here is res/values-ko/strings.xml

<resources>
    <string name="first_test">first ko</string>
</resources>

Here is res/values-zh/strings.xml

<resources>
    <string name="second_test">second zh</string>
</resources>

And here is res/values-ja/strings.xml

<resources>
    <string name="third_test">third ja</string>
</resources>

And my test devices locale setting priority is "ko > zh > ja"

I think it should be print like this.

first ko

second zh

third ja

But it was printed like this

first ko

second default

third default

I can't understand why it was printed like this.

I upload my test project here.

https://github.com/kimhc999/LanguagePriorityTest

I tested it in Galaxy S7(7.0), PIXEL(8.0 Preview 3), and emulators(7.0, 7.1, 8.0). But all of them have same result.

Can anyone help me?

Thank you.

Upvotes: 0

Views: 165

Answers (1)

Usman Rana
Usman Rana

Reputation: 2142

It is working in expected way, you are perceiving it in wrong way. In your app default language is English and you placed all values in strings.xml as following

<resources>
    <string name="app_name">Language Priority Test</string>
    <string name="first_test">first default</string>
    <string name="second_test">second default</string>
    <string name="third_test">third default</string>
</resources>

Language of your phone is ko and you placed only 1 value for that

Here is res/values-ko/strings.xml

<resources>
    <string name="first_test">first ko</string>
</resources>

When you run the application it will first search for value in values-ko folder and if value isn't available there then default value will be picked from values/strings.xml which is english in your case.

As only first_test is available in values-ko so for second_test and third_test it will pick values from default values folder and you are getting right result:

first ko

second default

third default

Upvotes: 1

Related Questions