java - Trouble with language localization in Android. Application doesn't load necessary resourses from strings.xml -
java - Trouble with language localization in Android. Application doesn't load necessary resourses from strings.xml -
i have application can localized many languages. have 1 big trouble. have default file values/strings.xml store string in english language default , have folder values-uk/strings.xml (for ukrainian localization). saving selected localization in sharedpreferences. problem when application starts without selected language preference (but scheme language of device ukrainian, checked) app must load ukrainian strings values-uk/strings.xml, loads english language values values/strings.xml. can explain me why happens , how can solve problem. give thanks much!
i had same problem. followed many tutorials. , have used localization in android application indian language. have @ code snippet.
@override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement //sharedpreferences.editor edit=getsharedpreferences("pref",mode_private).edit(); switch (id){ case r.id.action_assamese: setlocale("as"); homecoming true; case r.id.action_bihari: setlocale("bh"); homecoming true; case r.id.action_english: setlocale("en"); homecoming true; case r.id.action_gujarati: setlocale("gu"); homecoming true; case r.id.action_hindi: setlocale("hi"); homecoming true; case r.id.action_kannada: setlocale("kn"); homecoming true; case r.id.action_kashmiri: setlocale("ks"); homecoming true; case r.id.action_malayalam: setlocale("ml"); homecoming true; case r.id.action_marathi: setlocale("mr"); homecoming true; case r.id.action_oriya: setlocale("or"); homecoming true; case r.id.action_sanskrit: setlocale("sa"); homecoming true; case r.id.action_tamil: setlocale("ta"); homecoming true; case r.id.action_telgu: setlocale("te"); homecoming true; case r.id.action_urdu: setlocale("ur"); homecoming true; } homecoming super.onoptionsitemselected(item); } public void setlocale(string lang) { locale 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, mainactivity.class); startactivity(refresh); finish(); } more details can follow [this][1] tutorial. i hope may help you.
java android xml string localization
Comments
Post a Comment