java - Tomcat internationalization maintenance -


i trying implement internationalization in tomcat. there going different resource text files. idea load resources in memory while tomcat loads. below sample code load multiple resource in memory.

public class resourcebundleloader {       private static resourcebundle enresourcebundle;     private static resourcebundle frresourcebundle;      public static void loadbundle(){         locale enlocale = new locale("en", "us");         enresourcebundle = resourcebundle.getbundle("messagesbundle",enlocale);         enlocale = new locale("fr", "fr");         frresourcebundle = resourcebundle.getbundle("messagesbundle",enlocale);     }      public static resourcebundle getenresourcebundle(){         return enresourcebundle;     }      public static resourcebundle getfrresourcebundle(){         return frresourcebundle;     } } 

the method loadbundle called once thru startup servlet. , getenresourcebundle() , getfrresourcebundle() called accordingly. right way implement/maintain internationalization in tomcat? or there better way?

thanks in advance.

you dont need make helper class, per java documentation bundles cached in memory. make code more complicated maintain. ie have alter code every time add new "bundle".

just add code servlets and/or jsp's:

//request.getlocale() returns web browsers locale bundle = resourcebundle.getbundle("messagesbundle",request.getlocale()) 

just make sure have default message bundle file text. can add locales @ things translated.

utf-8 support

i suggest create servlet filter applies requests ensures utf-8 turned on both html output, , parsing of form responses posted application:

request.setcharacterencoding("utf-8"); response.setcharacterencoding("utf-8"); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -