簡體   English   中英

消息包密鑰中的空格

[英]spaces in message bundle keys

我希望能夠在我的消息包密鑰中包含空格,因為如果您不必將空格轉換為下划線,則更容易將現有文本轉換為鍵。

春天的消息來源似乎並不喜歡這樣。 可能嗎?

2011-03-30 15:45:56,519 ERROR [org.springframework.web.servlet.tags.MessageTag] - No message found under code 'Invalid username or password' for locale 'en_US'.
javax.servlet.jsp.JspTagException: No message found under code 'Invalid username or password' for locale 'en_US'.
    at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:183)

如果要通過.properties資源包存儲消息,請確保在鍵中的空格之前添加反斜杠。

Invalid\ username\ or\ password=Invalid username or password

請參閱Wikipedia中的屬性文件示例:

http://en.wikipedia.org/wiki/.properties

# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".

對於有這個問題的其他人來說,這是一個有點hacky groovy我寫的修復空間:

@Test
  void fixMessageBundle(){
      def path = "/path/to/it/messages_en_US.properties";
      String fixed = "";
      Map keys = [:]
      new File(path).eachLine { String it->
          String line = "";
          if(it.contains("=")){
            String key = it.split("=")[0];
            String val = it.split("=")[1];
            if(keys.containsKey(key)){
                println "removed duplicate key: ${key}. kept val: [${keys[key]}], threw out val: [${val}]"
                return
            }
            keys.put(key, val);
            line = key.replaceAll(/([^\\]) /, "\$1\\\\ ") + "=" + val;
          }
          fixed  += line+"\n";
      }
      new File(path).text = fixed;
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM