I have made a project in which I am using different language’s xml,like language_hi.xml,language_en.xml. so according to documentation I have made different folder for my each xml. For example for language_hi.xml I have made es/values-hi for language_en I have made res/values-en and in my each xml the string name is same,is there any way to select language_en.xml on one button click and language_hi.xml on another event.
this is my xml
res/values-hi/language_hi.xml
<string name="hello">sachit</string>
<string name="app">colon</string>
res/values-en/language_en.xml
<string name="hello">astro</string>
<string name="app">dev</string>
You can select the
Localeto use at runtime; for example, setting it to English will result in the values from theres\values-en\...folder being used.To do this, the following code is necessary:
However, I strongly recommend against using this. When a user runs an app, they expect it to either be in the default language (which in many cases is English), or their localized language. Giving someone an app in Hindi, for example, when they are in Russia, is really no good.
Keep in mind, that if you are using
enfor your entire app, getting a value fromlanguages_hi.xmlis incredibly difficult and, really, should not be done in any situation. An application should be the same language throughout, or it will begin to confuse the user (with the exception of apps that handle translations between languages). However, if you are interested in doing this (for whatever esoteric reason), you should review this answer.PS: I assume you know this, but I should mention it anyway. Any strings in the
res\values\...folder are used if the locale which the phone uses is not specified usingres\values-xx\.... You can find information on this here.