3

I have my array.xml to fill preferences value.

<string-array name="language">
    <item>English</item>
    <item>German</item> 
    <item>Russian</item>
    <item>Italian</item>
</string-array>

To translate the items I put them in various string.xml file, how can I add the values from @string/english, @string/german etc.?

1
  • What is wrong with <item>@string/english</item> and then <string name="english">English</string> in strings.xml ? Commented Oct 9, 2014 at 10:01

3 Answers 3

10

do this...

<string name="jan">January</string>
<string name="fev">February</string>
<string name="mar">March</string>

<string-array name="year">
    <item name="jan">@string/jan</item>
    <item name="fev">@string/fev</item>
    <item name="mar">@string/mar</item>
</string-array>
Sign up to request clarification or add additional context in comments.

Comments

7

Have you tried something like this:

res/values/array.xml
res/values-fr/array.xml
res/values-ja/array.xml

And so on...

If your issue is that you want to substitute the <item> value dynamically, you might have to do this in code. Check out this post: dynamic parameters in strings

1 Comment

ops... it was simple... I didn't think to duplicate array.xml :( thanks
2

You can just create string arrays in string.xml and other string.xml(ru) etc.

See below code snippet :-

string.xml

<!-- Language array -->
<string-array name="languages">
    <item>English</item>
    <item>Russian</item>
</string-array>

string.xml(ru)

<!-- Language array -->
<string-array name="languages">
    <item>английский</item>
    <item>русский</item>
</string-array>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.