Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android string-array locale verification

Tags:

android

locale

I was wondering if anybody had come across a good way to validate string-arrays in the res/values directory.

I create by code using the default locale and may have a resource of something like

<string-array name="array_example1">
    <item>One</item>
    <item>Two</item>
    <item>Three</item>
</string-array>

Then when the translators for the app make their translations they also create a string-array. Occasionally if one translation lags behind another one of the resource files may have not as many entries in the array (maybe only "One" and "Two" from the above example)

Is there any easy way to validate whether there's a mismatch in the number of entries? Having a mismatch can cause problems in the code, but as the app has 10's of string-arrays in several languages checking they all match up is time consuming.

What approach do others have for this?

like image 755
Andrew Avatar asked Oct 12 '11 12:10

Andrew


1 Answers

I've found a better way to stop the crashes. I hadn't realised that string-arrays could reference string resources in the following way:

<string-array name="array_example1">
    <item>@string/resOne</item>
    <item>@string/resTwo</item>
    <item>@string/resThree</item>
</string-array>

Then add

<string name="resOne">One</string>
<string name="resTwo">Two</string>
<string name="resThree">Three</string>

Therefore this way if there is a mismatch the default language will just get shown for that option and stop crashes due to different sized lists

like image 185
Andrew Avatar answered Sep 28 '22 12:09

Andrew