ammar
ammar

Reputation: 1393

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 ?

Upvotes: 2

Views: 1624

Answers (3)

AmitG
AmitG

Reputation: 10543

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.

Upvotes: 0

rsp
rsp

Reputation: 23373

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.

Upvotes: 1

Epcylon
Epcylon

Reputation: 4727

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

Upvotes: 1

Related Questions