Spring+freeMarker(国际化)
在config.xml中增加
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
</bean>
其中粗体部分是Spring的标准, 不可更改的
然后在src目录下创建messages.properties, messages_zh_CN.properties, 它们会在编译的时候被copy到WEB-INF/classes去的, messages_zh_CN.properties的内容是要经过native2ascii的编码转换才行的.
title=SpringTest
heading=Spring :: Test
greeting=Hello, It is now
heading=Spring :: Test
greeting=Hello, It is now
把spring包里面的spring.ftl复制到ftl文件目录的includes里面, 这样就能在ftl文件中使用宏来获得需要的message了:
<#import"/includes/spring.ftl" as spring/>
<html>
<head><title><@spring.message "title"/></title></head>
<body>
<h1><@spring.message "heading"/></h1>
<p><@spring.message "greeting"/>${now?if_exists}</p>
</body>
</html>
<html>
<head><title><@spring.message "title"/></title></head>
<body>
<h1><@spring.message "heading"/></h1>
<p><@spring.message "greeting"/>${now?if_exists}</p>
</body>
</html>
相关推荐
GavinZhera 2019-11-05
networkhunter 2014-09-09
87133658 2019-09-29
河的第三条岸 2015-07-13
PeterHao0 2016-01-22
AndyXuq 2014-09-09
码场老农 2013-06-05
sdaq 2015-01-24
duling 2019-06-28
bob00 2013-07-11
81941231 2012-09-17
shyu 2019-05-28
AsiaLee 2018-10-11
LuqiangShi 2018-09-03
liongxiong 2018-07-04
gybheroin 2018-07-03
andonliu 2018-06-27