如何使用消息本身?
How to use messages in itself?
message.properties
my.hello=hello
my.hello-world=${my.hello} world! (it doesn't work)
有没有办法像这样在 messages.properties 中使用 eval 表达式?
如果您扩展 PropertySourcesPlaceholderConfigurer
并且在 loadProperties
方法中您应该对那些值包含占位符前缀和后缀的属性进行一些解析和转换,这可能是可能的
因为我没有找到内置实现。我写一个库Nest-Message-Spring-Boot
使用嵌套消息表达式
hello.guy=Hello {0}!
hello.world=$(hello.guy,world)
hello.world
将是 Hello World!
使用参数占位符
hello.two=Hello {0} and {1}!
hello.owt=$(hello.two,,[=11=])
hello.world
与 {a, b}
将是 Hello b and a!
带转义符和引号的复杂表达式
book.name=<{0}>
book.price=${0,number,#.#}
book.promote=Come to buy {0} with $(book.price,)
java.promote=Hello guys! $(book.promote,$(book.name,java)"(2nd edition)",{0})
java.promote
与 {123}
将是
Hello guys! Come to buy <java>(2nd edition) with 3
message.properties
my.hello=hello
my.hello-world=${my.hello} world! (it doesn't work)
有没有办法像这样在 messages.properties 中使用 eval 表达式?
如果您扩展 PropertySourcesPlaceholderConfigurer
并且在 loadProperties
方法中您应该对那些值包含占位符前缀和后缀的属性进行一些解析和转换,这可能是可能的
因为我没有找到内置实现。我写一个库Nest-Message-Spring-Boot
使用嵌套消息表达式
hello.guy=Hello {0}!
hello.world=$(hello.guy,world)
hello.world
将是 Hello World!
使用参数占位符
hello.two=Hello {0} and {1}!
hello.owt=$(hello.two,,[=11=])
hello.world
与 {a, b}
将是 Hello b and a!
带转义符和引号的复杂表达式
book.name=<{0}>
book.price=${0,number,#.#}
book.promote=Come to buy {0} with $(book.price,)
java.promote=Hello guys! $(book.promote,$(book.name,java)"(2nd edition)",{0})
java.promote
与 {123}
将是
Hello guys! Come to buy <java>(2nd edition) with 3