0

I want to make application in two languages. When the application starts, there will be two buttons: the first button for Language X and the second for English. When I click on one of the language buttons, the application should start with the corresponding language. But I don't know how to do it. Is it possible?

3
  • This is a very broad question. I suggest you look into Android's support for localization Commented Feb 21, 2013 at 22:16
  • It's possible. If you're wondering how exactly - the answer will be way too long for Stack Overflow. Familiarize yourself with the localization techniques on Android. Commented Feb 21, 2013 at 22:19
  • 1
    Is there any particular reason you want to offer the user the choice in your app instead of using the option they have already selected system-wide? The best practice is to use the language they are using for the rest of their phone, and Android provides simple ways to do so. Commented Feb 21, 2013 at 22:22

5 Answers 5

1

Changing the locale for your app can be done as follows:

private void setLocale(Locale locale) { Locale.setDefault(locale); Resources res = getContext().getResources(); DisplayMetrics dm = res.getDisplayMetrics(); android.content.res.Configuration conf = res.getConfiguration(); conf.locale = locale; res.updateConfiguration(conf, dm); } 

On top of that, you of course need to provide localized strings.xml at the bare minimum.

Without more details, though, I'd question why you want to do this. The user should select the language from Android's settings, and your app should follow the language of the device. This happens automatically--the system will pick the resources you provide that are qualified with a language.

I won't try to post a guide on how to provide localized resources here. Please refer to the Android documentation for details.

Sign up to request clarification or add additional context in comments.

Comments

0

when you click on one of the buttons you can set the new Locale('languageCode') in that button's setOnClickListener()

and then reinitialize the textual elements which will re-render in the correct locale

Comments

0

Here's my approach on this, to which for me easy to do.

Create a set of resources (drawables,strings,layouts,menus etc.) using language as a qualifier.

When your main activity starts with two buttons, in the call back methods of your click listeners of your buttons manipulate the locale there, I think the system will figure out what resources to use based on your qualifier which is a language.

Comments

0

Localization is always possible, but the same concepts apply on Android/Smartphones as they do on Computers. If the Phone itself is set to display in a certain language then your application should also display in that language. Your job as a developer is to ensure your solution and programming are Unicode compliant and handle the appropriate characters you might expect that may be unique to certain languages.

Comments

0

If you want to have different languagas you should better try to use different strings for each language you want. For example:

values/strings.xml values/strings-de.xml values/strings-sk.xml values/strings-pl.xml 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.