What languages are supported by android for localization with their respective values folder name, the best link i could find was http://developer.android.com/reference/java/util/Locale.html
any body can help me with more languages what if we need to support more languages then listed above.
My app uses the following undocumented languages, and they work:
ca Catalan
el Greek
es Spanish
pl Polish
pt Portuguese
ro Romanian
ru Russian
sv Swedish
More generally, it should be the string in the "639-1" column of this table.
I suggest use the list of the ISO 639-1 standard
Virtually any language defined by the Strings representing the language code (as specified by ISO 639-1) and (optionally) country (as defined by Alpha 2 representation of ISO 3166-1). You can specify only the language (i.e. "en") or the language used specifically in one area (i.e. "en","US"). You do not need to use the constants (though convenient) that come with Locale.
// This is to get spanish locale of Spain
Locale spanish = new Locale("es", "ES");
The problem is not only specifying the correct languages, but also assuring that the mobile phone supports literals/formatting for the indicated Locale. I.e. a mobile phone sold in Spain will support "es" and "es_ES", almost surely "en" and "en_US" too and probably "ca_ES", "ba_ES" and "gl_ES". It is not likely that it will support for example "es_AR" or "zh_CN". So I think that the answer to your question is "it depends on the market of your application".
Related
From a question received privately:
I'm currently creating an Android app and one of the requirements is that it supports a second language. I've Googled the language codes but I'm not finding the one that I need; could you tell me if you support the Welsh language, which is a place in the United Kingdom? And if so, what is the country code for it?
That would be on Android’s side, not on the IDE side, to support; the resources are bundled within the APK itself and you should put localised strings in a localised values folder within the res/ folder. For example:
res/
values/ # Default locale (e.g., American English)
values-en-rGB/ # British English
values-it/ # Italian (any country)
In general, localisations on Android are defined as 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). Wales is not an independent country, but is part of Great Britain, and as such there is no ISO code for Wales as a region. But, there is a Welsh language code! So you should be able to localise your app by putting your Welsh strings in the res/values-cy or res/values-cy-rGB. The former will be used on all devices that are set to Cymraeg, regardless of the country they’re set to; the latter is specific to devices in Welsh with the country set to Great Britain. For Welsh, the two things are essentially the same, since there aren’t variations of it outside the UK, but this mechanism can be used for example to differentiate Traditional Chinese (zh-rTW) from simplified Chinese (zh-rCN).
For more details on how localisation works on Android, I recommend referring to the Localisation guide on the Android Developers website: https://developer.android.com/guide/topics/resources/localization
For the list of supported ISO languages and countries, you can refer to the Wikipedia: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for the countries, and https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes for the languages.
I translate my apps to Portuguese language. After users asking for Portuguese translation despite it's already translated, i can see it's translated when i change my device's language to Portuguese, i thought maybe i need to pt-rBR folder, but it does not help either.
I asked users to send their device language, image or screenshot of the app, but after multiple tries and few weeks none of them replied back.
Does anyone experience the same issue with Portuguese? I really can't figure out why it happens, i tried on 3 devices and both work fine. I also translated to Spanish, and Spanish is spoken in various countries too, haven't got any issues.
All the Portuguese strings (works for other resources too) should go to values-pt/strings.xml you should only use values-pt-rPT and values-pt-rBR if you have specific localizations for Portugal and Brazil respectively, otherwise (and in terms of simple localizations) they should share most elements.
Spanish is the same, you have values-es and then values-es-rES for Spain specifically, but various other Spanish-speaking countries, e.g.: values-es-rAR for Argentina and so forth.
French: values-fr or values-fr-rCA for Canada, etc.
Source: https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
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").
I'm working on an application that has localized strings for the UK, specified in res/values-en-rGB/strings.xml. My default string implementations, for the US, are in res/values/strings.xml.
Now, I'm adding additional localizations for Canada in res/values-en-rCA/strings.xml. I would like the application to behave as follows: If a user's device is localized to Canada (or their language is set to English(Canada) or French(Canada)), check if we have a string in en-rCA, and if not, fallback to the string in my default strings.xml file. However, my application currently fallbacks to strings from en-rGB when the device is set to a Canadian locale and the string is not found in en-rCA. Therefore, I have two questions:
How can I configure my app such that a device with a Canadian locale searches for a string in en-rCA and then, if it cannot find it, defaults to the string in my default values folder rather than en-rGB?
How can I ensure that a device whose language is set to French (Canada) defaults to en-rCA rather than my default values, as it currently does?
I would be happy to provide an example if it would be helpful. Thanks!
Finale Update:
After opening a bug report on Google Incorrect resource resolution strategy above Android N, defaulting to en_GB and not default strings.xml, they mentioned that this in the intended behaviour for Android N above. en_UK is considered "a representative of International English". The strings will fall back to "International English" strings or its representative before going to default en strings. I'm quoting their reply here:
Starting in N, all English locales (except for US and US territories like Puerto Rico and American Samoa) fall back to some International English variant if such a locale is available.
So for en-CA, we would try these locales first, before falling back on en-GB (which is considered a representative of International English if there is no better International English locale): en-rCA (Canadian English), b+en+001 (International English), en (English).
If you don't want en-GB strings to be picked up for en-CA, you should put resources in one of those three directories, as they would be considered a better match for en-CA.
Update 1:
It seems this is not just limited to en_CA. There is another similar question for other English locales : Android 7.0 Nougat picks up default strings when device language is en_US. Looks like a platform bug at this stage.
Original Answer:
Not sure if its a bug or a feature. From API level 24 (Android 7.0), they've updated how Android resolves strings as mentioned Improvements to Resource-Resolution Strategy
. Taking an example from the documentation below:
Before Android 7.0:
Lets say if the user has settings of fr_CH and following are the resources available in the app i.e de_DE, es_ES, fr_FR, it_IT. For older API's before Android 7.0, Android tried to find an exact match and if an exact match isn't found it defaults to the values/strings.xml, i.e en. So for en_CA case, if a string is not found in res/values-en-rCA/strings.xml, we can expect it to default to en.
After Android 7.0
However now in Android 7.0 and above, for the situation of fr_CH, it will fall back to the closest parent dialect i.e fr_FR.
Applying the same logic to the situation of en_CA and en_GB present in the app, I'm thinking that Android thinks that en_GB is the closest dialect to en_CA and is falling back to it instead of the default en first. I am facing the issue in my app and that's the only plausible explanation I can come up with of why this issue happens only on newer API versions and not on the ones before Android N.
Should happen automatically, without you doing anything. If you have values/strings.xml, values-en-rGB/strings.xml and values-en-rCA/strings.xml with the GB and CA versions containing only those strings that differ from the baseline (values/strings.xml) and if the user has his locale as en-CA, the system will load strings from values-en-rCA/strings.xml if not found, it'll fall back to values/strings.xml, the GB version wouldn't come in the picture.
For this you'll have to locally change your app locale. Basically you get the current locale, if it is fr-CA, you manually set the locale to en-CA
Locale enCALocale = new Locale("en", "CA");
Locale.setDefault(enCALocale);
Configuration config = new Configuration();
config.locale = enCALocale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
Update
As Shobhit mentioned, starting Android N, you can now have a list of locales selected in the setting and you can decide their priority:
In the above case the system will try and look for en-rCA/strings, if not found it'll look into en-rGB/strings instead of baseline, something that happened before N.
http://developer.android.com/reference/java/util/Locale.html
What is the difference for example between
Locale FRENCH vs Locale FRANCE
and
Locale GERMAN vs Locale GERMANY
I am searching, but I can't find the anything about the difference in the documentation. Any idea?
French and German are spoken in more countries than just France and Germany. In different countries they will have different currencies, different ways of writing numbers, etc. That's why you can indicate both the language & region of your locale, and that's why you can define specific resources for each language/region-combination (e.g. de-DE for Germany vs de-AT for Austria, or fr-FR for France vs fr-rCA for Canada).
One refers to a geographic area (and its conventions, such as using commas or decimal points in numbers), the other to a language.
For example, French could be spoken in France or Canada.
A Locale contains:
language code
country or region code (optional)
optional variant code (optional)
Therefore there are multiple predefined Locale objects for the same language. Some with Countrycode and some just with the language.
See: java.sun.com/developer/technicalArticles/J2SE/locale for more details
In the below link the documentation mentions creating "res/values-fr/strings.xml" for French translations and "res/values-ja/strings.xml" for Japanese translations. However, I couldn't find a list of all the acceptable path formats for all languages. I assume Italian would be "res/values-it/strings.xml", but it would be great if someone knew where this is documented.
http://developer.android.com/guide/topics/resources/localization.html
I assume Italian would be "res/values-it/strings.xml"
Yes, it is. The resource system uses the ISO3166-1 two letter country codes. See TelephonyManager.
Taken from Android docs:
The language codes are two-letter lowercase ISO language codes (such as "en") as defined by ISO 639-1. The country codes are two-letter uppercase ISO country codes (such as "US") as defined by ISO 3166-1.