この目的のために独自のカスタムメッセージソースを作成することができます。
何かのように:
public class SpecialMessageSource extends ReloadableResourceBundleMessageSource {
@Override
protected MessageFormat resolveCode(String code, Locale locale) {
MessageFormat result = super.resolveCode(code, locale);
if (result.getPattern().isEmpty() && locale == Locale.CHINESE) {
return super.resolveCode(code, Locale.ENGLISH);
}
return result;
}
@Override
protected String resolveCodeWithoutArguments(String code, Locale locale) {
String result= super.resolveCodeWithoutArguments(code, locale);
if ((result == null || result.isEmpty()) && locale == Locale.CHINESE) {
return super.resolveCodeWithoutArguments(code, Locale.ENGLISH);
}
return result;
}
}
と
今
<bean id="messageSource" class="SpecialMessageSource">
.....
</bean>
として春のXMLでこのmessageSource Beanを設定すると、以下の方法のMessageSource's
いずれかを呼び出すことになるラベルを解決し得るために
String getMessage(String code, Object[] args, Locale locale);
String getMessage(String code, Object[] args, String defaultMessage, Locale locale);
resolveCode()
が呼び出されます。 Rメッセージラベルは、引数を持って、あなたは
invalid.number= {0} is Invalid
以下のようにargs
パラメータを経由して、これらの引数を渡すと、あなたはmessageSource.getMessage("INVALID_NUMBER", new Object[]{2d}, locale)
resolveCodeWithoutArguments()
を呼び出すあなたのメッセージラベルは、引数を持っていない、あなたがnull
validation.success = Validation Success
としてargs
パラメータを渡すときに呼び出されます
あなたが呼び出すmessageSource.getMessage("INVALID_NUMBER", null, locale)
downvoteの理由は? – harrybvp
誰があなたを落胆させたのか分かりませんが、私は正しい軌道に乗っているので、あなたにアップアップして答えのクレジットを与えます。私のコードが私が望むすべてのことをしているかどうかはわかりません。たぶんあなたは問題を見つけることができます。 – Ryan
@Ryan私は自分のコードを更新し、あなたの望むように説明を追加しました – harrybvp