Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change language dynamically using androids multilanguage support?

Is there are way to switch between different languages within an app using androids multilanguage support (values-de folder for german and value-en folder for english)?

like image 890
M.E. Avatar asked Jan 09 '11 12:01

M.E.


People also ask

Which of the following is used to support multiple languages in Android?

xml , which holds your string values. Supporting different languages goes beyond using locale-specific resources.

Can Android Studio automatically translate your app into other languages?

In the Translation Editor, click the globe-icon to add a new language file, in our example we will add 'de' (German) and 'es"(Spanish). You may need to close and re-open the Translation Editor tab after adding a new language if it does not show up immediately.


1 Answers

This is not really supported but possible by changing the Configuration object's "locale" field [Google Groups Post]

Configuration c = new Configuration(getResources().getConfiguration());
c.locale = Locale.GERMAN;
getResources().updateConfiguration(c, getResources().getDisplayMetrics());

Note that this alone will only effect future strings, not ones already displayed on the screen. You'd want to do this from a different activity than your main one, then finish your main one and restart it. This is hacky. See Post from Hackborn

like image 53
Kevin TeslaCoil Avatar answered Oct 15 '22 17:10

Kevin TeslaCoil