是否可以重载 GWT i18n 中的消息方法
我有一个可本地化 GWT 项目的 com.google.gwt.i18n.client.Messages
实现。
但似乎不可能重载方法。是Bug还是有原因?
public interface CommonMessages extends Messages {
public static final CommonMessages INSTANCE = GWT.create( CommonMessages.class );
@DefaultMessage( "The entered text \"{0}\" contains the illegal character(s) \"{1}\" ." )
String textValidatorError( String o, String e );
@DefaultMessage( "The entered text \"{0}\" contains illegal character(s)." )
String textValidatorError( String o );
}
提出:
Rebinding common.client.i18n.CommonMessages
[java] Invoking generator com.google.gwt.i18n.rebind.LocalizableGenerator
[java] Processing interface common.client.i18n.CommonMessages
[java] Generating method body for textValidatorError()
[java] [ERROR] Argument 1 beyond range of arguments: The entered text "{0}" contains the illegal character(s) "{1}" .
I have an com.google.gwt.i18n.client.Messages
implementation for a localizable GWT-Project.
But it seems that it is not possible to overload the Methods. Is it a Bug or is there a reason?
public interface CommonMessages extends Messages {
public static final CommonMessages INSTANCE = GWT.create( CommonMessages.class );
@DefaultMessage( "The entered text \"{0}\" contains the illegal character(s) \"{1}\" ." )
String textValidatorError( String o, String e );
@DefaultMessage( "The entered text \"{0}\" contains illegal character(s)." )
String textValidatorError( String o );
}
brings up:
Rebinding common.client.i18n.CommonMessages
[java] Invoking generator com.google.gwt.i18n.rebind.LocalizableGenerator
[java] Processing interface common.client.i18n.CommonMessages
[java] Generating method body for textValidatorError()
[java] [ERROR] Argument 1 beyond range of arguments: The entered text "{0}" contains the illegal character(s) "{1}" .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的消息接口依赖于属性文件。
由于您的接口具有使用相同名称的方法,因此 gwt 会尝试在同一文件中查找属性 textValidatorError 两次。
第一次它寻找带有 2 个参数的属性,并找到了它。第二次它寻找具有 1 个参数的属性,并找到一个具有两个参数的属性......因此出现错误。
使用@Key注解指定不同的属性名称。
Your Messages interface relies on a properties file.
Because your interface has methods using the same name, gwt tries to look up the property textValidatorError twice in the same file.
The first time it's looking for a property with 2 arguments, and finds it. The second time it's looking for a property with 1 arguments, and finds one with two ... Hence the error.
Use the @Key annotation to specify different property names.