Where are the resources used by NumberFormat?

S

Scott Smith

I need to format percentages for 23 different locales, and unfortunately my
client doesn't use Java. If I recall correctly, in Java I'd use
NumberFormat.getPercentInstance(locale) [or something like that], and the
JRE would get the appropriate percent formatting info from a locale-specific
resource bundle.

OK, so... where are those resources? I basically need to do something
similar in a non-Java program, and I want to avoid having to research the
percent formats for 23 different locales.

I've done some searching, but haven't been able to find them. Can someone
point me in the right direction?

Thanks in advance.

-Scott
 
T

Thomas Fritsch

Scott said:
I need to format percentages for 23 different locales, and unfortunately
my client doesn't use Java. If I recall correctly, in Java I'd use
NumberFormat.getPercentInstance(locale) [or something like that], and the
JRE would get the appropriate percent formatting info from a
locale-specific resource bundle.

OK, so... where are those resources? I basically need to do something
similar in a non-Java program, and I want to avoid having to research the
percent formats for 23 different locales.

I've done some searching, but haven't been able to find them. Can someone
point me in the right direction?

Looking into the source "NumberFormat.java" I find
ResourceBundle resource = LocaleData.getLocaleElements(desiredLocale);
where class LocaleData is imported from package "sun.text.resources".
I assume this call loads resources that same package.
In file "<jre>/lib/rt.jar" there are many files
sun/text/resources/LocaleElements_<locale>.class
for european locales. And in file "<jre>/lib/ext/localedata.jar" there are
some more for asian locales.
 
C

Chris Uppal

Scott said:
I need to format percentages for 23 different locales, and unfortunately
my client doesn't use Java. If I recall correctly, in Java I'd use
NumberFormat.getPercentInstance(locale) [or something like that], and the
JRE would get the appropriate percent formatting info from a
locale-specific resource bundle.

OK, so... where are those resources? I basically need to do something
similar in a non-Java program, and I want to avoid having to research the
percent formats for 23 different locales.

A) I should check the licensing position very carefully before using Sun's IP
in a non-Java application.

B) I think it depends on the Locale service provider.

C) Why not just dump the data out of Java with a loop over
NumberFormat.getAvailableLocales(), calling getPercentInstance() on each one ?

D) The data included with the jre is in <jre>/lib/ext/localedata.jar. Inside
the jar, the resource bundles are sun/text/resources/FormatData_*.class.

E) The source for that isn't included in src.zip (further evidence that Sun
regard this data as part of their private IP).

F) The source /is/ included in the platform source download (hedged about by
licencing restrictions).

G) I would be willing to bet that the data for Java's number format stuff was
supplied by IBM, and their code is available as the (impressive) ICU library
for C, C++. and Java.
http://icu.sourceforge.net/userguide/intro.html

-- chris
 
M

mr.intj

ScottSmithwrote:
I need to format percentages for 23 different locales, and unfortunately
my client doesn't use Java. If I recall correctly, in Java I'd use
NumberFormat.getPercentInstance(locale) [or something like that], and the
JRE would get the appropriate percent formatting info from a
locale-specific resource bundle.
OK, so... where are those resources? I basically need to do something
similar in a non-Java program, and I want to avoid having to research the
percent formats for 23 different locales.
I've done some searching, but haven't been able to find them. Can someone
point me in the right direction?

Looking into the source "NumberFormat.java" I find
ResourceBundleresource = LocaleData.getLocaleElements(desiredLocale);
where class LocaleData is imported from package "sun.text.resources".
I assume this call loads resources that same package.
In file "<jre>/lib/rt.jar" there are many files
sun/text/resources/LocaleElements_<locale>.class
for european locales. And in file "<jre>/lib/ext/localedata.jar" there are
some more for asian locales.

Thomas,

Thanks very much. Found everything I needed!

-Scott
 
M

mr.intj

ScottSmithwrote:
I need to format percentages for 23 different locales, and unfortunately
my client doesn't use Java. If I recall correctly, in Java I'd use
NumberFormat.getPercentInstance(locale) [or something like that], and the
JRE would get the appropriate percent formatting info from a
locale-specific resource bundle.
OK, so... where are those resources? I basically need to do something
similar in a non-Java program, and I want to avoid having to research the
percent formats for 23 different locales.

A) I should check the licensing position very carefully before using Sun's IP
in a non-Java application.

B) I think it depends on the Locale service provider.

C) Why not just dump the data out of Java with a loop over
NumberFormat.getAvailableLocales(), calling getPercentInstance() on each one ?

D) The data included with the jre is in <jre>/lib/ext/localedata.jar. Inside
the jar, the resource bundles are sun/text/resources/FormatData_*.class.

E) The source for that isn't included in src.zip (further evidence that Sun
regard this data as part of their private IP).

F) The source /is/ included in the platform source download (hedged about by
licencing restrictions).

G) I would be willing to bet that the data for Java's number format stuff was
supplied by IBM, and their code is available as the (impressive) ICU library
for C, C++. and Java.
http://icu.sourceforge.net/userguide/intro.html

-- chris

Chris,

Thanks for the detailed reply. I was able to find the information that
I needed with your help and the JAD decompiler. Someone could make a
case about the IP issue, but I was looking at it more for reference
than to lift code. Turns out that the percent formats are the same for
all of the locales that I was interested in. Good to know.

-Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top