今天发现,Seesaw依赖j18n.jar,看文档,Seesaw内置支持国际化,貌似很简单很好用。
写了个例子:
文件结构:
core.clj中的内容:
(ns com.core (:use [seesaw.core])) (def main-frame (frame :title ::hello-title, :resource ::my-frame, :content (label ::hello-content))) (defn show-frame [] (-> main-frame pack! show!)) (show-frame)
core_zh_CN.properties
hello-title=Hello Title Chinese
hello-content=Hello Content Chinese
core.properties
hello-title=Hello Title
hello-content=Hello Content
上面是一个能跑的例子,下面说一下注意事项:
1、只有被Seesaw用到的地方,才会做国际化;
说了等于白说,这不是很明显的嘛,我今天犯傻在这事上折腾了好久,多么想让一个没有被用到的str也被国际化啊。。。回头一想,这怎么可能?
2、资源文件的路径命名,要和用到的在同一个包路径下,一个clj,对应一组properties。
这岂不是说,我写几个clj文件,就要写几组properties?现在看来,还真是的。如果文件名不对,会报如下异常:
CompilerException java.util.MissingResourceException: Can't find bundle for base name com.core, locale zh_CN, compiling:(core.clj:6)
3、其他遇到的问题:第6行,(label ::hello-content)换成"Hello Content"是可以的,但写成::hello-content是不会转换的。