When using a Custom locale in android, the directory names are, for example
res/drawable-en-rUS
res/values-fr-rCA
where the -r specifies a region (country) in which that language is spoken.
What about when also specifying the regional variant? My client has asked that we support English, Chinese, and three (3) variants of Japanese. (*)
I set the locale using a customized Application class and code something like this:
locale = new Locale(lang, country);
Locale.setDefault(locale);
config.locale = locale;
mContext.getResources().updateConfiguration(config,mContext.getResources().getDisplayMetrics());
and am using resource directories named like this:
/res/drawable-en
/res/drawable-cx
/res/drawable-ja
/res/drawable-ja-rHI
/res/drawable-ja-rFU
While this works; the bottom two entries are hacks. I'm using imaginary country names to be the regions, when I actually need them to be something like
/res/drawable-ja-rJP-vHI
/res/drawable-ja-rJP-vFU
to specify the variant within Japan.
There's another Locale()
constructor, namely
Locale(String language, String country, String variant);
If I use this as
locale = new Locale("ja", "JP", "hi");
How do I specify the resource directories including language, region, and variant?
The best resource I've found on Providing Alternative Application Resources doesn't show how to do it.
(*) they've requested these Japanese variants:
The problem with this is that you can't specify variants as resource folders. From what I can tell, the only purpose for the variant
string is to be able to display it to the user. Honestly, I think your 'hack' is probably the best way to go about this.
Even if it were possible some other way, the variants you're using aren't really regional variants anyway, just different ways of writing the same thing. (Personally, I'm a big fan of mixed, but I still only know about 300 kanji, so that gets me in trouble sometimes... it's enough to get around on though!)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With