Questions tagged [resourcebundle]

Resource bundles contain locale-specific objects. 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.

Resource bundles contain locale-specific objects. 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. For example, the base name of a family of resource bundles might be "MyResources". The family should have a default resource bundle which simply has the same name as its family - "MyResources" - and will be used as the bundle of last resort if a specific locale is not supported. The family can then provide as many locale-specific members as needed, for example a German one named "MyResources_de".

Each resource bundle in a family contains the same items, but the items have been translated for the locale represented by that resource bundle. For example, both "MyResources" and "MyResources_de" may have a String that's used on a button for canceling operations. In "MyResources" the String may contain "Cancel" and in "MyResources_de" it may contain "Abbrechen".

If there are different resources for different countries, you can make specializations: for example, "MyResources_de_CH" contains objects for the German language (de) in Switzerland (CH). If you want to only modify some of the resources in the specialization, you can do so.

763 questions
296
votes
17 answers

How to use UTF-8 in resource properties with ResourceBundle

I need to use UTF-8 in my resource properties using Java's ResourceBundle. When I enter the text directly into the properties file, it displays as mojibake. My app runs on Google App Engine. Can anyone give me an example? I can't get this work.
nacho
  • 2,961
  • 3
  • 15
  • 3
100
votes
8 answers

Apostrophe doesn't get translated properly when placed in a resource bundle

Apostrophe doesn't get translated properly when placed in a resource bundle. key = {0}'s brush is {1} centimeters tall (e.g. Sam's brush is 4 centimeters tall) The apostrophe gets missed if I format the above key from a java.util.ResourceBundle…
user339108
  • 12,613
  • 33
  • 81
  • 112
96
votes
6 answers

Format a message using MessageFormat.format() in Java

I have stored some messages in a resource bundle. I'm trying to format these messages as follows. import java.text.MessageFormat; String text = MessageFormat.format("You're about to delete {0} rows.", 5); System.out.println(text); Assume that the…
Tiny
  • 27,221
  • 105
  • 339
  • 599
70
votes
7 answers

Resource files not found from JUnit test cases

Summary My JUnit tests are not finding the files they require during execution. I'm using Maven for dependency management and compilation. Details All files required by the test cases are located in: src/test/resources. For example,…
Alex Averbuch
  • 3,245
  • 5
  • 33
  • 44
53
votes
4 answers

Bundling .js files vs CDN

In order to improve performance of our web pages, we are recommended to use CDNs to serve .js files on our web pages. That makes sense. Also, we are recommended to bundle our .js files in order to reduce the number of requests which are being made…
tugberk
  • 57,477
  • 67
  • 243
  • 335
53
votes
14 answers

How to load a resource bundle from a file resource in Java?

I have a file called mybundle.txt in c:/temp - c:/temp/mybundle.txt How do I load this file into a java.util.ResourceBundle? The file is a valid resource bundle. This does not seem to work: java.net.URL resourceURL = null; String path =…
user143794
45
votes
8 answers

Do resource bundles in Java support runtime string substitution?

Can you do the following with a Java ResourceBundle? In the properties file... example.dynamicresource=You currently have {0} accounts. At runtime... int accountAcount = 3; bundle.get("example.dynamicresource",accountCount,param2,...); To give a…
benstpierre
  • 32,833
  • 51
  • 177
  • 288
44
votes
13 answers

java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US

I am trying to create a utility class ReadPropertyUtil.java for reading data from property file. While my class is located under a util directory , my skyscrapper.properties file is placed in some other directory. But , when i try to access the…
roger_that
  • 9,493
  • 18
  • 66
  • 102
34
votes
9 answers

How do I specify values in a properties file so they can be retrieved using ResourceBundle#getStringArray?

I am trying to use ResourceBundle#getStringArray to retrieve a String[] from a properties file. The description of this method in the documentation reads: Gets a string array for the given key from this resource bundle or one of its…
Grant Wagner
  • 25,263
  • 7
  • 54
  • 64
32
votes
2 answers

Java ResourceBundle leading whitespace in values

I'm trying out the example given at Oracle's documentations. The java file is here as shown in that page. Now with this java file, I keep a LabelsBundle.properties file in the same directory. # This is the default LabelsBundle.properties file s1 =…
prongs
  • 9,422
  • 21
  • 67
  • 105
30
votes
7 answers

Bundle script file not being rendered.

Script file name: jquery.transit.min.js The file is in the Scripts folder, bundles.Add(new ScriptBundle("~/bundles/jquery") .Include("~/Scripts/jquery-{version}.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryui") …
Bilal Fazlani
  • 6,727
  • 9
  • 44
  • 90
29
votes
6 answers

MVC bundle client caching

By default a MVC bundle is cached on client for 1 year. Is it possible to set it's client headers manually (for 1 specific bundle)? What I need is to set custom expire headers for one of my bundles. I can't rely on the "v=hash" querystring because…
stian.net
  • 3,928
  • 4
  • 25
  • 38
28
votes
2 answers

How to add space at the end of property value

label.my.answer=My Answer I would like to add spaces deliberately at the end of the above key (e.g. I would like to have 2 spaces at the end "My Answer ") Currently the java.util.ResourceBundle functionality kind of trims this piece of code while…
Joe
  • 14,513
  • 28
  • 82
  • 144
27
votes
5 answers

In Java how do I find out what languages I have available my Resource Bundle

I have some resource bundles packaged in my main jar widget_en.properties widget_de.properties I retrieve a resource bundle based on my default locale as folows ResourceBundle.getBundle("widget", Locale.getDefault()); But I want to present the…
Paul Taylor
  • 13,411
  • 42
  • 184
  • 351
26
votes
1 answer

Java ResourceBundle Performance

I am using a ResourceBundle and Locale to lookup property values. Quite simply, the code looks like this: public static String getPropertyValue(Locale locale, String resourceName, String key) { ResourceBundle resource =…
Chocula
  • 1,946
  • 1
  • 16
  • 21
1
2 3
50 51