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
Related
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
I am using Assets files as help files in my app and have well over a dozen. I am porting the app to multiple languages. Where do the alternative language asset files go?
I am already using the "res/values" directories for language files (values, values-es, etc) for use within the app. I thought the "Assets" directory was for help files and items like that.
I am trying to NOT muddy my values folders with the many help files that I am including and was using "activity.getAssets().open( file )" to read the files.
Also, some of these "Asset" files are different language pictures.
Can you put the files in /res instead of /assets? This has built in support for multiple languages, there is an easy to follow guide here.
Basically, if your original text is in /res/values/strings.xml, for example, you would put your translations in /res/values-{ISO LANGUAGE CODE}/strings.xml
For example, your French translation would be in /res/values-fr/strings.xml.
Android will pick the appropriate translation file according to the locale of the user's phone.
There are some good explanations of the other differences between /res and /assets here.
For the voice recognition in my app (using Vosk) I have defined the specific asset folder as resource string.
I.e. values\strings.xml contains:
<resources>
<string name="language_directory">vosk-model-small-en-us-0.15</string>
...
and values-de-rDE\strings.xml contains:
<resources>
<string name="language_directory">vosk-model-small-de-0.15</string>
...
So I can access the asset directory via
val assets = Assets(activity)
val assetDir = assets.syncAssets()
val modelDir = activity.getString(R.string.language_directory)
recognitionListener.model = Model("$assetDir/$modelDir")
This way the correct directory is always chosen based in the active locale.
In my case, those are located at models\src\main\assets\sync\<language_directory>
Make folder in assets:
1. htmlpagesNL
2. htmlpagesUS
Copy file from htmlpagesNL and paste to htmlpagesUS and Translate
Use url inside Nl string file:
file:///android_asset/htmlpagesNL for NL translation
Use url inside Us string file:
file:///android_asset/htmlpagesUS for US translation
Support different languages
Support different languages and cultures
Each time I create values_enu folder under res folder in eclipse for localization issue I get an error invalid resource directory name
http://developer.android.com/training/basics/supporting-devices/languages.html
Can someone help please.
One thing that wasn't clear to me from the docs is what a directory should be called in case of language variants, e.g. British/American English or German/Austrian German.
So even though the locales are of form en_GB, en_US, de_DE or de_AT etc, the corresponding folders should be called
res/values-en-rGB/
res/values-en-rUS/
res/values-de-rDE/
res/values-de-rAT/
That means keep the letter capitalization but use only hyphens instead of underscores and add an r before the language variant.
Use hyphen(-) instead of underscores(_)..
values-en is valid and values_en is invalid
You only should write "values-en".
The syntax is: FOLDERNAME MINUS 2-CHARACTER-LANGUAGE-KEY
Another example:
drawable-es <<= this will create a folder for Spanish picture files. It could be useful for implementing a labeled button you have created in photoshop or gimp.
I want to change the language of a my application according to the default language of the device in which the app is installed.
For example: if the default language of the device is French, the user will use the app in French.
I've tried to search for a solution, but probably I don't understand how to do that. Anyone can help me? Every help will be gretly appreciated.
To add support for more languages, create additional values directories inside res/ that include a hyphen and the ISO country code at the end of the directory name. For example, values-es/ is the directory containing simple resourcess for the Locales with the language code "es". Android loads the appropriate resources according to the locale settings of the device at run time.
Create the resource subdirectories and string resource files. For example:
MyProject/
res/
values/
strings.xml
values-es/
strings.xml
values-fr/
strings.xml
Where fr = french
And in /values-fr/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title">Mon Application</string>
<string name="hello_world">Bonjour le monde !</string>
</resources>
Source = Multi language
use qualifiers on your strings i believe fr is for france. So if you have a resource folder called values-fr, then anyone with french on their phone will get the french string file located in that folder and everyone else will get the string file in the values folder (without the -fr qualififer)
You can use qualifiers in all kind of resources of your app. You can for example, have a different layout depending on user language (it's useful on japanese or arabic language).
http://developer.android.com/guide/topics/resources/localization.html
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