我想将我的 GWT 应用程序国际化。阅读文档后,我看不到使用常量而不是消息的理由。消息似乎在各个方面都更强大。
有任何理由使用常量吗?与 Messages 相比,它们是否具有更好的性能或任何其他优势?
我想将我的 GWT 应用程序国际化。阅读文档后,我看不到使用常量而不是消息的理由。消息似乎在各个方面都更强大。
有任何理由使用常量吗?与 Messages 相比,它们是否具有更好的性能或任何其他优势?
消息仅与字符串有关,而常量可以包含数字、布尔值、字符串数组等。
不一定是不使用消息的理由,但有一点值得注意。使用 Messages 接口时,需要对 .properties 文件中定义的包含单引号 (') 的字符串进行转义。使用常量接口时,这不是必需的。例如,如果您有以下界面:
MyMessages.java
public interface MyMessages extends Messages {
@DefaultMessage("Please")
String please();
}
MyMessages_fr.properties
# this will throw a java.text.ParseException: Unterminated single quote
please = S'il vous plaît
# this will be parsed correctly and will display with only 1 single quote
please = S''il vous plaît