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">
Related
I have ListPreference for selecting languages. The current trnalsations are defined in their own strings.xml as seen in the image. To fill the preference list i include the string-array elements inside the main strings.xml, making it a static configuration.
Question: Is there any way to make the Language ListPreference dynamic by iterating through all the strings.xml and extracting the Locale information from them some how on run time?
This is the current static setup:
values/strings/strings.xml
<resources>
<!-- Preferences -->
<string name="pref_language">Language</string>
<string-array name="pref_language_list">
<item>English</item>
<item>Svenska</item>
<item>Deutsch</item>
<item>Français</item>
<item>Português</item>
<item>Español</item>
<item>Pусский</item>
</string-array>
<string-array name="pref_language_values">
<item>en</item>
<item>se</item>
<item>de</item>
<item>fr</item>
<item>pt</item>
<item>es</item>
<item>ba</item>
</string-array>
</resources>
xml/pref_general.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference
android:entries="#array/pref_language_list"
android:entryValues="#array/pref_language_values"
android:key="language"
android:title="#string/pref_language"
android:icon="#drawable/language"
/>
</PreferenceScreen>
entries and entryValues should work.
while I don't understand these useless string definitions & string assignments ...
add them directly into the arrays; into values/arrays.xml; with attribute translatable="false".
and these language tags also don't match the resource file locations.
<resources>
<string-array name="pref_language_list" translatable="false">
<item>English</item>
<item>Svenska</item>
<item>Deutsch</item>
<item>Français</item>
<item>Português</item>
<item>Español</item>
<item>Pусский</item>
</string-array>
<string-array name="pref_language_values" translatable="false">
<item>en</item>
<item>se-rSE</item>
<item>de-rDE</item>
<item>fr-rFR</item>
<item>pt-rPT</item>
<item>es-rES</item>
<item>ba-rRU</item>
</string-array>
</resources>
strings.xml: Error: Found item String/button more than one time
how to rid off this problem??help
You cannot have multiple strings with same name ("button") in your case. Give unique name to each of them as follows
<resources>
<string name="app_name">CourtCounter</string>
<string name="button1">Button1</string>
<string name="button2">Button2</string>
<string name="button3">Button3</string>
</resources>
Do like this:-
<resources>
<string name="app_name">CourtCounter</string>
<string name="button1">Button1</string>
<string name="button2">Button2</string>
<string name="button3">Button3</string>
</resources>
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.
As you know you can write whatever resource you need inside res/values.
I made an xml file for each gui/activity I'm using. Here's an example:
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">This is home!</string>
<string name="app_name">Hattrick4Manager</string>
<string name="oauth_button">Authorize me!</string>
<string name="download_button">Syncronize</string>
<string name="oauth_name">Authorization</string>
</resources>
update-ui.xml
<resources>
<string name="inizio_download">Update Started...</string>
<string name="fine_download">Update Completed...</string>
<string name="update_title">Update</string>
<string name="update_done">Done</string>
<string name="update_inizio_club">Club...</string>
<string name="update_inizio_arena">Arena...</string>
<string name="update_inizio_fan">Fans...</string>
<string name="update_inizio_matches">Matches...</string>
<string name="update_inizio_league">League...</string>
<string name="update_inizio_leaguefix">League Fixtures...</string>
<string name="update_inizio_economy">Economy...</string>
<string name="update_inizio_players">Players...</string>
</resources>
When I use this in the code I have to recall them like:
R.string.update_done
or
R.string.hello
my problem is that like this I have basically to add the prefix for every GUI I make. I would prefer doing something like:
R.string.update-ui.done
Is it possible?
You can create as many resource files as you want, but you can not perform the nested name referencing based on the filename: the Android aapt tool doesn't support arbitrary nested objects on the generated R object.
You might be able to do stuff like this in update-ui.xml:
<resources>
<string name="update_ui_inizio_download">Update Started...</string>
<string name="update_ui_fine_download">Update Completed...</string>
</resources>
and then use
R.string.update_ui_inizio_download
to reference the contents of the file
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>.