Issue
I've got a string-array
<string-array name="Color">
<item>@string/red</item>
<item>@string/green</item>
<item>@string/purple</item>
</string-array>
<string name="red">red></string>
<string name="green">green></string>
<string name="purple">purple></string>
And I asses it in Java:
int id = R.array.Color;
String[] colors = getResources().getStringArray(id);
variantTextView.setText(getResources().getResourceEntryName(id));
ansA.setText(colors[0]);
ansB.setText(colors[1]);
ansC.setText(colors[2]);
- How do I localize the NAME of this array?
- Is it required to extract the strings as I've done it? Or is there a way to localize the entire array?
Solution
How do I localize the NAME of this array?
You don't, any more than you localize a variable name in your Java/Kotlin code. If you want to display Color
to users, have that to-be-displayed value as a separate string resource.
Is it required to extract the strings as I've done it?
No.
Or is there a way to localize the entire array?
Have two copies of your Colors
<string-array>
, each in the proper resource set based on language. Each <string-array>
can then have <item>
elements that contain the actual strings, not references to string resources. You might do this if you want the array to have a different order of elements (e.g., sorted alphabetically).
Answered By - CommonsWare
Answer Checked By - Robin (JavaFixing Admin)