i want to change my app string language, when language from settings is changed.
Like, right now it's english. When I siwtch to hindi language from settings, the text in my android app should also be in hindi.
How to do that?
Create values-xx
where "xx"is any language code like "en", "fr", "sp", "ar" .... and so on
create an xml with name of string.xml
in the same folder.
create string in that xml
<string name="welcome">write in the language which you put as the language code</string
You shoul this site: http://developer.android.com/guide/topics/resources/localization.html
You must create values folders in res folder for localization.And you must create string.xml in your values folders. For example:
values-tr for Turkish
values-fr for French
values-hi/strings.xml
<string name="welcome">स्वागतम</string>
<string name="email">ईमेल पता</string>
<string name="password">पासवर्ड</string>
<string name="login">लॉगिन</string>
<string name="signup">खाता नहीं है? साइन अप करें</string>
use
Locale.getDefault().getLanguage();
to get the device language for your device.(e.g en)
then make a switch to swap between ur "string" Values in ur app.(values/string.xml)
reference: Get the current language in device
quote:
Locale.getDefault().getLanguage() ---> en
Locale.getDefault().getISO3Language() ---> eng
Locale.getDefault().getCountry() ---> US
Locale.getDefault().getISO3Country() ---> USA
Locale.getDefault().getDisplayCountry() ---> United States
Locale.getDefault().getDisplayName() ---> English (United States)
Locale.getDefault().toString() ---> en_US