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/drawabl开发者_如何学Ce-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:
- hiragana only
- hiragana with furigana above the kanji
- normal with kanji + hiragana
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!)
The purpose of Locale Variant is to provide additional options like different sorting or different language variant (which is the case of Norwegian). This was not designed for what you are using it for.
Certainly, if I had requirements like yours, I would simply try to load the whole different resource set (preserving Locale). It is nowhere near the easy task, though. And of course the maintenance would be a nightmare.
精彩评论