hibernateとhibernateアノテーションのローカライズされたエラーメッセージを提供したいので、プロパティファイルValidatorMessages.properties、ValidatorMessages_ar.propertiesに作成しました
そしてそれらをresourcesフォルダーに置き、messageSourceを使用してプロパティファイルから読み取ります。
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:messages</value>
<value>classpath:errors</value>
<value>classpath:app</value>
<value>classpath:ValidatorMessages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>
そしてクラスでは私は次のようなものを使用します:
@NotNull(message = "{validation.notEmpty.password}")
private string password;
バリデーターを呼び出すときは、次を使用します。
Validator validator = Validation.buildDefaultValidatorFactory()
.getValidator();
Set<ConstraintViolation<MyClass> cvs = validator
.validate(myObject);
for (ConstraintViolation<MyClass> cv : cvs) {
String field = cv.getPropertyPath().toString();
result.addError(new FieldError("version", field, cv.getMessage()));
}
if (result.hasErrors()) {
initModel();
result.reject("add.version.errors");
return "manageVersions";
}
英語で正常に動作し、英語のメッセージを正しく表示しますが、アラビア語に切り替えると、アラビア語ではなく英語のメッセージが表示されます。
LocaleContextHolder.getLocale()
言語が変更され、アラビア語であることを示しています。そのため、構成やアイデアに欠けているものがありますか?