Java resource bundle file name


















This is unfortunately not possible if the jar is embedded in an executable file by Launch4j and such The property file doesn't have to be inside a JAR. If the class is in a package a. From the JavaDocs for ResourceBundle. Nick Holt Nick Holt Specify the class at basename property of loadBundle tag. Community Bot 1 1 1 silver badge. Jeyan Jeyan 1 1 gold badge 10 10 silver badges 23 23 bronze badges.

This will require all your resource bundles to be uniquely named! John John 1, 2 2 gold badges 22 22 silver badges 32 32 bronze badges. Supporting UTF-8 breaks for. This comment is incorrect. UTF-8 has a variable number of bytes and is the right answer for internationization - which is the point of using ResourceBundles. See this related question and associated accepted answer. Prashant Rajput Prashant Rajput 1 1 silver badge 3 3 bronze badges. Buhake Sindi Subba Reddy Subba Reddy 5 5 silver badges 6 6 bronze badges.

Angsuman Chakraborty Angsuman Chakraborty 21 1 1 bronze badge. JanaVish JanaVish 43 4 4 bronze badges. JorgeEsteban JorgeEsteban Can you provide more information about your answer? Sign up or log in Sign up using Google. Other strings designate application-defined formats. Refer to the note on the cache lookup below.

This step is iterated over all combinations of the candidate locales and formats until the newBundle method returns a ResourceBundle instance or the iteration has used up all the combinations. For example, if the candidate locales are Locale "de", "DE" , Locale "de" and Locale "" and the formats are "java. Locale format Locale "de", "DE" java. If a bundle has been found that is a base bundle a bundle for Locale "" , and the candidate locale list only contained Locale "" , return the bundle to the caller.

If a bundle has been found that is a base bundle, but the candidate locale list contained locales other than Locale "" , put the bundle on hold and proceed to Step 6. If a bundle has been found that is not a base bundle, proceed to Step 7. If the method returns a non-null locale, it becomes the next target locale and the loading process starts over from Step 3.

Otherwise, if a base bundle was found and put on hold in a previous Step 5, it is returned to the caller now. Otherwise, a MissingResourceException is thrown. At this point, we have found a resource bundle that's not the base bundle. If this bundle set its parent during its instantiation, it is returned to the caller.

Otherwise, its parent chain is instantiated based on the list of candidate locales from which it was found. Finally, the bundle is returned to the caller. During the resource bundle loading process above, this factory method looks up the cache before calling the control. If the time-to-live period of the resource bundle found in the cache has expired, the factory method calls the control.

If reloading is required, the factory method calls control. If control. Such dummy resource bundles are under the same expiration control as specified by control. All resource bundles loaded are cached by default.

Refer to control. The following is an example of the bundle loading process with the default ResourceBundle. Control implementation. Conditions: Base bundle name: foo. Messages Requested Locale : Locale. Messages", Locale. Next, getBundle tries loading a bundle in the following sequence. Then, getBundle sets up its parent chain from the list of the candidate locales.

Parameters: baseName - the base name of the resource bundle, a fully qualified class name targetLocale - the locale for which a resource bundle is desired loader - the class loader from which to load the resource bundle control - the control which gives information for the resource bundle loading process Returns: a resource bundle for the given base name and locale Throws: NullPointerException - if baseName , targetLocale , loader , or control is null MissingResourceException - if no resource bundle for the specified base name can be found IllegalArgumentException - if the given control doesn't perform properly e.

Returns null if this resource bundle does not contain an object for the given key. Returns: an Enumeration of the keys contained in this ResourceBundle and its parent bundles. Parameters: key - the resource key Returns: true if the given key is contained in this ResourceBundle or its parent bundles; false otherwise. Throws: NullPointerException - if key is null Since: 1. Returns: a Set of all keys contained in this ResourceBundle and its parent bundles.

The default implementation returns a Set of the keys returned by the getKeys method except for the ones for which the handleGetObject method returns null. Once the Set has been created, the value is kept in this ResourceBundle in order to avoid producing the same Set in subsequent calls. Subclasses can override this method for faster handling. Returns: a Set of the keys contained only in this ResourceBundle Since: 1.

That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy. Skip navigation links. Object java. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user's locale.

In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles. It is also convenient for translators because they only work with translatable text and do not look at the programming code.

A resource bundle is a Java properties file that contains locale-specific data. It is a way of internationalizing Java applications by making the code locale-independent.

Resouce bundles are organized into families with a common base name. The default resource bundle is used if a specific locale is not supported. PropertyResourceBundle loads the data from a properties file. A properties file is a plain-text file that contains translatable text. Properties files are not part of the Java source code, and they can contain only String values.

ListResourceBundle manages resources with a convenient list; it gets the data from a class file. Module java. Package java. Object java. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user's locale. In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles.

This allows you to write programs that can: be easily localized, or translated, into different languages handle multiple locales at once be easily modified later to support even more locales Resource bundles belong to families whose members share a common base name, but whose names also have additional components that identify their locales.

Resource Bundles and Named Modules Resource bundles can be deployed in modules in the following ways: Resource bundles together with an application Resource bundles can be deployed together with an application in the same module. In that case, the resource bundles are loaded by code in the module by calling the getBundle String or getBundle String, Locale method. Resource bundles as service providers Resource bundles can be deployed in one or more service provider modules and they can be located using ServiceLoader.

A service interface or class must be defined. The caller module declares that it uses the service, the service provider modules declare that they provide implementations of the service. Refer to ResourceBundleProvider for developing resource bundle services and deploying resource bundle providers. The module obtaining the resource bundle can be a resource bundle provider itself; in which case this module only locates the resource bundle via service provider mechanism.

Resource bundles in other modules and class path Resource bundles in a named module may be encapsulated so that it cannot be located by code in other modules. Resource bundles in unnamed modules and class path are open for any module to access. Resource bundle follows the resource encapsulation rules as specified in Module.

Resource bundles in automatic modules A common format of resource bundles is in. Resource bundle only JAR file can be readily deployed as an automatic module. This allows resource bundles in. Control The ResourceBundle. Control class provides information necessary to perform the bundle loading process by the getBundle factory methods that take a ResourceBundle.

Control instance. You can implement your own subclass in order to enable non-standard resource bundle formats, change the search strategy, or define caching parameters. Refer to the descriptions of the class and the getBundle factory method for details. Cache Management Resource bundle instances created by the getBundle factory methods are cached by default, and the factory methods return the same resource bundle instance multiple times if it has been cached. Refer to the descriptions of the getBundle factory method , clearCache , ResourceBundle.

Example The following is a very simple example of a ResourceBundle subclass, MyResources , that manages two resources for a larger number of resources you would probably use a Map. Notice that you don't need to supply a value if a "parent-level" ResourceBundle handles the same key with the same value as for the okKey below. Control ResourceBundle. Control defines a set of callback methods that are invoked by the ResourceBundle.

Removes all resource bundles from the cache that have been loaded by the caller's module. Removes all resource bundles from the cache that have been loaded by the given class loader. Determines whether the given key is contained in this ResourceBundle or its parent bundles. Gets a resource bundle using the specified base name, the default locale, and the caller module. Gets a resource bundle using the specified base name and the default locale on behalf of the specified module.

Gets a resource bundle using the specified base name and locale, and the caller module. Returns a resource bundle using the specified base name, target locale, class loader and control. Gets a resource bundle using the specified base name and locale on behalf of the specified module. Returns a resource bundle using the specified base name, target locale and control, and the caller's class loader. Returns a resource bundle using the specified base name, the default locale and the specified control.

Gets an object for the given key from this resource bundle or one of its parents. Gets a string array for the given key from this resource bundle or one of its parents. Returns a Set of the keys contained only in this ResourceBundle. Returns a Set of all keys contained in this ResourceBundle and its parent bundles.

Field Detail parent protected ResourceBundle parent The parent bundle of this bundle. The parent bundle is searched by getObject when this bundle does not contain a particular resource. Sole constructor.



0コメント

  • 1000 / 1000