localization - Not able to read strings from region specific folders in Android -
i trying override locale configuration in app. but, not able differentiate between language , regions.
i trying following code override locale.
getting locale override.
example : "de_de", "de_at"
public static locale getlocalefromstring(@nonnull final string locale) { string[] split = locale.split("_"); if (split != null || split.length > 1) { string language = split[0]; string country = split[1]; return new locale(language, language, country); } return locale.getdefault(); }
the structure of resource folders is:
values/strings.xml (default strings) values-de-rde/strings.xml values-de-rat/strings.xml
if, define values-de/strings.xml, application start reading folder. means locale overriding works in app, how android system not able read string region specific folders.
(my device language english.)
any appreciated.
the arguments passed location's constructor may wrong:
second should country , third should variant.
so getlocalefromstring
should this:
public class mainactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); resources res = getresources(); displaymetrics dm = res.getdisplaymetrics(); configuration conf = res.getconfiguration(); conf.locale = getlocalefromstring("de_de"); res.updateconfiguration(conf, dm); setcontentview(r.layout.activity_main); } public static locale getlocalefromstring(@nonnull final string locale) { string[] split = locale.split("_"); if (split != null || split.length > 1) { string language = split[0]; string country = split[1]; return new locale(language, country); } return locale.getdefault(); } }
Comments
Post a Comment