When your program needs a 地元の-明確な/細部 資源, such as
String
for example, your program can 負担 it from the
資源 bundle that is appropriate for the 現在の 使用者's 地元の. In
this way, you can 令状 program code that is 大部分は 独立した・無所属 of
the 使用者's 地元の, which 孤立するs most, if not all, of the
地元の-明確な/細部 (警察などへの)密告,告訴(状) in 資源 bundles.
This 許すs you to 令状 programs that can:
- be easily localized, or translated, into different
languages.
- 扱う 多重の 地元のs at once.
- be easily 修正するd, later, to support even more 地元のs.
One 資源 bundle is, conceptually, a 始める,決める of 関係のある services
that supports XResourceBundle
. Each 関係のある service of
XResourceBundle
has the same base 指名する 加える an
付加 構成要素 that identifies its 地元の. For example, suppose
your 資源 bundle is 指名するd MyResources
. The first
service you are likely to 器具/実施する is the default 資源 bundle,
which has the same 指名する as its family--MyResources
. You
can also 供給する as many 関係のある 地元の-明確な/細部 services as you need.
For example, perhaps you would 供給する a German one 指名するd
MyResources_de
.
Each 関係のある 実施 of XResourceBundle
含む/封じ込めるs
the same items, but the items have been translated for the 地元の
代表するd by that XResourceBundle
実施. For
example, both MyResources
and MyResources_de
may have a String
that is used on a button for
確認するing 操作/手術s. In MyResources
the
String
may 含む/封じ込める 承認する
and in
MyResources_de
it may 含む/封じ込める Gut
.
If there are different 資源s for different countries, you
can make specializations: for example, MyResources_de_CH
is the German language (de) in Switzerland (CH). If you only want to
修正する some of the 資源s in the specialization, you can do so.
When your program needs a 地元の-明確な/細部 反対する, it 負担s
the XResourceBundle
実施 using the
XResourceBundleLoader service:
XResourceBundle myResources = xLoader.getBundle("MyResources", currentLocale);
The first argument 明示するs the family 指名する of the 資源
bundle that 含む/封じ込めるs the 反対する in question. The second argument
示すs the 願望(する)d 地元の. getBundle
uses these two
arguments to 建設する the 指名する of the ResourceBundle
subclass it should 負担 によれば the に引き続いて specifications.
The 資源 bundle lookup searches for services with さまざまな
suffixes on the basis of (1) the 願望(する)d 地元の and (2) the 現在の
default 地元の as returned by 地元の.getDefault(), and (3) the root
資源 bundle (baseclass), in the に引き続いて order from lower-level
(more 明確な/細部) to parent-level (いっそう少なく 明確な/細部):
baseclass + "_" + language1 + "_" + country1 + "_" + variant1
baseclass + "_" + language1 + "_" + country1
baseclass + "_" + language1
baseclass + "_" + language2 + "_" + country2 + "_" + variant2
baseclass + "_" + language2 + "_" + country2
baseclass + "_" + language2
baseclass
For example, if the 現在の default 地元の is en_US, the
地元の that the 報知係 is 利益/興味d in is fr_CH, and the
資源 bundle 指名する is MyResources; 資源 bundle lookup
will search for the に引き続いて services, in order:
MyResources_fr_CH
MyResources_fr
MyResources_en_US
MyResources_en
MyResources
The result of the lookup is a service, but that service may be
支援するd by a 所有物/資産/財産 とじ込み/提出する on disk. If a lookup fails,
getBundle()
throws a
MissingResourceException
.
The base service must be fully qualified (for
example, myPackage::MyResources
, not just
MyResources
).
資源 bundles 含む/封じ込める 重要な/value pairs. The 重要なs uniquely
identify a 地元の-明確な/細部 反対する in the bundle. Here is an
example of a XResourceBundle
実施 that 含む/封じ込めるs
two 重要な/value pairs:
class MyResource 延長するs com.sun.星/主役にする.資源.XResourceBundle
{
// some queryInterface stuff
// ...
public final 反対する getDirectElement(String 重要な)
{
if (重要な.equals("okKey")) return "Ok";
if (重要な.equals("cancelKey")) return "取り消す";
return null;
}
}
重要なs are always String
s. In this example, the 重要なs
are OkKey
and CancelKey
. In the above
example, the values are also String
s--承認する
and 取り消す
--but they do not have to be. The values can
be any type of 反対する.
You retrieve an 反対する from 資源 bundle using the appropriate
get method. Because OkKey
and CancelKey
are both strings, you use getByName
to retrieve them:
button1 = new Button(myResourceBundle.getByName("OkKey").getString());
button2 = new Button(myResourceBundle.getByName("CancelKey").getString());
The get methods all 要求する the 重要な as an argument and return
the 反対する if 設立する. If the 反対する is not 設立する, the get methods
throw a ::com::sun::星/主役にする::コンテナ::NoSuchElementException.
NOTE: You should always 供給(する) a base service
with no suffixes. This will be the class of "last 訴える手段/行楽地" if a
地元の is requested that does not 存在する. In fact, you must 供給する
all of the services in any given 相続物件 chain for which
you 供給する a 資源. For example, if you 供給する
MyResources_fr_BE, you must 供給する both
MyResources and MyResources_fr, or the
資源 bundle lookup will not work 権利.
You do not have to 制限する yourself to using a 選び出す/独身 family of
ResourceBundle
s. For example, you could have a 始める,決める of
bundles for exception messages, ExceptionResources
(ExceptionResources_fr
, ExceptionResources_de
, ...),
and one for widgets, WidgetResource
(WidgetResources_fr
,
WidgetResources_de
, ...); breaking up the 資源s however you like.