0

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.

Shakash3obd
  • 13
  • 2
  • 9

1 Answers1

4

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.

Daniel Lockard
  • 615
  • 3
  • 11
  • I think I liked this solution from the point of automating things depending on the system but is there anyway I can manually get to choose which file '/values-fr/strings.xml' or '/values/strings.xml' to use at the beginning of the application after the user decision the first launch? I will read the localization just in case even though I am not going to automate things since I am myself a multilingual but for some application I want them to be in Arabic rather than English like my entire phone. – Shakash3obd Jul 17 '12 at 18:20
  • Check out this then. http://stackoverflow.com/questions/6236052/how-can-i-change-language-of-my-application This tells you how to programmatically tell it which language to load. – Daniel Lockard Jul 17 '12 at 18:44
  • Thanks a lot Mr. Lockard, one last thing, what is the proper way to save whatever language the user choose as default so the application remember the chosen language? In my mind, I think I need to write the decision to a file and then every time the user open the application, I will have to check this file and set the language. But I think there must be a better or more professional way to do this? isn't it? – Shakash3obd Jul 17 '12 at 21:06
  • You'll want to store it in SharedPreferences. – Daniel Lockard Jul 17 '12 at 21:24