changing language in java
i used .properties files to manage the language in java code. but how to change the language manually, i mean when the user want to change the language. in other word what google and facebook开发者_高级运维 did to manage this ?
Basically, you need to set the Locale that matches your users selection. There are some issues that you need to be aware of, but it should be fairly straight forward. There are a couple guides to get you started here, and here
You might want to look at storing your UI texts in resource bundles, then offer your users a choice of locales that are known to the application and reload the UI for the user from the bundle loaded using the locale chosen.
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
setLocale(request, Locale.ITALY); // This is inherited method.
return mapping.findForward(SUCCESS);
}
Call setLocale() method with arguments request and java.util.Locale. Make sure that you have respective ApplicationResource_it_IT.properties in your resource path in this case.
精彩评论