Android localization - How to use values folder -b qualifier - android

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

Related

Strings.xml is named in different ways

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).

"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 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

Set translated languages in application

The default language of my app is English and I translated it into German. But now if I want to export it as an signed application in Eclipse there comes many errors that all string are not translated in other languages like es, fr , it and so on.
How can I export my app as signed application with only two languages and ignore all other languages?
You don't need to translate your app if you don't want to. Just check that all strings are defined in the base values/ folder. Then you can create more values-XX/ folders with their own strings.xml with all of the strings (or just a fraction of them). Android will take the default string if it doesn't find the localised version of the string.
If you are not localising to other languages, make sure that their values folder are not defined. For example, if you are not localising to Spanish, make sure that you don't have the values-es/ folder in your res/ folder.
EDIT: Same topic solved: Lint: How to ignore "<key> is not translated in <language>" errors?

android localization doesn't work for some languages

I've created a values-he folder with strings.xml file identical to the default strings.xml with translated string values, but running the app both on a Hebrew selected real device and on a Hebrew selected AVD still shows the default English texts. Any ideas why?
EDIT: this was answered - in some cases, Hebrew included, some android devices support deprecated language codes. For Hebrew the old 'iw' code is still supported on some devices instead of 'he'.
This is known to be the case in some other languages.
From the Android Locale class it's said:
Note that Java uses several deprecated two-letter codes. The Hebrew ("he") language code is rewritten as "iw", Indonesian ("id") as "in", and Yiddish ("yi") as "ji". This rewriting happens even if you construct your own Locale object, not just for instances returned by the various lookup methods. Also some devices use he for hebrews too so to be compatible with use both values-iw and values-he
Starting Summer 2021 Google now requires you to upload the bundle (.aab) instead of the .apk file. With that change, if your device does not support a specific language, it will not be downloaded from the Play Store.
Check the solution here.

Categories

Resources