如何扩展可用的Java语言环境列表 [英] How to extend the list of available Java Locales

查看:101
本文介绍了如何扩展可用的Java语言环境列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来向Java 1.6中提供的Locales添加更多Locales。但我想创建的语言环境没有ISO-3166国家/地区代码,也没有ISO-639语言代码。有什么办法可以做到这一点吗?我想添加的语言环境只在语言名称上有所不同,但是一个族群越小,他们对自己的身份就越挑剔; - )

I am looking for a way to add more Locales to the Locales available in Java 1.6. But the Locales I want to create do not have ISO-3166 country codes, nor ISO-639 language codes. Is there any way to do this anyways? The Locales I want to add only differ in the language names, but the smaller an ethnic group is, the more picky they get about their identity ;-)

所以我想关于扩展现有的Locale,类似于

So I thought about extending an existing Locale, something like

UserDefinedLocale extends Locale { 
   UserDefinedLocale (Locale parentLocale) {...}
}

但java.util.Locale是final,这使得它特别难以入侵周围的东西...

but java.util.Locale is final, which makes it especially hard to hack something around...

那么,Java Locales列表是否详尽无遗?我是第一个错过更多Locales的人吗?

So, is the idea that the list of Java Locales is exhaustive? Am I the first to miss some more Locales?

推荐答案

阅读 java.util Locale

它说:
使用此类中的构造函数创建一个Locale对象:

It says : "Create a Locale object using the constructors in this class: "

它还说:
因为Locale对象只是区域的标识符,构造区域设置时不执行有效性检查

It also says : "Because a Locale object is just an identifier for a region, no validity check is performed when you construct a Locale"

它还说:
区域设置是识别类型的机制你想得到的对象(NumberFormat)。语言环境只是一种识别对象的机制,而不是对象本身的容器

It also says : "A Locale is the mechanism for identifying the kind of object (NumberFormat) that you would like to get. The locale is just a mechanism for identifying objects, not a container for the objects themselves"

最后,javadoc对于getAvailableLocales()方法说:
返回的数组表示Java运行时环境和安装的LocaleServiceProvider实现支持的语言环境的联合

And finally, the javadoc for the getAvailableLocales() method says : "The returned array represents the union of locales supported by the Java runtime environment and by installed LocaleServiceProvider implementations"

所以你强制必须发明一个不在标准列表中的语言代码,并将其用作您的语言环境的标识符。

So you just have to invent a language code which is not in the standard list, and use it as an identifier for your locale.

这篇关于如何扩展可用的Java语言环境列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆