如何在java中验证语言环境?
问题描述:
我在应用程序中读取了一个指定语言代码的文件:
I read a file in an application that specifies a language code:
public void setResources(String locale) {
// validate locale
// ULocale lo = new ULocale(locale);
// System.out.println(lo.getDisplayCountry());
}
必须采用以下格式:< ISO 639语言代码> _< ISO 3166地区代码>
例如。 en_UK,en_US等。是否可以在继续之前验证语言环境字符串是否有效?
that must be in the format: <ISO 639 language code>_<ISO 3166 region code>
eg. en_UK, en_US etc. Is it possible to validate that the locale string is valid before continuing?
答
现在我这样做:
ULocale uLocale = new ULocale(locale);
if (uLocale.getCountry() != null && !uLocale.getCountry().isEmpty()) {
...
}
工作正常。