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

前端 未结 2 827
感动是毒
感动是毒 2021-01-14 12:46

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 resource

相关标签:
2条回答
  • 2021-01-14 12:57

    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?

    0 讨论(0)
  • 2021-01-14 13:12

    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 讨论(0)
提交回复
热议问题