In this tutorial we are going to learn how to include string localization in android apps to make these mulit-language supported. As we all now android is very popular operating system in whole world and if we are going to develop any app and want this app to spread all around the world then we must include this multi-language support in our app. Android also provide localiation for other resources like graphics and audios but it this tutorial we are going to learn only string localition to support multi-languges in our apps.

In this article i will cover languages arabic,Deutsch,Portuguese and Hindi . you can take an idea from this and can include many more languages as you wants.

Android String Localiation Concept

Android by deffault considers English as primary language and loads the string resources from res ⇒ values ⇒ strings.xml and if we wants to add multi-language support, we need to create a values folder by appending an Hyphen and the ISO language code. For example if we want to add support for Arabic, we have to create a values folder named values-ar and keep a strings.xml file in it with all the strings translated into Arabic language.

well, if we depth string localization works as follows

  •  When any user changes the device language through Settings ⇒ Language & Input, android OS itself checks for appropriate language resources in the app. (Let’s say user is selecting Arabic)
  •  If the app supports selected language, android looks for it’s string resources in values-(ISO language Code) folder in the project. (For Arabic it loads the string values from values-ar/string.xml)
  •  If the supported language strings.xml misses any string value, android always loads the missing strings from default strings.xml file i.e values/strings.xml

So it is necessary to use all the string in values/strings.xml and the use thier reference in xml files or when ever you wants to show text on your screen layout. you must need to avoid hard coded strings in your app java code and layout xml files.

you can see the example below

Always declare the string in values/strings.xml file like this

and use this in xml files like this

in java code

never use below methods

Android Studio Project

Create a new android studio project and move to res->layout  folder of your project and paste below code to activity_main.xml

now move to res->values and paste below code in

For just learning I am using one string Hello World! but if you are developing app you need to put all the string in this file if you wants your app to support multi-language support properly. Hard coded string in xml and java code will not be translated.

Above activity_main.xml will create a layout like below one

english

Now you need to create values folders for different localoations to support multi-language in your app like below onestrings

above there

values->strings.xml for English

values-ar->strings.xml for Arabic

values-de->strings.xml for Deutsch

values-hi->strings.xml for Hindi

values-pt->strongs.xml for Portuguese

 

for Arabic move to values-ar->strings.xml file to paste below code

rbic

remember you need to translate every string in values/strings.xml file as i am using one Hello World!  i have translated this.

values-de->strings.xml

desu

values-hi->strings.xml

values-pt->strongs.xml

pur

after you are done with above methods just need to run the code and you can test this it will work perfectly as working in above vedio.

 

You can also download source code from here:MultiLanguageApp

you can add as many resource value folder by appending IOS language codes

ISO language codes

 

Language Locale values/strings.xml
German de values-de/strings.xml
Chinese zh values-zh/strings.xml
Czech cs values-cs/strings.xml
Dutch nl values-nl/strings.xml
French fr values-fr/strings.xml
Italian it values-it/strings.xml
Japanese ja values-ja/strings.xml
Korean ko values-ko/strings.xml
Polish pl values-pl/strings.xml
Russian ru values-ru/strings.xml
Spanish es values-es/strings.xml
Arabic ar values-ar/strings.xml
Bulgarian bg values-bg/strings.xml
Catalan ca values-ca/strings.xml
Croatian hr values-hr/strings.xml
Danish da values-da/strings.xml
Finnish fi values-fi/strings.xml
Greek el values-el/strings.xml
Hebrew iw values-iw/strings.xml
Hindi hi values-hi/strings.xml
Hungarian hu values-hu/strings.xml
Indonesian in values-in/strings.xml
Latvian lv values-lv/strings.xml
Lithuanian lt values-lt/strings.xml
Norwegian nb values-nb/strings.xml
Portuguese pt values-pt/strings.xml
Romanian ro values-ro/strings.xml
Serbian sr values-sr/strings.xml
Slovak sk values-sk/strings.xml
Slovenian sl values-sl/strings.xml
Swedish sv values-sv/strings.xml
Tagalog tl values-tl/strings.xml
Thai th values-th/strings.xml
Turkish tr values-tr/strings.xml
Ukrainian uk values-uk/strings.xml
Vietnamese vi values-vi/strings.xml

 

Shares

Leave a Reply

Your email address will not be published. Required fields are marked *