Change locale in android app (onto Hindi) -
creating multi languages support app possibility change language in app settings.
as works fine english, spanish, franch, russian languages, doesn't work hindi , chineese.
1) specify language name in original language in app instead of हिन्दी can see "hindi".
\res\values-hi\arrays.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="languages"> <item name="english">english</item> <item name="russian">Русский</item> <item name="spanish">espagnol</item> <item name="russian">français</item> <item name="chineese">中国</item> <item name="hindi">हिन्दी</item> </string-array> <string-array name="languagesvalues"> <item name="english">en</item> <item name="russian">ru</item> <item name="spanish">es</item> <item name="russian">fr</item> <item name="chineese">zh-cn</item> <item name="hindi">hi</item> </string-array> </resources>
2) end after selecting "hindi" - default (english) being selected.
\res\values-hi\strings.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">लकी बीनने</string> <string name="score">0000</string> <string name="settings">सेटिंग</string> <string name="start_button">प्रारंभ</string> <string name="about_button">के बारे में</string> <string name="about">लियोनिद द्वारा बनाया गया</string> <string name="feedback">प्रतिक्रिया भेजें </string> <string name="high_score">उच्च स्कोर के</string> <string name="score_set">स्कोर निर्धारित किया गया है \r\nमें:</string> <string name="game_over">खेल खत्म</string>
....
saving locale in preferences.
public class settings extends preferenceactivity { locale mylocale; static boolean localechanged; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); addpreferencesfromresource(r.xml.preferences); // language changing preference langpreference = getpreferencescreen().findpreference( "language"); langpreference.setonpreferencechangelistener(languagechangelistener); } preference.onpreferencechangelistener languagechangelistener = new onpreferencechangelistener() { @override public boolean onpreferencechange(preference preference, object newvalue) { switch (newvalue.tostring()) { case "en": setlocale("en"); break; case "ru": setlocale("ru"); break; case "fr": setlocale("fr"); break; case "es": setlocale("es"); break; case "zh-cn": setlocale("zh-cn"); break; case "hi": setlocale("hi"); break; } localechanged = true; return true; } }; // * manually changing locale/ public void setlocale(string lang) { mylocale = new locale(lang); resources res = getresources(); displaymetrics dm = res.getdisplaymetrics(); configuration conf = res.getconfiguration(); conf.locale = mylocale; res.updateconfiguration(conf, dm); intent refresh = new intent(this, settings.class); startactivity(refresh); finish(); }
what wrong?
it depends on device. once check device supports hindi language going settings
--> language & input
.
Comments
Post a Comment