liferayliferay-6liferay-theme

Change site language programmatically


I need to change site language programmatically in Liferay and Im stuck. I thought that I can use LanguageUtil class, but I dont know how.

Is there any way, to change Liferay language programmatically? (I know I can do that in administration panel, but I need to have that feature in my code also).

Now my code looks like this:

@ResourceMapping("changeLanguageToEnglish")
public void changeLanguageToEnglish(){
        LanguageUtil langUtil = new LanguageUtil();
        //langUtil.setLanguage(language);
}

Solution

  • I can do this using the portal-ext.properties:

    #
    # Set the default locale used by Liferay. This locale is no longer set at
    # the VM level. See LEP-2584.
    #
    user.country=US
    user.language=en
    

    Also by a hook

    <hook>
         <language-properties>content/Language_en.properties</language-properties>
         <language-properties>content/Language_fa.properties</language-properties>
    </hook>
    

    And through a portlet

    Change languaje portlet

    Regards!