开发者

Java JRE: How to add localized resources to stantard JRE resources

开发者 https://www.devze.com 2023-03-23 13:35 出处:网络
I need the JRE to use translated versions of a JRE resource that is available only in English. As per the ResourceBundle.java doc, it\'s easy: add localized resources with the right locale suffix. Fo

I need the JRE to use translated versions of a JRE resource that is available only in English.

As per the ResourceBundle.java doc, it's easy: add localized resources with the right locale suffix. For example, the standard

would become a translated version:

  • XMLSchemaMessages_FR.properties

And so on.

EDIT: this particular file lives in : com\sun\org\apache\xerces\internal\impl\msg\XMLSchemaMessages.properties

My question is: how do I make those extra resources visible to the JRE ?

Thanks in advance, for any help. -- cheers


Assuming that Xerces uses ResourceBundle to get the messages, you should put a new file in

com\sun\org\apache\xerces\internal\impl\msg\XMLSchemaMessages<locale>.properties 

where locale is a correct identifier for the locale you need.

Then pinpoint the exact location where the XMLSchemaMessages resource bundle is loaded, and set a breakpoint so you single step through the ResourceBundle loading procedure in the JRE (a JDK is recommended here, so you have source for the runtime) and you can see what is being searched for.

Note: You are dealing with a vendor specific XML Parser here meaning this will be Oracle specific and may even only work on some Java versions. Considered bringing in your own validating XML Parser and localize it instead?


The above answers took me a little while to work out.

Just to make it easier for others, here's my summary of how to get Locale specific error messages to appear if you try parsing an XML document using XML schema with Java's internal Xerces parser:

Find an appropriate properties file in the format

XMLSchemaMessages_<lower_case_language_code>.properties

For Italian I found XMLSchemaMessages_it.properties on the following site (which might be an old version, but it worked for me)

http://grepcode.com/file/repo1.maven.org/maven2/com.sun.xml.parsers/jaxp-ri/1.4.5/com/sun/org/apache/xerces/internal/impl/msg/XMLSchemaMessages_it.properties

I then created a directory structure in my temp directory to hold the new file

com\sun\org\apache\xerces\internal\impl\msg

Since jar files and zip files share the same format (and I'm lazy and today I was using Windows), I then zipped the above com directory, creating a file called com.zip. I then changed the name of the file

rename com.zip to XMLSchemaMessages_Locale.jar

and then moved the new jar file to

C:\Program Files\Java\jdk1.7.0_04\jre\lib\ext

Of course the above path depends on your platform and specific version of Java (I was using Windows 7).

Instead of zipping, if you have JDK you could easily build the jar file using the command-line jar command, from Unix, Linux or Windows.

0

精彩评论

暂无评论...
验证码 换一张
取 消