- Multi Language Support To Android App
- Objective:
- Step 1 Colors.xml file
- Step 2 Drawable Directory
- Step 3 string.xml
- Step 4 Make More for each language
- Step 5 activity_main.xml file
- Step 6 MainActivity.Java file
- Jay Poojara
- Android Building Multi-Language Supported App
- 1. How String Localization Works
- Don’ts:
- 2. Creating New Project
- 3. Testing The Other Languages
- 4. Android Localization Language ISO Codes
- 5. Translation Services
Multi Language Support To Android App
To download the code, login with one of the following social providers.
Login Login
Be patient. we are fetching your source code.
Objective:
Android is one of the popular Mobile OS which is being used by millions of users over 190 countries and it is increasing day by day. So when you are targeting global audience, it will be beneficial if you make your app localized.
While localizing, you should think about text, audio, currency, numbers and graphics depending upon the region or country. But in this tutorial language is covered only.
We will make simple login application.
Before going into this you should care about this things.
- Whenever you are making any android application, Always declare text you want to use in your application in strings.xml only. For Example While referring it in layout file
- When defining the string through java code, use R.string
It would be easy to edit and to translate your app into multiple language.
How String Localization Works?
By default android considers English as primary language and loads the string resources from res >> values >> strings.xml . When you want to make Multilanguage supported app, you need to create a values folder by appending a Hyphen (-) and the ISO language code. For example for French, values-fr named folder should be created and keep a strings.xml file in it with all the strings translated into French language.
In brief it works as follows:
- When user changes the device language, android OS itself checks for proper language resources in the app.
- If the app supports selected language, android looks for it’s string resources in values-(ISO language Code) folder in the project.
- 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
To Create new Project:
open File >> New >> Android Application Project
Step 1 Colors.xml file
Add following colors into values >> colors.xml file
Step 2 Drawable Directory
Create Following drawable under drawable directory
bg_button_rounded.xml
bg_form_rounded.xml
Bg_gradient.xml
Step 3 string.xml
Open strings.xml from values directory.
Paste following strings into values >> strings.xml files. These are default English text.
Step 4 Make More for each language
Now as we discussed earlier about localization mechanism, Create new folder under res folder named values-hi, values-fr, values-de.
Deutsch values-de >> strings.xml
Hindi values-hi >> strings.xml
French values-fr >> strings.xml
Step 5 activity_main.xml file
Now paste below code into activity_main.xml file
Step 6 MainActivity.Java file
Now, Paste following code into MainActivity.java file
To know more about Locale class please refer:
To know more about Configuration class please refer:
Now, run the project. You will see app in English (Assuming your device language is English).
Now for testing with other languages
- Go to Settings >> Language & Input
- Select the Language and choose the language that you supported in the app
Hindi
French
Deutsch
I hope you find this blog post very helpful while working with Multi language support to Android App. Let me know in comment if you have any questions regarding Multi language supported Android app. I will reply you ASAP.
Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.
Jay Poojara
I am dedicated and very enthusiastic Android developer. I love to develop unique and creative apps and also like to learn new programing languages and technology.
Источник
Android Building Multi-Language Supported App
Android is one of the few popular mobile operating systems having millions of users over 190 countries and growing day by day. So when you are aiming your app to be globally successful, it is always a good idea to make the app localized.
While localizing, you should consider using appropriate text, audio, currency, numbers and graphics depending upon the region or country. But this tutorial only covers localizing strings i.e supporting multiple languages. Localizing with Resources explains about other things should be considered when localizing your app.
In this article we are going to build a Multi-Language supported app that supports French, Deutsch (German), Hindi and Japanese.
VIDEO DEMO
1. How String Localization Works
By default android considers English as primary language and loads the string resources from res ⇒ values ⇒ strings.xml. When you want to add support for another language, you need to create a values folder by appending an Hyphen and the ISO language code. For example if you want to add support for French, you should create a values folder named values-fr and keep a strings.xml file in it with all the strings translated into French language.
In brief the localization works as follows
1. When 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 French)
2. If the app supports selected language, android looks for it’s string resources in values-(ISO language Code) folder in the project. (For french it loads the string values from values-fr/string.xml)
3. 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 mandatory that the default stings.xml file should contains all the string values that app uses. Other wise the app will crash with Force Close error.
While you are supporting multiple languages, you should consider below as a best practice while defining the strings. Always declare the string in strings.xml only.
When referring it in xml, use @strings notation.
When defining the string through java code, use R.string
Don’ts:
Never hard code the string in xml or in java code which make the translation difficult.
So let’s create a new project and try with an example.
2. Creating New Project
1. Create a new project in Eclipse by going to File ⇒ New ⇒ Android Application Project and fill the required information.
2. Add following colors in colors.xml located under values. If you don’t see colors.xml, create a new file and add the below colors.
3. Under drawable folder create three files named bg_button_rounded.xml,bg_form_rounded.xml, bg_gradient.xml with following contents. These files are not related to language support, but just to give nice gradients background and rounded corners to buttons, input boxes.
bg_button_rounded.xml
bg_form_rounded.xml
bg_gradient.xml
4. Open strings.xml located under values folder and add following strings. These are default English language strings.
5. Now under res folder create three folders named values-de, values-fr, values-hi, values-ja and a strings.xml file in each of the folders.
Your project should look like this once you created the required files/folders.
Now translate the strings into respected languages and place them in appropriate strings.xml files.
Deutsch values-de/strings.xml
Hindi values-hi/strings.xml
Japanese values-ja/strings.xml
6. Open your main activity layout file (in my case activity_main.xml) and add the following content to create a simple layout. This layout contains a title and a login form.
7. Open your MainActivity.java and make sure that it has following code. This code will be added automatically when you create new project.
Now if you run the project you should see the app in English (assuming that your device is set to English language)
3. Testing The Other Languages
In order to see the app in other languages follow below steps or check the above demo video.
1. On the device go to Settings ⇒ Language & Input
2. Select the Language and choose the language that you supported in the app.
4. Android Localization Language ISO Codes
Below table give you ISO languages codes for all the languages that android supports.
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 |
5. Translation Services
Right now I used Google Translate service to translate the strings into other languages. But if you want more accurate and meaningful translation always go for professional services like Professional translations through Google Play
Finally Localization Checklist gives you list of things to be verified before the app goes live when localization considered.
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk: [email protected]
Источник