ResourceBundle.GetBundle Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
GetBundle(String) |
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. |
GetBundle(String, Locale) |
Gets a resource bundle using the specified base name and locale, and the caller's class loader. |
GetBundle(String, ResourceBundle+Control) |
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. |
GetBundle(String, Locale, ClassLoader) |
Gets a resource bundle using the specified base name, locale, and class loader. |
GetBundle(String, Locale, ResourceBundle+Control) |
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. |
GetBundle(String, Locale, ClassLoader, ResourceBundle+Control) |
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. |
GetBundle(String)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
[Android.Runtime.Register("getBundle", "(Ljava/lang/String;)Ljava/util/ResourceBundle;", "")]
public static Java.Util.ResourceBundle? GetBundle (string? baseName);
[<Android.Runtime.Register("getBundle", "(Ljava/lang/String;)Ljava/util/ResourceBundle;", "")>]
static member GetBundle : string -> Java.Util.ResourceBundle
Parameters
- baseName
- String
the base name of the resource bundle, a fully qualified class name
Returns
a resource bundle for the given base name and the default locale
- Attributes
Exceptions
if the ResourceBundle
cannot be found.
Remarks
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader. Calling this method is equivalent to calling <blockquote> getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader())
, </blockquote>
Java documentation for java.util.ResourceBundle.getBundle(java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
GetBundle(String, Locale)
Gets a resource bundle using the specified base name and locale, and the caller's class loader.
[Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;)Ljava/util/ResourceBundle;", "")]
public static Java.Util.ResourceBundle? GetBundle (string? baseName, Java.Util.Locale? locale);
[<Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;)Ljava/util/ResourceBundle;", "")>]
static member GetBundle : string * Java.Util.Locale -> Java.Util.ResourceBundle
Parameters
- baseName
- String
the base name of the resource bundle, a fully qualified class name
- locale
- Locale
the locale for which a resource bundle is desired
Returns
a resource bundle for the given base name and locale
- Attributes
Exceptions
if the resource bundle cannot be found.
Remarks
Gets a resource bundle using the specified base name and locale, and the caller's class loader. Calling this method is equivalent to calling <blockquote> getBundle(baseName, locale, this.getClass().getClassLoader())
, </blockquote>
Java documentation for java.util.ResourceBundle.getBundle(java.lang.String, java.util.Locale)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
GetBundle(String, ResourceBundle+Control)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
[Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;", "")]
public static Java.Util.ResourceBundle? GetBundle (string? baseName, Java.Util.ResourceBundle.Control? control);
[<Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;", "")>]
static member GetBundle : string * Java.Util.ResourceBundle.Control -> Java.Util.ResourceBundle
Parameters
- baseName
- String
the base name of the resource bundle, a fully qualified class name
- control
- ResourceBundle.Control
the control that control the access sequence
Returns
a resource bundle for the given base name and the default locale
- Attributes
Remarks
Java documentation for java.util.ResourceBundle.getBundle(java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
GetBundle(String, Locale, ClassLoader)
Gets a resource bundle using the specified base name, locale, and class loader.
[Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;)Ljava/util/ResourceBundle;", "")]
public static Java.Util.ResourceBundle? GetBundle (string? baseName, Java.Util.Locale? locale, Java.Lang.ClassLoader? loader);
[<Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;)Ljava/util/ResourceBundle;", "")>]
static member GetBundle : string * Java.Util.Locale * Java.Lang.ClassLoader -> Java.Util.ResourceBundle
Parameters
- baseName
- String
the base name of the resource bundle, a fully qualified class name
- locale
- Locale
the locale for which a resource bundle is desired
- loader
- ClassLoader
the class loader from which to load the resource bundle
Returns
a resource bundle for the given base name and locale
- Attributes
Exceptions
if the ResourceBundle
cannot be found.
Remarks
Gets a resource bundle using the specified base name, locale, and class loader.
This is equivalent to calling: <blockquote>
getBundle(baseName, targetLocale, loader, control)
</blockquote> passing a default instance of Control
. Refer to the description of modifying the default behavior. The following describes the default behavior.
<b>"default_behavior">Resource Bundle Search and Loading Strategy</b>
getBundle
uses the base name, the specified locale, and the default locale (obtained from java.util.Locale#getDefault() Locale.getDefault
) to generate a sequence of "candidates"><em>candidate bundle names</em>. If the specified locale's language, script, country, and variant are all empty strings, then the base name is the only candidate bundle name. Otherwise, a list of candidate locales is generated from the attribute values of the specified locale (language, script, country and variant) and appended to the base name. Typically, this will look like the following:
baseName + "_" + language + "_" + script + "_" + country + "_" + variant
baseName + "_" + language + "_" + script + "_" + country
baseName + "_" + language + "_" + script
baseName + "_" + language + "_" + country + "_" + variant
baseName + "_" + language + "_" + country
baseName + "_" + language
Candidate bundle names where the final component is an empty string are omitted, along with the underscore. For example, if country is an empty string, the second and the fifth candidate bundle names above would be omitted. Also, if script is an empty string, the candidate names including script are omitted. For example, a locale with language "de" and variant "JAVA" will produce candidate names with base name "MyResource" below.
MyResource_de__JAVA
MyResource_de
In the case that the variant contains one or more underscores ('_'), a sequence of bundle names generated by truncating the last underscore and the part following it is inserted after a candidate bundle name with the original variant. For example, for a locale with language "en", script "Latn, country "US" and variant "WINDOWS_VISTA", and bundle base name "MyResource", the list of candidate bundle names below is generated:
MyResource_en_Latn_US_WINDOWS_VISTA
MyResource_en_Latn_US_WINDOWS
MyResource_en_Latn_US
MyResource_en_Latn
MyResource_en_US_WINDOWS_VISTA
MyResource_en_US_WINDOWS
MyResource_en_US
MyResource_en
<blockquote><b>Note:</b> For some Locale
s, the list of candidate bundle names contains extra names, or the order of bundle names is slightly modified. See the description of the default implementation of Control#getCandidateLocales(String, Locale) getCandidateLocales
for details.</blockquote>
getBundle
then iterates over the candidate bundle names to find the first one for which it can <em>instantiate</em> an actual resource bundle. It uses the default controls' Control#getFormats getFormats
method, which generates two bundle names for each generated name, the first a class name and the second a properties file name. For each candidate bundle name, it attempts to create a resource bundle:
<ul><li>First, it attempts to load a class using the generated class name. If such a class can be found and loaded using the specified class loader, is assignment compatible with ResourceBundle, is accessible from ResourceBundle, and can be instantiated, getBundle
creates a new instance of this class and uses it as the <em>result resource bundle</em>.
<li>Otherwise, getBundle
attempts to locate a property resource file using the generated properties file name. It generates a path name from the candidate bundle name by replacing all "." characters with "/" and appending the string ".properties". It attempts to find a "resource" with this name using java.lang.ClassLoader#getResource(java.lang.String) ClassLoader.getResource
. (Note that a "resource" in the sense of getResource
has nothing to do with the contents of a resource bundle, it is just a container of data, such as a file.) If it finds a "resource", it attempts to create a new PropertyResourceBundle
instance from its contents. If successful, this instance becomes the <em>result resource bundle</em>. </ul>
This continues until a result resource bundle is instantiated or the list of candidate bundle names is exhausted. If no matching resource bundle is found, the default control's Control#getFallbackLocale getFallbackLocale
method is called, which returns the current default locale. A new sequence of candidate locale names is generated using this locale and searched again, as above.
If still no result bundle is found, the base name alone is looked up. If this still fails, a MissingResourceException
is thrown.
"parent_chain"> Once a result resource bundle has been found, its <em>parent chain</em> is instantiated. If the result bundle already has a parent (perhaps because it was returned from a cache) the chain is complete.
Otherwise, getBundle
examines the remainder of the candidate locale list that was used during the pass that generated the result resource bundle. (As before, candidate bundle names where the final component is an empty string are omitted.) When it comes to the end of the candidate list, it tries the plain bundle name. With each of the candidate bundle names it attempts to instantiate a resource bundle (first looking for a class and then a properties file, as described above).
Whenever it succeeds, it calls the previously instantiated resource bundle's #setParent(java.util.ResourceBundle) setParent
method with the new resource bundle. This continues until the list of names is exhausted or the current bundle already has a non-null parent.
Once the parent chain is complete, the bundle is returned.
<b>Note:</b> getBundle
caches instantiated resource bundles and might return the same resource bundle instance multiple times.
<b>Note:</b>The baseName
argument should be a fully qualified class name. However, for compatibility with earlier versions, Java SE Runtime Environments do not verify this, and so it is possible to access PropertyResourceBundle
s by specifying a path name (using "/") instead of a fully qualified class name (using ".").
"default_behavior_example"> <strong>Example:</strong>
The following class and property files are provided: <ul> <li>MyResources.class <li>MyResources.properties <li>MyResources_fr.properties <li>MyResources_fr_CH.class <li>MyResources_fr_CH.properties <li>MyResources_en.properties <li>MyResources_es_ES.class </ul>
The contents of all files are valid (that is, public non-abstract subclasses of ResourceBundle
for the ".class" files, syntactically correct ".properties" files). The default locale is Locale("en", "GB")
.
Calling getBundle
with the locale arguments below will instantiate resource bundles as follows:
<table class="striped"> <caption style="display:none">getBundle() locale to resource bundle mapping</caption> <thead> <tr><th scope="col">Locale</th><th scope="col">Resource bundle</th></tr> </thead> <tbody> <tr><th scope="row">Locale("fr", "CH")</th><td>MyResources_fr_CH.class, parent MyResources_fr.properties, parent MyResources.class</td></tr> <tr><th scope="row">Locale("fr", "FR")</th><td>MyResources_fr.properties, parent MyResources.class</td></tr> <tr><th scope="row">Locale("de", "DE")</th><td>MyResources_en.properties, parent MyResources.class</td></tr> <tr><th scope="row">Locale("en", "US")</th><td>MyResources_en.properties, parent MyResources.class</td></tr> <tr><th scope="row">Locale("es", "ES")</th><td>MyResources_es_ES.class, parent MyResources.class</td></tr> </tbody> </table>
The file MyResources_fr_CH.properties is never used because it is hidden by the MyResources_fr_CH.class. Likewise, MyResources.properties is also hidden by MyResources.class.
Added in 1.2.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
GetBundle(String, Locale, ResourceBundle+Control)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
[Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;", "")]
public static Java.Util.ResourceBundle? GetBundle (string? baseName, Java.Util.Locale? targetLocale, Java.Util.ResourceBundle.Control? control);
[<Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;", "")>]
static member GetBundle : string * Java.Util.Locale * Java.Util.ResourceBundle.Control -> Java.Util.ResourceBundle
Parameters
- baseName
- String
the base name of the resource bundle, a fully qualified class name
- targetLocale
- Locale
the target locale of the resource bundle
- control
- ResourceBundle.Control
the control that control the access sequence
Returns
a resource bundle for the given base name and the default locale
- Attributes
Remarks
Java documentation for java.util.ResourceBundle.getBundle(java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Applies to
GetBundle(String, Locale, ClassLoader, ResourceBundle+Control)
Gets a resource bundle using the specified base name, the default locale, and the caller's class loader.
[Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;", "")]
public static Java.Util.ResourceBundle? GetBundle (string? baseName, Java.Util.Locale? targetLocale, Java.Lang.ClassLoader? loader, Java.Util.ResourceBundle.Control? control);
[<Android.Runtime.Register("getBundle", "(Ljava/lang/String;Ljava/util/Locale;Ljava/lang/ClassLoader;Ljava/util/ResourceBundle$Control;)Ljava/util/ResourceBundle;", "")>]
static member GetBundle : string * Java.Util.Locale * Java.Lang.ClassLoader * Java.Util.ResourceBundle.Control -> Java.Util.ResourceBundle
Parameters
- baseName
- String
the base name of the resource bundle, a fully qualified class name
- targetLocale
- Locale
the target locale of the resource bundle
- loader
- ClassLoader
the class loader to load resource
- control
- ResourceBundle.Control
the control that control the access sequence
Returns
a resource bundle for the given base name and the default locale
- Attributes
Remarks
Java documentation for java.util.ResourceBundle.getBundle(java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.