Resource directory name for language variant?

When using custom locale in android, directory names, e.g.

res/drawable-en-rUS res/values-fr-rCA 

where -r indicates the region (country) in which the language is spoken.

How about when the regional option is indicated? My client asked us to support English, Chinese, and three (3) variants of Japanese. (*)

I set the locale using a custom application class and code like this:

 locale = new Locale(lang, country); Locale.setDefault(locale); config.locale = locale; mContext.getResources().updateConfiguration(config,mContext.getResources().getDisplayMetrics()); 

and use 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 use imaginary country names to be regions when I really need them to be something like

 /res/drawable-ja-rJP-vHI /res/drawable-ja-rJP-vFU 

to indicate an option in Japan.

There is also a Locale() constructor, namely

Locale(String language, String country, String variant);

If I use it like

locale = new Locale("ja", "JP", "hi");

How do I specify resource directories, including language, region, and variant?

The best resource I have found on Providing alternative application resources does not show how to do this.

(*) they requested these Japanese options:

  • only hiragana
  • hiragana with furigan over kanji
  • normal with kanji + hiragana
+4
source share
2 answers

The problem is that you cannot specify options as resource folders. From what I can say, the only purpose for the variant string is to show it to the user. Honestly, I think your β€œhacking” is probably the best way to do this.

Even if it were possible in some other way, the options that you use are not really regional options, just different ways of writing the same thing. (Personally, I am a big fan of mixed ones, but I still only know about 300 characters, so sometimes I have problems ... it's enough to get around, though!)

+2
source

The goal of Locale Variant is to provide additional options, such as different sorting or another option (for example, Norwegian). It was not intended for what you use it for.
Of course, if I had such requirements as yours, I would just try to load the whole set of resources (keeping Locale). However, it is not so simple. And of course, maintenance would be a nightmare.

+1
source

All Articles