spring - 消息包键中的空格

标签 spring internationalization message-bundle

我希望能够在我的消息包键中包含空格,因为如果您不必也将空格转换为下划线,则将现有文本转换为键会更容易。

不过,spring 消息源似乎不喜欢这个。是否可以?

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

请参阅维基百科中的属性文件示例:

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".

关于spring - 消息包键中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5491517/

相关文章:

java - Spring PropertyPlaceholderConfigurer 破坏 Autowire

spring - 在springboot中使用gradle时,加载依赖项遇到sun.security.validator.validatorexception。我不知道怎么解决

database - 如何在从数据库检索数据的 JSF 中使用国际化

Grails - 仅用于 war 构建的消息包 (i18n)

php - Symfony2 中的 FOSMessageBundle

java - Java Hashmap<Integer, Integer> 和 mysql 临时表哪个更有效?

java - Spring Constant 将忽略并非所有大写字段

php - 如何自动将电子邮件附件文件名转换为 UTF-8(使用 Mail_mimeDecode)

spring-mvc - Spring MVC/Freemarker : using a message from a bundle in a Freemarker expression