You have a list of items that you would like to group together into an XML string array. Let's take a drop-down menu with language options as an example:
Languages:
English
Chinese
French
Spanish
Ideally you would want to group them into a string array that looks like this:
<string-array name="languages_array">
<item>English</item>
<item>Chinese</item>
<item>French</item>
<item>Spanish</item>
</string-array>
When uploading onto our platform, we recommend putting each array item into a separate string, adding the translatable="false" attribute to the string array, then referencing each item:
<string name="english_language">English</string>
<string name="chinese_language">Chinese</string>
<string name="french_language">French</string>
<string name="spanish_language">Spanish</string>
<string-array name="languages_array" translatable="false">
<item>@string/english_language</item>
<item>@string/chinese_language</item>
<item>@string/french_language</item>
<item>@string/spanish_language</item>
</string-array>
This way, due to the translatable="false"
attribute, the string-array will be hidden on our platform, but can still exist in the strings.xml file. When you want to add an extra item to your array, it will not affect the other array items and will remove sequencing complications with array items.
This not only helps during localization. but is also a best practice for handling string arrays for Android.
Comments
1 comment
If you had the foresight to make bar an xml element, wouldn't you have the foresight to make it a json object?
Plus, this is probably the exact best case to use xml over json. You're marking up text strings with properties. Thats what xml was designed to do, but how often do you serialize data like that?
Its a good point, but its no secret that xml should be used for mark up and json should be used for object notation.
MyAARPMedicare
Please sign in to leave a comment.