Search code examples
javaxsltxalan

How to be able to change the error messages locales when using the Java Transformer class


I am using the XSL Transformer class in java (in my case, it's Java 8). I have some error messages such as:

Avertissements de compilateur :
  file:/D:/Java/a661Xmltool/samplesCopy/metadata/Transforms/Part1/DataSpaceXSD/GenerateDataSpaceXSD_V1_0withEXSLT.xsl: line 1160: Attribut 'base' à l'extérieur de l'élément.
Avertissements de compilateur :
  file:/D:/Java/a661Xmltool/samplesCopy/metadata/Transforms/Part1/DataSpaceXSD/GenerateDataSpaceXSD_V1_0withEXSLT.xsl: line 1160: Attribut 'base' à l'extérieur de l'élément.
ERROR:  'Erreur de syntaxe dans 'text(  )'.'

My machine has a French Locale, but I would prefer to have the messages in English. Is it possible to do that like it is with the SAXParser class?

For example, in the SAXParser, you can do:

 try {
    parser.setProperty("http://apache.org/xml/properties/locale", locale);
 } catch (SAXException ex) {
 }

I tried with the transformer:

transformer.setParameter("http://apache.org/xml/properties/locale", locale);

but to no avail.

To be more clear, I am asking about the Xalan implementation, which is the default Java implementation. I looked in the Xalan documentation, and found nothing.


Solution

  • This may not be what you want, but one option would be setting the locale of the entire JVM from the command line with the options:

    java ... -Duser.country=US and -Duser.lang=en
    

    Perusing the Xalan code, it seems that message resources are always loaded as a function of the default locale, hence I don't think that you can set a local specifically for Xalan. Too bad because that should be fairly simple to implement.

    https://github.com/apache/xalan-j/blob/660e12dca29e28df9f3f9ebb7c19435bb16362f3/src/org/apache/xalan/res/XSLTErrorResources.java#L1455