XML mapping + localisation



I make an android application, I want to store my objects using XML mapping, but also I want to make localized strings. I saw a kind of solution - to make a lot of arrays:



<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>

<integer-array name="distance_from_sun">
<item>1000</item>
<item>2000</item>
<item>3000</item>
<item>4000</item>
</integer-array>
</resources>


And then, in code make objects, using same id's from this arrays.


But I think there is a better solution than this, can I store all names in different(localized) strings.xml and have a *.xml file, which looks like:



<object type="array" elementType="Planet" length="4" id="0">
<object type="Planet" id="1">
<field name="name" type="string" value="@string/mercury_name" />
<field name="distance_from_sun" type="int" value="1000" />
</object>
<object type="Planet" id="2">
<field name="name" type="string" value="@string/venus_name"/>
<field name="distance_from_sun" type="int" value="2000" />
</object>
<object type="Planet" id="3">
<field name="name" type="string" value="@string/earth_name" />
<field name="distance_from_sun" type="int" value="3000" />
</object>
<object type="Planet" id="4">
<field name="name" type="string" value="@string/mars_name" />
<field name="distance_from_sun" type="int" value="4000" />
</object>
</object>

No comments:

Post a Comment