java message bundle - property file naming convention when using extensions or private use subtags?

184 Views Asked by At

What's the naming convention for message bundle property files when using extensions or private use subtags? For instance, if the locale is EN US, the property file lookup will be

message_en_US.properties

though, what if I need instantiate a local EN US and the private use subtag string is RandomTag. How do I name the file so GetBundle can find it? The API doc does not talk about how to deal with extensions

P.S: I realize RandomTag can be specified as a variant and I could just name the file message_en_US_RandomTag.properties but I would like to avoid this as we might use legitimate variants in the future as specified in the BCP-47 standards for locale

1

There are 1 best solutions below

0
iliyan On

(As of JDK 17 - https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ResourceBundle.Control.html#getCandidateLocales(java.lang.String,java.util.Locale))

It is impossible to use Locale extension to select a different property file from a Bundle because ResourceBundle.getBundle() method depends on ResourceBundle.Control.getCandidateLocales() to generate a list of the possible matches. That list is only based on combinations of the L(anguage), S(cript), R(region), and V(ariants) attributes of the target Locale. It does not include any provisions for E(xtensions)