LabelLocator 的 zk 国际化
zk internationalization by LabelLocator
我想在我的项目中实现 zk 国际化。我查看了所有文档并找到了以下信息:
public class FooServletLocator implements org.zkoss.util.resource.LabelLocator {
private ServletContext _svlctx;
private String _name;
public FooServletLocator(ServletContext svlctx, String name) {
_svlctx = svlctx;
_name = name;
}
public URL locate(Locale locale) {
return _svlctx.getResource("/WEB-INF/labels/" + name + "_" + locale + ".properties");
}
}
那么我应该通过代码调用这个定位器:
Labels.register(LabelLocator2)
问题是我应该把这个代码行和调用定位器放在哪里,在我的视图模型(我使用 mvvm)或其他地方?我看不懂:(
感谢您的帮助!!!
关于 ZK 国际化的 docs 非常简单。看来你只是没有读过几段:
Then, we could register label locators when the application starts by use of WebAppInit as follows.
public class MyAppInit implements org.zkoss.zk.ui.util.WebAppInit {
public void init(WebApp wapp) throws Exception {
Labels.register(new FooDBLocator(("moduleX");
Labels.register(new FooDBLocator(("moduleY");
Labels.register(new FooServletLocator((ServletContext)wapp.getNativeContext(), "module-1");
Labels.register(new FooServletLocator((ServletContext)wapp.getNativeContext(), "module-2");
}
}
where we assume moduleX and moduleY is the database table to load the properties, and module-1.properties and module-2.properties are two modules of messages you provide. Then, you configure it in WEB-INF/zk.xml as described in ZK Configuration Reference.
我想在我的项目中实现 zk 国际化。我查看了所有文档并找到了以下信息:
public class FooServletLocator implements org.zkoss.util.resource.LabelLocator {
private ServletContext _svlctx;
private String _name;
public FooServletLocator(ServletContext svlctx, String name) {
_svlctx = svlctx;
_name = name;
}
public URL locate(Locale locale) {
return _svlctx.getResource("/WEB-INF/labels/" + name + "_" + locale + ".properties");
}
}
那么我应该通过代码调用这个定位器:
Labels.register(LabelLocator2)
问题是我应该把这个代码行和调用定位器放在哪里,在我的视图模型(我使用 mvvm)或其他地方?我看不懂:(
感谢您的帮助!!!
关于 ZK 国际化的 docs 非常简单。看来你只是没有读过几段:
Then, we could register label locators when the application starts by use of WebAppInit as follows.
public class MyAppInit implements org.zkoss.zk.ui.util.WebAppInit {
public void init(WebApp wapp) throws Exception {
Labels.register(new FooDBLocator(("moduleX");
Labels.register(new FooDBLocator(("moduleY");
Labels.register(new FooServletLocator((ServletContext)wapp.getNativeContext(), "module-1");
Labels.register(new FooServletLocator((ServletContext)wapp.getNativeContext(), "module-2");
}
}
where we assume moduleX and moduleY is the database table to load the properties, and module-1.properties and module-2.properties are two modules of messages you provide. Then, you configure it in WEB-INF/zk.xml as described in ZK Configuration Reference.