开发者

I18n of XSD validation error messages in Java

I perform XSD XML validation using the following classes:

import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

The problem is that XSD error messages returned by validator are always in English开发者_如何学Go language. Is it possible to call locale-aware validation with JAXP API?


JAXP is an API; it is up to the actual implementation (for example, Apache Xerces) to provide localization-aware messages.

Normally, though, system-level libraries and implementations (such as JAXP & Xerces) will provide messages localized based on the system's default locale (whatever is returned from the expression java.util.Locale.getDefault()); this is, again, OS-specific.

On Microsoft Windows, for example, you can change your system's default locale using the Regional Settings window.

If you want, you can override the "default locale" used by the JVM by specifying the user.language and user.region system properties (for example, -Duser.language=fr and -Duser.region=CA would make the JVM yield "Canadian French" as a default locale. Eventually, this setting will get to JAXP's code. If Xerces provides Canadian French resource bundles, then Canadian French messages will be emitted.


It should print error messages in Japanese, only if it exist the resource file inside java.xml\com\sun\org\apache\xerces\internal\impl\msg\XMLSchemaMessages_ja.properties But I didnt find how to add more languages.

Validator validator = schema.newValidator();
validator.setErrorHandler(errorHandler);
validator.setProperty("http://apache.org/xml/properties/locale", Locale.forLanguageTag("ja"));

Hope it helps.


Apparently there's no way to achieve what I want.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜