Strings.xml is named in different ways - android

I would like to know the difference between the following
values-b+de
and
values-de

These both folders are used for localization. The way that you have implemented both values folder will be select the country code of the "de" language.
In values-b+de folder you are passing the language code as null so it will select the default language code and in values-de you are the call for default language code.
Creating the directory, the format is as below.
<resource type>-b+<language code>[+<country code>]
For more details, you can go to this link

Actually there is not difference between them as you write them.
The values-b convention was introduced in Android 7 (API level 24) in order to Improve the resource-resolution strategy as mentioned here:
https://developer.android.com/guide/topics/resources/multilingual-support.html#postN
And here also:
https://developer.android.com/training/basics/supporting-devices/languages.html#CreateDirs
Example:
For Spanish in general you will have resources in values-b+es folder.
But if you want these resources to make influence only for Spanish in Latin america you will have to place you're resources in values-b+es+419 (which was values-es-rUS in the old convention).

Related

Android localization - How to use values folder -b qualifier

android resources folder values. What is the values**-b** option i read about here?
What i want to do is have my app support two different languages, french and spanish. But i had a thought. it would be much more organized if instead of doing strings-es.xml and strings-fr.xml if i could do this:
values-es
|
Strings.xml
values-fr
|
Strings.xml
this way if there is any other things that should be localized they can easily go into the respective folders. Is this possible ?
The synax of -b+ allows you to include the script of the language, for languages that use multiple script like Serbian, whilst the old method don't allow this.
The default format that Android uses (as of 7.1) is as following:
values-sr is Serbian in the Cyrillic script
values-b+sr+Latn is Serbian in the Latin script
It is known as a BCP 47 language tag. BCP 47 documentation
Using '-b' is a newer way of supporting locales. You can support locales using the method you indicate above, but you can also support locales by putting them in directories like this:
values-b+es/strings.xml
values-b+fr/strings.xml

"values-in-rID" resources folder android stands for what?

App i am working on supports Indonesian locale, I do have
"values-in"
"values-in-rID"
resource folders.Both contains strings only.
I didn't find any info regarding "values-in-rID". i can see its getting used here too in android sdk
values-in means Indonesian Locale, and in all regions.
values-in-rID means Indonesian Locale, but applies only in the region of Indonesia. The r here means region.
The following screenshot should make things clear.
These are language and locale codes. For example, French in France is not entirely the same as French in Canada, so you might see fr-FR and fr-CA used to differentiate them instead of just using fr.
Android has a resource fallback mechanism that uses this folder naming pattern. Imagine your app has language resources for French(France) in a folder values-fr-rFR, resources for French(Switzerland) in a folder values-fr-rCH and resources that are the same for France and Switzerland in a folder values-fr. For the app locale French(Switzerland) Android will first attempt to load resources from the values-fr-rCH folder and then fall back to values-fr. See here for further details.
So, the folder values-in-rID contains resources for usage in Indonesian as spoken/written in Indonesia. Whether this approach makes sense for Indonesian or not I don't know: it certainly does if a variant of Indonesian is used outside of Indonesia. Anyway, make sure to provide a set of default resources as well as your Indonesian resources, as described here.

Android localization resources

I have just finished developing an android application that I was asked to make. I had also planned to translate it in different languages; below you can see the tree of the folders/files:
Inside strings.xml there are all the values that I am using inside the classes and they are all in Italian, my language (Here you can see an example if needed). I'd like to be able to translate all those fields in English and french as well.
I have read this article -> http://developer.android.com/training/basics/supporting-devices/languages.html
From what I have understood, I'd have to create a folder called values-fr with a strings.xml inside (it will have the same values names, but different translations).
QUESTION
I would like to be able to support English and Italian as well, but I don't understand how to manage the folders. Could you please tell me which option is the correct?
Inside the folder values use strings.xml with Italian (my language) strings. Then create another folder called values-en and, like I did before, create strings.xml with English values
Inside the folder values use strings.xml with English strings. Then create another folder called values-it and then, create strings.xml with Italian values
I guess that the point 2 is the correct solution but I'm not sure. The folder values has English as default language?
Thanks for the attention.
Technically speaking both are valid. values/ is the fallback if a more specific qualifier is not found. There is no written rule that enforces you in having the English strings in values/. It just makes a little more sense to have the English as fallback since it easier to find foreigners that speak English rather than Italian

Android localise strings to es_US

I am trying to localise strings to es_US (Spanish in US).
I have string resources in folder values-es-rUS and language on device is set to EspaƱol (Estados Unidos), Locale.getDefault() returns es_US.
Even when everything seems to be correct, app doesn't pick up strings from values-es-rUS but it falls to values.
Did someone make it work?
EDIT: Solved. Can't mark my answer as accepted now.
Problem was in gradle build file configuration. I use resConfigs "en", "es" so build can exclude other resources. It seems that "es" excludes also "es_US".
When I changed it to resConfigs "en", "es_US" it started to work
Folder should be placed in res/values-es_rUS
strings.xml files must have same names in all strings localized
*
From here (table 2 - section 2)
Language and region
The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r").
The codes are not case-sensitive; the r prefix is used to distinguish the region portion. You cannot specify a region alone.
This can change during the life of your application if the user changes his or her language in the system settings. See Handling Runtime Changes for information about how this can affect your application during runtime.
See Localization for a complete guide to localizing your application for other languages.
Also see the locale configuration field, which indicates the current locale.
http://developer.android.com/guide/topics/resources/localization.html
I'm sure you've looked at this, but it has everything you need on it. I followed the instructions step by step and was able to localize my strings.
Perhaps you named your values folder incorrectly? That would be my guess

Android Strings.XML Regional file overrides language file?

I am trying to localize my app and have a few doubts. i have translate strings in spanish language and i am trying to be very specific with Region codes, so I named the folders as values-es_rES, values-es_rUS and values-es_rMX. Now there are more countries and users who like to use spanish language so i created a generic values-es folder.
I am wondering can android automatically push all mexico, US and Spain users to respective languages under their region codes and can others like chile, peru will be shown values-es language rather than my default US English?
You have two options
Use the language-region locale (ie. es_ES for Spanish/Spain or es_PE for Spanish/Peru)
Use MNC/MCC codes in your resource folders, which will take presence over the locale ones.
The way you have described it, all users with a defined locale of es_XX (any region) will go to your "values-es" folder, but the US user will not, unless the US user has configured "es_US" as their locale.
Take a look at Table 2 at
http://developer.android.com/guide/topics/resources/providing-resources.html
Remember that if an asset is missing from "es_ES" it will get it from "es", so only change those that are different.

Categories

Resources