How to show Locale List based on the Resource availability - android

I am developing an application that fetches all the system available locales and show in a listview to be selected by user to change the application language(just like android's language change option).
But I have a few res/values folder in my application resources like values (default), values-bn, values-zh, values-ar. SO I want these 4 languages to be shown in the list. How can I do this? I need to do this programmatically.
Suppose, I have 4 folders values, values-bn, values-en, values-zh
Then I only show,
Bengali
English
Chinese

OK, so what you want to do is have four languages: English, Bengali, Chinese, and Arabic, have I got that right? (Your question is internally inconsistent so it's hard to tell).
And you want to have a set of fallback values for when a string is missing in one of those four languages. The fallback values are in English, although the system won't know or care about that.
So what you want to do is put the strings for the four languages in the values-en, values-bn, values-zh, and values-ar directories and the fallback strings in the values directory.
In fact, since your fallback strings are in English, you could just put them in the values directory and have an empty resources file in the values-en directory. English would still show up in the list.
But why not just put the English versions of the strings in the values-en directory?

Related

Android app language localization

I have developed an app. Now I want to support other regional languages in it. But now the app is almost ready, changing each java file to set the texts in the textview for the corresponding language is a big pain. Is there any other simple way to do that? Like making a different string.xml file and doing some stuff, then all the views will get changed???
Create alternative resources
A large part of localizing an app is providing alternative text for different languages. In some cases you also provide alternative graphics, sounds, layouts, and other locale-specific resources.
An app can specify many res// directories, each with different qualifiers. To create an alternative resource for a different locale, you use a qualifier that specifies a language or a language-region combination. (The name of a resource directory must conform to the naming scheme described in Providing Alternative Resources, or else your app cannot compile.)
Example:
Suppose that your app's default language is English. Suppose also that you want to localize all the text in your app to French, and most of the text in your app (everything except the app's title) to Japanese. In this case, you could create three alternative strings.xml files, each stored in a locale-specific resource directory:
res/values/strings.xml Contains English text for all the strings
that the app 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.
If your Java-based code refers to R.string.title, here is what happens at runtime:
If the device is set to any language other than French, Android loads title from the res/values/strings.xml file.
If the device is set to French, Android loads title from the res/values-fr/strings.xml file.
Notice that if the device is set to Japanese, Android looks for title in the res/values-ja/strings.xml file. But because no such string is included in that file, Android falls back to the default, and loads title in English from the res/values/strings.xml file.
If you properly used resource references (like R.string.hello) You can create another language configuration and it should be properly loaded. If you "hard coded" strings within JAVA code with literals like "hello world" You have quite a bit of refactoring to do.

Android localization resources

I have just finished developing an android application that I was asked to make. I had also planned to translate it in different languages; below you can see the tree of the folders/files:
Inside strings.xml there are all the values that I am using inside the classes and they are all in Italian, my language (Here you can see an example if needed). I'd like to be able to translate all those fields in English and french as well.
I have read this article -> http://developer.android.com/training/basics/supporting-devices/languages.html
From what I have understood, I'd have to create a folder called values-fr with a strings.xml inside (it will have the same values names, but different translations).
QUESTION
I would like to be able to support English and Italian as well, but I don't understand how to manage the folders. Could you please tell me which option is the correct?
Inside the folder values use strings.xml with Italian (my language) strings. Then create another folder called values-en and, like I did before, create strings.xml with English values
Inside the folder values use strings.xml with English strings. Then create another folder called values-it and then, create strings.xml with Italian values
I guess that the point 2 is the correct solution but I'm not sure. The folder values has English as default language?
Thanks for the attention.
Technically speaking both are valid. values/ is the fallback if a more specific qualifier is not found. There is no written rule that enforces you in having the English strings in values/. It just makes a little more sense to have the English as fallback since it easier to find foreigners that speak English rather than Italian

Different languages for different localizations

I am developing an application, that has both English and Russian language. I want my application to be in Russian for countries of former USSR and English for other countries.
The solution I was thinking about: to put the same files as in values-ru folder into values-xx localizations folders, where I want Russian to be the default language. The same thing to do with English: to copy files from values-en to values-xx (here values-xx are localization folders of those countries, where I want English to set as default language).
I doubt, that this is a correct solution. Is there a better and shorter solution for my task?
You can use the values (with no county specifier) folder to place your resources in English; this will be your default language configuration. Then you can add Russian resources to the specific countries you want (i.e. the ex-USSR countries) like you say.
First of all, you can copy only string.xml from "values-ru" folder. Other localization automatically take strings from default "values" folder. You don't need to copy English version.

android localization resource chooser

I have an android application on eclipse it's text-views and the buttons' texts on Arabic language , I want to localize my application to both Arabic and English users .
Firstly under res folder I have created another folder and named it values-en .
I let the original folder values as is it and later I will use it for Arabic .
My first question it is necessary to create another folder (values-ar) for Arabic localization issues.
Or original values folder is just enough?.
Secondly
On values-en folder I created strings.xml file and added the following statement to it
COMTAS
I set the text of one of the textviews from resource chooser so choose application-title .
after that the textview's text converted to #string/application-title.
the project gives me the following message
NOTE: This project contains Java compilation errors, which can cause rendering failures for custom views. Fix compilation problems first.
Can someone explains to me how to make localization in simple steps.
And how I can retrieve textviews' texts either in english or arabic (reading from values folder)?
First: Leaving a strings.xml in the "values" folder will cause this language to be "default" (or rather "fallback") language.
Second: The text is read automatically from the strings.xml placed in the values-folder matching your System Locale (the locale you get when you call Locale.getDefault()), e.g. if system locale is set to english, the values are taken from values-en folder. Therefore it would be wise to place the arabic values in a values-ar folder.
I can't say anything related to your compile errors as you didn't post the code causing the error.
It's always good to follow the documentation. Here is the link for Localizing with Resources.
Create a values-ar folder for the arabic language, and let the default language as english. Why?
Whenever the application runs in a locale for which you have not provided locale-specific text, Android will load the default strings from res/values/strings.xml.
So if your application is running on a device set to Spanish language, it would still load arabic language (if it's set as default).
English is a most talked language, which would be better to let english by default, ant let the arabic language in values-ar(in my humble opinion).
Hope this helps you.

Android Strings.XML Regional file overrides language file?

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.

Categories

Resources