【发布时间】:2015-11-19 11:22:56
【问题描述】:
有没有办法以编程方式更改网站语言环境的状态?
我必须编写一个脚本来暗示更改我们门户网站某些站点的区域设置。换句话说,拥有一个对象组,我想更改其设置中的语言环境。
http://i.stack.imgur.com/Xypas.png
请注意,我们使用的是 Liferay Portal 6.2。
提前致谢。
为澄清而编辑:我正在通过控制面板 -> 服务器管理 -> 脚本执行脚本。这是我评论问题的地方:
//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 以更改那里的语言环境,我有这个:
//group is where I´d like to change locales
UnicodeProperties uniprops = group.getTypeSettingsProperties();
uniprops.setProperty("locales",customAvailableLocales);
group.setTypeSettingsProperties(uniprops);
但该组在“当前”列和 TypeSetting 中的区域设置不同,正如我通过控制面板在设置中看到的那样。
【问题讨论】:
-
请更具体一点:什么样的“脚本”?到目前为止,您尝试过什么?
-
嘿,感谢您的回复 :) 特别是,是一个 groovy 脚本,但实际上可以是任何类型。在这一点上,我试图操纵字段 TypeSettingsProperties(与每个组关联的 UnicodeProperties),但它总是在“语言环境”属性中具有两个语言环境:英语和西班牙语,但在“当前”列中有三个语言环境:英语、西班牙语和 euskera。
-
欢迎来到stackoverflow。我们总是尝试通过editing 来改进问题,直到每个用户在不阅读所有 cmets 的情况下理解它们。你能解释一下,你在什么样的上下文中执行你的脚本。我本来希望首先使用浏览器 - 但显然您正在尝试使用一些 API,如 REST、Web 服务、远程 EJB?由于每个 API 都不同,因此您需要更加具体。您当前代码的简短 sn-p 也会有所帮助。
-
感谢您的建议。我做了一些编辑。让我知道是否有更多的理解问题:-)
-
您的问题解决了吗?我有同样的问题:)