0

A way to load localization from database

asked 2009-10-27 03:10:52 +0800

agharta82 gravatar image agharta82
36

Hi all!
Anyone known how to load the content of i3-label.properties (and variants, eg en_US, IT, DE etc..) from a database?

I need to load the language from database, not from file.


Regards,


Agharta

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2009-10-27 22:43:44 +0800

iantsai gravatar image iantsai
2755 1

There are two solutions, first is to implement your own LabelLocator, second is implement whole I18N Utilities yourself.

1.)implement your own LabelLocator

implements interface org.zkoss.util.resource.LabelLocator.
there's only one method you should implement that is public URL locate(Locale locale) throws Exception;
the url.openStream() should return a content which format is same as ZK i3-label format.
you can implement a Servlet to access DB, and form the URL to connect to that servlet.

But there is a limitation in this mechanism, that is ZK's I18N Label Handling model is static and in-memory, which means you can't change the label after initialization.
So if you want a model that you can change the label at runtime, you need to impl one for yourself.

2.)The I18N implementation in ZK is just a utility, you can implement one for yourself.

to see how to custom a I18N label resolving mechanism yourself, you can take a look at the src of:
org.zkoss.util.resource.impl.LabelLoader
org.zkoss.util.resource.Labels

Copy them as a base, declare your own tld for EL method.
It won't be too hard.


also you can post a feature request to SF.net, but you need to wait.

link publish delete flag offensive edit

answered 2009-10-28 02:17:14 +0800

agharta82 gravatar image agharta82
36

Hi iantsai,
Thank you for reply.

I'll try the second solution, is seems more flexible.

Thanks a lot!!!!

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-10-27 03:10:52 +0800

Seen: 624 times

Last updated: Oct 28 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More