【问题标题】:Is there a reason to ever use Constants instead of Messages?是否有理由使用常量而不是消息?
【发布时间】:2013-08-05 15:53:44
【问题描述】:

我想将我的 GWT 应用程序国际化。阅读文档后,我看不出有任何理由使用常量而不是消息。消息似乎在各个方面都更强大。

有任何理由使用常量吗?与 Messages 相比,它们是否具有更好的性能或任何其他优势?

【问题讨论】:

    标签: java gwt internationalization


    【解决方案1】:

    消息仅与字符串有关,而常量可以包含数字、布尔值、字符串数组等。

    Google Groups

    【讨论】:

      【解决方案2】:

      不一定是不使用消息的理由,但有一点值得注意。使用 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
      

      【讨论】:

        猜你喜欢
        • 2017-02-14
        • 1970-01-01
        • 2010-12-31
        • 2021-12-01
        • 2013-06-04
        • 2012-07-22
        • 1970-01-01
        • 2018-02-11
        • 2020-10-05
        相关资源
        最近更新 更多