Android ResourceNotFound exception - android

I have two values directories - one for English and one default.
if the resource are located in any of those folders, i can use it.
But if there is no resource in default values directory and locale is other than English, it causes ResourceNotFoundException.
I understand why this happens and why Android was built this way (to prevent ambiguous resource usage in case there are more than one non-default resource files with this resource).
But is there any way to force Android use, for example, English resource bundle if resource couldn't be found?

The only option you have is to make sure the /res/values/strings.xml file contains every string in English but you must also have /res/values-no/strings.xml which has the Norwegian strings.
If /res/values-no/strings.xml doesn't have the resource it will drop back to /res/values/strings.xml. It's the only way to do it.

Related

Why do I keep getting this "is translated but not found in default local"?

Why do I keep getting this "is translated but not found in default local"? how can I solve it?
To my knowledge there are only two strings files I need to worry about the base one valuse\strings.xml and ja/strings.xml the first in English, the second in Japanese.
The base string resources is inside values directory and the translation is inside values-xx or values-xx-xXX directory. For Japanese translation, the directory should be values-jp.
Why do I keep getting this "is translated but not found in default
local"
It means that you have one or more strings in values-xx but the strings didn't exist in your values directory.

Android localization for any region some country

I create folder values-ru (for any region). But with using Ukrainian language or Belarus i have an error.
android.content.res.Resources$NotFoundException: String resource ID #0x7f0d0037
Tell me, why i got an error. Does i must create values-ru-uk and etc. for all region?
You should define all your strings in the default (source) language, regardless of what translations you're adding.
These goes in: values/strings.xml.
If this is missing (or the string is missing in that file) then I expect that's why you get an error.
You can then add as many language files as you need: e.g:
values-uk/strings.xml. (Ukrainian)
values-be/strings.xml. (Belarusian)
or specific regions thereof: e.g:
values-ru-rUA/strings.xml. (Russian in Ukraine)
Disclaimer: I'm not an Android developer, but I've written localisation software that generates strings files.

Android Adding "values-en" folder causes "Couldn't resolve resource" warning

I have the next problem:
When I add a new folder called "values-en" and I move the strings.xml file from the default folder "values" to that "values-en", I always get the next error:
Couldn't resolve resource #string/my_string
I have cleaned the project and refresh and the warning is always there.
Is there any restriction where I must always have a strings.xml in the device folder "values"?
Someone has experimented the same?
Thanks in advance
You must have the values folder. To support multiple languages you can add the other values folders (values-en, values-fr, etc).
In the default values folder you declare your strings in your app's default language and in values-en the same strings but with their english translation.

Android one values folder for multiple languages

Is there a way to tag a strings resource folder with more than one language(values-en-es)?
My problem is that for Hebrew on some devices the language code "iw" and on others it is "he".
My current solution is to make two folders with the same content and only change their name
respectively.
I wonder if there is a more accurate way to do it?
Resource folder names can have multiple qualifiers but only one qualifier per type:
For example
values-en-rGB //Language + Region
is valid but
values-en-fr//Language + Language
is not valid, since it has multiple values for a single qualifier. So
values-iw-he
is not possible.
Source: Android Developers, Qualifier Name Rules.
However this doesn't mean you have to duplicate the files. Instead, you can create an Alias Resource.
Android Developers explains Alias Resouces like this:
Creating Alias Resources: When you have a resource that you'd like to use for more than one device configuration (but do not want to provide as a default resource), you do not need to put the same resource in more than one alternative resource directory. Instead, you can (in some cases) create an alternative resource that acts as an alias for a resource saved in your default resource directory.
For example, a String resource in one folder
<string name="app_name">My Awesome App</string>
can be referenced in another String resource in another folder as:
<string name="application_name">#string/app_name</string>
More about alias-resources on Android Developers.
You can make a File Link in eclipse, as described here.
So you have your values-iw/strings.xml with the real values and you make a File Link to that file in your values-he folder. This has the benefit that you do not have to edit 2 files, the linked 'file' gets updated automatically.

Android - reading out exsting locale values directories

I wonder if there is a way to read out the locale values of all existing values directories.
Let's say I've got the following directories under my res-Directory
[...]
values
values-de
values-nl
[...]
Now I need a method to get back the information that there is a locale of de and nl existing for the directory values.
Is there any way, if yes how?
Any help will be appreciated.
Regards,
Christian
Well, ideally, your app neither knows nor cares what resource sets you have. That is the whole point behind resource sets, after all -- to insulate your app from changes in resources.
That being said, one possibility is to write a script that is part of your build process that generates a file with your requested data (e.g., XML file containing the roster of resource sets) that you then read in at runtime.
Or, arrange to have a "magic value" in each set. For example, in res/values-de/strings.xml, you could have a lang_de string, and in res/values-nl/strings.xml, you could have a lang_nl string. Then, you can use reflection to iterate over your string resources and find those matching the lang_ pattern. This may be significantly slower than the first option, particularly if you have lots of string resources.
I know of no way to interrogate the system to find out what resource sets are defined.

Categories

Resources