The item in string-array can be directly localized in android? - android

I know I can use string resource to localize item in string-array, just like Method 1 do.
Is it OK to localize the item in string-array directly ? just like Method 2
Thanks!
--------------------------Method 1-----------------------------------------
<string-array name="Box">
<item>#string/Inbox</item>
<item>#string/Sent</item>
<item>#string/Outbox</item>
<item>#string/Draft</item>
</string-array>
<string name="Inbox">Inbox</string>
<string name="Sent">Sent</string>
<string name="Outbox">Outbox</string>
<string name="Draft">Draft</string>
<string name="Inbox">收件</string>
<string name="Sent">发件</string>
<string name="Outbox">已发</string>
<string name="Draft">草稿</string>
-----------------------------Method 2-----------------------------------------
<string-array name="Box">
<item>Inbox</item>
<item>Sent</item>
<item>Outbox</item>
<item>Draft</item>
</string-array>
<string-array name="Box">
<item>收件</item>
<item>发件</item>
<item>已发</item>
<item>草稿</item>
</string-array>

yes you can use Method2.
you just have to create localized resource folder.
here is a complete reference.

Related

How can I nest string resource?

This is what I want to do, in standard way.
<string name="foo">foo</string>
<string name="foo_bar">foo bar</string>
Can I rewrite like below?
<string name="foo">foo</string>
<string name="foo_bar">#string/foo bar</string>
I know this is not in schema, however, it is OK like below,
<string name="foo">foo</string>
<string name="altfoo">#string/foo</string>
Why!?
This
<string name="foo">foo</string>
<string name="foo_bar">#string/foo bar</string>
wrong coz there is no resource with the name foo bar
The above would be right if you had
<string name="foo bar">foo and bar</string>
<string name="foo_bar">#string/foo bar</string>
This
<string name="foo">foo</string>
<string name="altfoo">#string/foo</string>
is right coz there is a resource with name foo and you are referencing the same
You may want to check
Concatenate Strings in the strings.xml file for Android

No resource found in xml

I have this error on my xml
error: Error: No resource found that matches the given name (at '^index_0' with value '#array/Tipo_peso').
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="#string/array_tipo_conversion">
<item>#array/Tipo_peso</item> //here show the error
<item>#array/Tipo_Longitud</item>
<item>#array/Tipo_Volumen</item>
</string-array>
<string-array name="#string/tipos">
<item>Peso</item>
<item>Longitud</item>
<item>Volumen</item>
</string-array>
<string-array name="#string/Tipo_peso">
<item>Kg</item>
<item>Gramos</item>
<item>Onza</item>
<item>Libras</item>
<item>Toneladas</item>
</string-array>
this is the file of strings.xml
<string name="Tipo_Volumen">Tipo_Volumen</string>
<string name="Tipo_Longitud">Tipo_Logitud</string>
<string name="Tipo_peso">Tipo_peso</string>
<string name="tipos">tipos</string>
<string name="array_tipo_conversion">array_tipo_conversion</string>
I need translated this in english and spanish
You can't use an 'identifier' as the value of attribute 'name' in the following line:
<string-array name="#string/Tipo_peso">
Consider this:
<string-array name="Tipo_peso">

Why getDefaultSharedPreferences(context).getString(key, value) returns localized string?

I'm working with an application in Android and I have a list preference. The problem is that when I get the value with PreferenceManager.getDefaultSharedPreferences(context).getString(key, value) it returns the localized string instead of the entry value wich is what I'm expecting. In a previous version it was working. That is the right behavior? In that case, how shall i do to get the entry value? Here is some code to explain.
Thanks in advance.
Preferences.xml:
<ListPreference
android:id="#+id/protocol"
android:key="protocol"
android:title="#string/protocol"
android:dialogTitle="#string/change_protocol"
android:defaultValue="default"
android:entries="#array/protocol_entries"
android:entryValues="#array/protocol_entry_values" />
arrays.xml
<string-array
name="protocol_entry_values">
<item>default</item>
<item>protocol_1</item>
<item>protocol_2</item>
<item></item>
</string-array>
<string-array
name="protocol_entries">
<item>#string/label_default_protocol</item>
<item>#string/label_protocol_1</item>
<item>#string/label_protocol_2</item>
<item>#string/label_other</item>
</string-array>
strings.xml
<string name="label_default_protocol">Default protocol</string>
<string name="label_protocol_1">First protocol</string>
<string name="label_protocol_2">Second Protocol</string>
<string name="label_other">Other</string>
It sounds like you have different versions of the <string-array name="protocol_entry_values"> data in localized form. You should only have one definition of the values. The protocol_entries should be localized.

Android: use res/values with String[]

I know how to use strings.xml for global strings in Android, but what's about the String[] ?
Is there any possibility to use this and if there is, how?
Thank you.
If you meant String arrays inside and xml refer here
Create a file in your values folder called arrays.xml and create your array like this
<string-array name="colors">
<item>red</item>
<item>orange</item>
<item>yellow</item>
<item>green</item>
<item>blue</item>
<item>violet</item>
</string-array>
Not Directly in strings.xml, but something like this can be done in string.xml:
<string name="string1">str1</string>
<string name="string2">str2</string>
<string-array name="system">
<item>#string/string1</item>
<item>#string/string2</item>
</string-array>

Referencing an XML string in an XML Array (Android)

in arrays.xml
<string-array name="my_items">
<item>My item 1</item>
<item>My item 2</item>
<item>My item 3</item>
</string-array>
in strings.xml
<resources>
<string name="item1">My item 1</string>
<string name="item2">My item 2</string>
<string name="item3">My item 3</string>
</resources>
I would like to reference the string in the array "My item 1" from strings.xml. How do I do that?
oh yeah, that is what I meant. This is how I did it.
<string-array name="my_items">
<item>#string/item1</item>
<item>#string/item2</item>
<item>#string/item3</item>
</string-array>
It resolved correctly in Android 1.6
You can't. It might be possible to do the reverse: have #string/item1 in the <string-array>.

Categories

Resources