Liferay: changing locales for a site programmatica

2019-09-08 03:53发布

问题:

Is there a way to change the status of site´s locales programatically?

I have to make a script that implies changing locales for some sites of our portal. In other words, having an object Group, I´d like to change the locales in its settings.

http://i.stack.imgur.com/Xypas.png

Note we are using Liferay Portal 6.2.

Thanks in advance.

EDIT for clarifying: I´m executing the script through Control Panel -> Server admin -> Script. Here is where I have the problem commented:

//customAvailableLocales is a String containing the locales the site should have associated
    Locale[] languageArray = LanguageUtil.getAvailableLocales(groupId);
    if(languageArray != null && languageArray .length > 0){
        for(int i = 0;i<languageArray.length;i++) {
           if(!customAvailableLocales.contains(languageArray [i].toString())){
            //Here, the locale should be disassociated to the site (from current col. to available col.)

           }
    }
}

Getting into the TypeSettings to change the locales there, I have this:

//group is where I´d like to change locales
    UnicodeProperties uniprops = group.getTypeSettingsProperties();
    uniprops.setProperty("locales",customAvailableLocales);
    group.setTypeSettingsProperties(uniprops);

But the group has not the same locales in the "current" column and in the TypeSetting, as I can see in the settings through the Control Panel.

回答1:

I find the solution for you (for us). Add to your code

UnicodeProperties uniprops = group.getTypeSettingsProperties();
uniprops.setProperty("inheritLocales", "false"); // add this line
uniprops.setProperty("locales",customAvailableLocales);    
group.setTypeSettingsProperties(uniprops);
GroupLocalServiceUtil.updateGroup(group) // and this will update your group/site

It works fine to me!