java - gettext-commons per-request locale in servlet -


the gettext-tutorial states

the preferable way create i18n object through i18nfactory. factory caches i18n object internally using the package name of provided class object , registers i18nmanager. classes of same package use same i18n instance.

but running inside httpservlet (actually velocityviewservlet in particular case) seems me if change locale on cached object stay subsequent requests , not desirable because each request must served particular locales.

so question is, should instead create ad-hoc i18n objects on per-request basis, specific locale of request? think performance penalty, should instead create own manager , select appropriate instance based on request's locale?

any comments appreciated. there doesn't seem doc or examples besides tutorial , javadoc.

update: there 1 thing tried , seems work. instead of declaring private static member tutorial says, call factory method on each request, using special version of i18nfactory:

geti18n(java.lang.class clazz, java.lang.string bundlename, java.util.locale locale) 

this should cached instance of particular locale (or force load on first request locale), avoiding performance penalties on subsequent requests same one. if can confirm make sense:

public class foo extends velocityviewservlet {   @override   public void doget(httpservletrequest request, httpservletresponse response) {     locale reqlocale = request.getlocale();     i18n i18n = i18nfactory.geti18n(foo.class, "app.i18n.messages", reqlocale);     string localized = i18n.tr("bar");      ...   } ... } 

again, i've tested , it's working i'd know if it's correct implementation of gettext-commons type of application.

thanks in advance,

-- alejandro imass


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -