Liferay:以编程方式更改网站的区域设置 [英] Liferay: changing locales for a site programmatically

查看:89
本文介绍了Liferay:以编程方式更改网站的区域设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式更改站点区域设置的状态?

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

请注意,我们正在使用Liferay Portal 6.2.

Note we are using Liferay Portal 6.2.

提前谢谢.

编辑以澄清问题:我正在通过控制面板"->服务器管理"->脚本"执行脚本.这是我对问题进行评论的地方:

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.)

           }
    }
}

进入TypeSettings更改那里的语言环境,我有这个:

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);

但是,该组在当前"列和TypeSetting中的语言环境不同,如我在控制面板"中的设置所见.

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.

推荐答案

我(为我们)为您找到了解决方案.添加到您的代码

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

对我来说很好!

这篇关于Liferay:以编程方式更改网站的区域设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆