Android localization values-** folder names - android

I have seen several conflicting tables that show localizations and what names they should take
A lot of them suggest that there are versions of the language for each country, which is fine, for languages like English, Spanish and Chinese, where I can choose to make a values-en folder or a values-en_US folder if I want to make it more specific
but some other languages like greek have a locale name el_GR , can I just make a folder names values-el or does it HAVE to be values-el_GR
thats just an example and I don't trust the tables I have read, and the android developer guide does not nearly list the available locales

The folder name of Android string files is formatted as the following:
without region variant: values-[locale]
with region variant: values-[locale]-r[region]
For example: values-en, values-en-rGB, values-el-rGR.
In your case, you just need to create a folder values-el for the Greek translation, and values-el-rGR for the country-specific Greek translation.
Also, you can make use of the resources fallback mechanism in Android, to allow particular strings to be further translated locally.
For example, suppose you have a string called “R.string.title” and the locale is ‘el-GR’, Android will look for a value of “R.string.title” by searching the files in the following order:
res/values-el-rGR/strings.xml
res/values-el/strings.xml
res/values/strings.xml
Therefore, you can just put the country-specific translation inside the res/values-el-rGR/strings.xml, and let the res/values-el/strings.xml stores the general translations.
It can avoid duplicating your strings in different language files by utilizing this fallback mechanism.

Right click "res" folder in your project. Pick > New > Android resource file > Localization - and it will offer you all the possible Language and Locales options and even create required folders.

all can find in https://developer.android.com/index.html
in https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
the page descript multiple resouce define, like drawable , value
in https://developer.android.com/training/basics/supporting-devices/languages.html
the page provide Language res define,
it‘s import How Create Locale Directories and Resource Files .
the format is <resource type>-b+<language code>[+<country code>].
and the language code country code reference https://developer.android.com/reference/java/util/Locale.html
language
ISO 639 alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters (for future enhancements). When a language has both an alpha-2 code and an alpha-3 code, the alpha-2 code must be used.
You can find a full list of valid language codes in the IANA Language Subtag Registry (search for "Type: language").
https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
country (region)
ISO 3166 alpha-2 country code or UN M.49 numeric-3 area code. You can find a full list of valid country and region codes in the IANA Language Subtag Registry (search for "Type: region").
https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
Other reference: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

Related

What is the difference between country and region translation in android translations editor

I am currently translating my android app via the embedded translations editor of android studio. Within the locale menu, I could either choose a general language or a language/dialect connected to a specific country. For instance German (de) or German (de) in Austria (at) or German (de) in Belgium (Be) etc..
In case I would like to reach users in all Spanish speaking countries, is it enough to add just a general Spanish locale in my values-es folder or should I create a Spanish locale for each hispanophone country? The second option would not make sense to me, especially since the app is not that complex, that it has to support dialects or varieties.
In the Project, at the left side, select option Project Files, so one can see the directory structure of the current project.
Under the res directory, there is a folder values... for each desired language and country combination, and within each one there is a strings.xml file created. That files should contain all the words translated in the related language.
The simplest way is to initially create a general file with the Spanish language (es): it would be the values-es folder (created by right clicking mouse on the res directory, option, then new, Android Resource Directory and selecting the Spanish language.
After one should create a new empty strings.xml file, created under this new folder (value-es) Right mouse click in the new folder, select option new, Values Resource File, named it strings.xml.
This file will contain all the words in your app, under the common general structure, that should be in each strings.xml file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<-!--strings-->
</resources>
However, there are some cases that will be exceptions and you will need to create more specific files. Let's assume the one needs the app for Chile. So it to be created a new folder. Also use new, Android Resource Director, and choose Spanish and Chile. The new folder will be called values-es-rCL. Under this folder, one needs to create other empty Strings.xml with the above initial content.
This file will be almost empty
Howeever there are exceptions: savories is tapa in Spain, but in Chile is picoteos.
If default language is English put:
Under values folder in strings.xml:
savories
Under values-es folder in strings.xml:
tapas
Under values-es-rCL folder in strings.xml:
picoteos
So where appear savories, the app searchs in specific country (values-es-rCL), if it didn't find, it search in language (values-es),if it also didn't find, it search in default language (values)
For a normal word, like tap, it just necessary put the word grifo in spanish language, with no worry about chilean strings.xml
if someone needs to be compatible with Mexico, then it will be necessary to create strings.xml and the folder values-mx-rMX for this "dialect". local translatio for 'savories' is the word botanas

How to set custom name for android language directory?

I would like to have different directories for multiple languages. For example I have Kurdish language with 2 dialects - Badini and Sorani. But there are no specific regions for them in Android.
Can I name them customly for each region?
Correct dir naming for Kurdish but one dir for all regions - not desired
Inorrect naming but desired one
While building throws Error: Invalid resource directory name
Is it even possible ?
In one word NO,
According to google documentation To add support for more locales, create additional directories inside res/. Each directory's name should adhere to the following format:
<resource type>-b+<language code>[+<country code>]
After you’ve decided on the locales to support, create the resource subdirectories and files.
For example, values-b+es/ contains string resources for locales with the language code es. Similarly, mipmap-b+es+ES/ contains icons for locales with the es language code and the ES country code. Android loads the appropriate resources according to the locale settings of the device at runtime.
MyProject/
res/
values/
strings.xml
values-b+es/
strings.xml
mipmap/
country_flag.png
mipmap-b+es+ES/
country_flag.png
for more details follow the document language

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. How to use the same localizable messages for all the languages in a country?

My country (Spain) has several languages (es-ES, ca-ES, gl-ES, eu-ES). We won't add all the languages for now so we would like to use main language in Spain, i.e. Spanish (es). We would like to display the /values-es/strings.xml when the user has selected one of the other languages in the country. How can we do that?
Oh, and we would like to use English as the default language (/values/strings.xml).
It would be great to have something like /values-ES/strings.xml, but I suppose that can't be done because the first code should be the language code.
Now we are copying the /values-es/strings.xml file to the other folders (values-ca, values-gl and values-eu) but we'd like to avoid that.
I think that you should have only 2 folders with 1 strings.xml for each other:
res/values/strings.xml this resource will contains your text in English ;
res/values-es/strings.xml this resource will contains your text in Spanish .
When your app is installed on a device which is configured with the Italian language, it will use the file resource on case 1.
When your app is installed on a device which is configured with a Spanish language (and there are a lot of Spanish language out there, think about South America countries), it will use the file resource on case 2.
You can do it easily with Android Studio:
right-click on res folder
go to New > Android resource directory
a window will show you some options; pick Locale and then click on the button with those symbols "> >"
then on the Language list, pick es: Spanish and then click OK, as showed in the image below (note that by default the Specific Region Only has Any Region selected!)
By experience: I never faced up a Breton, Corsican or Provençal users claiming for a full translation of the application in their language (by default the app has English as default and French).
I would say you want to do something like this.
if (Locale.getDefault().getISO3Country().equals("ESP"))
{
Locale[] locales = Locale.getAvailableLocales();
for (Locale loc : locales)
if (loc.getISO3Language().equals("SPA"))
{
Locale.setDefault(loc);
break;
}
}
Note: I'm not sure if I got the ISO3 language and country codes right. And you'll also have to do something for the (rare?) situation that the es-ES locale is not available.
If you are trying to override Catalan with Spanish, you should probably have that in the values-ca/strings.xml file.
The way to do what you are asking is to provide the resources in the appropriate mobile country code resource folder, which takes precedence over language-region resources.
Assume that you have the following situation:
The application code calls for R.string.text_a
Two relevant resource files are available:
res/values-mcc404/strings.xml, which includes text_a in the application's default language, in this case English.
res/values-hi/strings.xml, which includes text_a in Hindi.
The application is running on a device that has the following configuration:
The SIM card is connected to a mobile network in India (MCC 404).
The language is set to Hindi (hi).
Android will load text_a from res/values-mcc404/strings.xml (in English), even if the device is configured for Hindi. That is because in the resource-selection process, Android will prefer an MCC match over a language match.
The MCC for Spain is 214.
(See Localization)
I found another tricky solution: hard links. Although it doesn't remove whole problem completely, at least it protects you from routine task of copying file across multiple directories or making equal changes in all existed files with risk of miss something.
But I must admit that there is some caveats:
1) Some IDE does not support working with hard links by-default. Intellij IDEA and Android Studio will break your hard links if you don't disable "safe write" option in settings.
2) Most version control systems also doesn't support hard links by default. Let's take git for example. It will break existing hard links after reverting or merging changes.
Currently, I'm using batch file for restoring hard links after they get broken by git.
In a general term, there should be only one strings.xml file under values folder containing the relevant data.
If we explicitly specify different values folder like values-ca,values-es, whenever there are setting changes in the android device, it will look to the particular folder and take the appropriate strings value.
If the requirement is keep uniform text means better have only values->strings.xml file alone with the required data.
But with this approach multilingual apk is not possible i.e. for other country different language is expected, there will be variations again. So wherever we need uniform language, lets go with single folder alone and wherever multilingual is preferred, we can have multiple values-es,values-ca folder like that.
Hope that helps
How about trying to set it in java, instead of using strings.xml.
As doing it programatically gives you more flexibility at run-time.
Configuration config = new Configuration(getResources().getConfiguration());
Locale locale = Locale.getDefault();
String country = locale.getCountry();
String language = locale.getLanguage();
if (country.equalsIgnoreCase("ES") && (language.equalsIgnoreCase("ca") || language.equalsIgnoreCase("gl") || language.equalsIgnoreCase("eu"))) {
locale = new Locale("es");
}
config.setLocale(locale);
And then you can simply have one /values-es/strings.xml for all the ES country languages.

What is "values" folder name for Danish Language?

I read the localization in Android. Here for we need to create different values's folder for each language.
for e.g.
res/values/strings.xml : Contains English text for all the strings that the application uses, including text for a string named title.
res/values-fr/strings.xml : Contain French text for all the strings, including title.
res/values-ja/strings.xml : Contain Japanese text for all the strings except title.
Now I want to give support for Danish language then what should I name to value's folder ?
For Danish, you got to use values-da folder.
Edit: It turns out, according to this post that it is values-da.
Plus, according to the Android Locale class documentation:
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.
The variant codes are unspecified.
For Danish generally, you would want to use res/values-da/strings.xml.
To have strings specific to a country as well as a language you would use res/values-da-rDK/strings.xml for Denmark, res/values-da-rGL/strings.xml for Greenland, res/values-da-rDE/strings.xml for Germany (there being a sizable Danish-speaking community in Southern Schleswig along with a few elsewhere in Germany), res/values-da-rFO/strings.xml for the Faroe Islands, and so on. You can even have something like res/values-da-rFR/strings.xml as while there isn't a large Danish-speaking population in France, nothing stops you doing something like that anyway.
You can mix these, e.g. being specific to country only for a handful of values, falling back to res/values-da/strings.xml for everything else.
Via http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes, you would use res/values-da/strings.xml.
Android value's folder is following the locale naming specified by ISO-639-1.
Danish language, according to the standard, have the locale da, so your folder will be values-da.
The same rule applies to all languages.
Reference: http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Categories

Resources