Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localization does not work for string array in android application

I have defined a string array in my values folder in this way for default English language

<string-array name="movie">
        <item>11001#Action#1</item>
        <item>11002#Animation#1</item>
        <item>11003#Comedy#1</item>
        <item>11004#Documentary#1</item>
        <item>11005#Family#1</item>
        <item> 11006#Film-Noir#1</item>
        <item>11007#Horror#1</item>
        <item>11008#Musical#1</item>
        <item>11009#Romance#1</item>
    </string-array>

My applicaiton is suported for many language like chainese simplified thats why i have defined another string-array in values-zh-rCN/string.xml for chainese simplified langue like this way

<string-array name="movie">
        <item>11001#动作片#1</item>
        <item>11002#动画片#1</item>
        <item>11003#喜剧#1</item>
        <item>11004#记录片#1</item>
        <item>11005#家庭#1</item>
        <item> 11006#黑色电影#1</item>
        <item>11007#恐怖片#1</item>
        <item>11008#音乐剧#1</item>
        <item>11009#爱情片#1</item>
    </string-array>

when my app is running and seleted Default english langue shown the array data but when i have seleted phone language in chainese simplified or other langue instead of english the array data does not shown. what are the possible solutionn for these problem ?

like image 460
Abaneel Jahid Avatar asked Mar 31 '17 17:03

Abaneel Jahid


2 Answers

Write your texts in string.xml as strings items, then use them into arrays.xml, example:

string.xml (English):

<string name="array_power_unit_item_00">By Watt.</string>
<string name="array_power_unit_item_01">By KiloWatt.</string>
<string name="array_power_unit_item_02">By Ampere and Volt.</string>
<string name="array_power_unit_item_03">By MilliAmpere and Volt.</string>

string.xml (Arabic):

<string name="array_power_unit_item_00">بالواط.</string>
<string name="array_power_unit_item_01">بالكيلو واط.</string>
<string name="array_power_unit_item_02">بالأمبير و الفولت.</string>
<string name="array_power_unit_item_03">بالميلي أمبير و فولت.</string>

arrays.xml:

<string-array name="arraypowerunit" translatable="false">
<item>@string/array_power_unit_item_00</item>
<item>@string/array_power_unit_item_01</item>
<item>@string/array_power_unit_item_02</item>
<item>@string/array_power_unit_item_03</item>
</string-array>
like image 65
MohammadL Avatar answered Oct 13 '22 03:10

MohammadL


<string name="abcd">喜剧</string>
<string name="efgh">记录片</string>

<array name="array_abcd">
     <item>@string/abcd</item>
     <item>@string/efgh</item>
</array>
like image 24
Narendra Sorathiya Avatar answered Oct 13 '22 02:10

Narendra Sorathiya