Shakash3obd
Shakash3obd

Reputation: 13

How to set language preferences for Android app?

I am developing an Android app in which the application can be used by any language but I want to set preferences for the language of the text showing in the app as labels or the text in the buttons.

So what I want to know how to do it is to include a 'Settings' in the menu in which the user can set a default language such as for now either English or Arabic then the entire application will only show text and labels and buttons with the language that has been specified. So when the user first download the application it will prompt for choosing a language then every time the application launch it will use the language specified at first or can change it from the setting in the menu.

I know how to add an item in the menu for an activity but what I don't know how to do it is to save the setting as preference and change all text in the app.

Upvotes: 0

Views: 3674

Answers (1)

Daniel Lockard
Daniel Lockard

Reputation: 615

What you should do is just let the phone decide the localization and then have the appropriate localization files in your project. The Android docs on localization should help. Basically what you're going to want to do is create several folders.

Your default folder strings.xml will be res/values/strings.xml, and then for say... French you're going to want to create res/values-fr/strings.xml. Then, if the phone is set to french it will load the strings from the values-fr folder, and if they are not found it will look in strings.xml in the res/values/ folder.

Upvotes: 4

Related Questions