I'm tring to make zk internationalization in my project. I have looked through all docs and find out this info:
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");
}
}
Then i should invoke this locator by code:
Labels.register(LabelLocator2)
The question is where should i put this codeline and invoke locator, in my viewmodel (i use mvvm) or somewhere else? I can't understand it :(
Thanks for any help !!!
The docs about ZK internationalization are quite straightforward. It seems you just do not have read up a couple of paragraphs:
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.