Im facing a problem where I have an array that contains words in english, for example:
Array = ["Apple", "Orange", "Banana"]
What I want is that if the user doesn't use English as primary language, for example instead Swedish, I want the array to be translated to that language using the strings.xml provided translations. So that the array becomes this instead:
Array = ["Äpple", "Apelsin", "Banan"]
With Xcode I could just use .localized after the array but I couldn't find similar function in Android studio. Anyone that has a good solution for this?
Greetings, Pontus.
I need to convert my android app from English Language into Arabic Language,
but the database inside the APK is encrypted.
Anyone know what to do?
You should add new string in value with new name ex:
Strings-en.xml
Strings-ar.xml
and translate all value in your string file
I want to convert language codes to their display forms (with their native letters). For example:
Need to convert these language codes :en, ru, it, ja
Result should be this list:
English, Русский, Italiano, 日本語
How to do that?
The Locale class should do what you want.
getCountry() will give you a country code, for which you can obtain the name via getDisplayName().
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
I get a response from a webservice that will return several language codes (ISO 639-2) as options. I now want to translate those into a human understandable word.
For example:
eng-> English
ger -> German
fre -> French
How would you translate those words. Should I be using the strings.xml? But how will I get the Resource ID of those words?
Thanks a lot
You can convert 639-2 codes to 639-1 code using answer for this question
and after you get a 2 letter code construct Locale object and use getDisplayLanguage method