Android Strings.XML Regional file overrides language file? - android

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.

Related

How to know if Android resolved to use a localized strings.xml file or the default one?

The motivation of this question comes from this other question:
How do I get the current language my app is in? (Not the device's language as specified in the Settings. I want the language that Android resolved to use for my app).
This question has been asked several times on the site, but it fails to consider this corner-case:
Imagine the user has only one preferred language in his device: say German, for example.
My app two strings.xml files: The default one, and one in French (values-fr/strings.xml).
Obviously, Android will resolve to use the default strings.xml in this case.
But if I do any of the following, it will return German:
Locale.getDefault()
getResources().getConfiguration().getLocales().get(0)
getResources().getConfiguration().locale.
(And many other suggestions that I have found on the site)
And who told Android that the default strings.xml file was in German? Why did it made that assumption? The default file could be in Spanish, Italian, Polish...whatever.
Ideally, I would like a method that returns null in this case. Some method that tells me that no match was found for German and Android had to fall-back to the default strings.xml.
Does such method exist?
Put the language name in both strings.xml files. For example, as languageName.
When you get the string for R.string.languageName, it will be the language chosen by Android among the ones you support.
Those functions all return the phone's locale. They have nothing to do with resource localization. So nobody said the strings.xml file was German. The user set the phone to German, and the resource subsystem decided strings.xml was the best match for that. Basically you have the way it works backwards.
I don't think there is a way to get what you want for two reasons:
1)It's supposed to be transparent to the programmer.
2)It doesn't pick one file over the other. It picks independently for each string. So if you have a strings.xml with two strings A and B, and had a german strings file with only A, it would give you the german A and the default B.

How to Properly Support English when Localizing an App?

I'm working on localizing an Android app.
For arguments sake, let's say the app will support English, Albanian, and Bengali.
Currently all English strings are listed in the "default value" column of the translations editor:
Apps on the app store generally state what locales they support.
I'm assuming when you submit an app that either a person or machine verifies your claims... so...
Is it necessary to explicitly add English (en) locale/column in addition to the default values (just as Albanian and Bengali have been added in the photo) in order for the app to be considered to officially "support" English?
You do not have to add English locale to have it in Supported Language menu. Check documentations out.
When your Java code refers to strings, the system would load strings from the default (en_US) resource file, even if the app has Spanish resources localized under es_ES. This is because when the system cannot find an exact match, it continues to look for resources by stripping the country code off the locale. Finally, if no match is found, the system falls back to the default, which is en_US.
The system would also default to en_US if the user chose a language that the app didn't support at all, like French.
Default locale is en_US.
No.
Apps on the app store generally state what locales they support.
If you are talking about Apple's App Store, Google Play won't list the supported languages in similar fashion.
However, you can localize the store listing page. According to play console help, If a user's language preference matches the translation languages you've added, they'll see your app's translated version. You can also add localized graphic assets for your store listing pages. See this for more. This feature is similar to App Store's metadata localization.
There is an easy solution to your problem.
Just find the path in your project:
res/
and add a folder named:
values-en
Then add a file named:
strings.xml
Finally, it will look like this:
res/values-en/strings.xml
And the resources in it will show when the user's language setting is English.

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

Android localization independent from phone language settings

I have a bunch of localized strings.xml files as good located in values-XX folders.
Definetely, I know how to localize my app dependently from phone language settings. It is easy, right? Just change phone language settings, and Android will takestrings.xml linked to picked language.
In my case I should to allow to user pick preferable language, in application settings.
So, I want to know. Is it possible to keep my current R.string.<anything> everywhere, is it possible to say to Android : "hey! I need to use strings.xml from values-EN folder (for example)?"

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

Categories

Resources