Silverstripe不同语言的页面关系
我创建了一个链接数据对象来自动让用户创建对前端中不同页面的引用。我在前端使用两种语言:德语和英语。在弹出窗口中,我创建了一个下拉列表来选择页面
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Titel'),
new TextField('URL', 'Externer Link'),
new SimpleTreeDropdownField('PageLinkID', 'Interner Link', 'SiteTree')
);
}
,但我只在下拉列表中获取德语页面。尝试将管理语言更改为英语,但没有任何变化。该数据库似乎只返回德语页面......
有任何线索吗?
I have created a Link DataObject to automatically let users create a reference to a different page in the Frontend. I use two languages in the frontend, German and English. In the popup I create a dropdown to select the pages
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Titel'),
new TextField('URL', 'Externer Link'),
new SimpleTreeDropdownField('PageLinkID', 'Interner Link', 'SiteTree')
);
}
But I only get the German pages in the dropdown. Tried to change the admin language to English but no change. The database seems to only return the German pages...
Any clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我做了一些更多的挖掘并找到了如何做到这一点。您需要在获取 SiteTree 对象之前调用“disable_locale_filter”:
然后在检索它们后调用“enable_locale_filter”:
这些是我将保留在此处的其他方法,因为我认为它们仍然有用...
我相信您可能必须使用 Translatable::get_by_locale() 来执行此操作 - 我假设您只希望人们能够选择要链接到其语言的页面?
也许是这样的?
编辑:请参阅下面的注释,但另一种选择是使用 Translatable::get_current_locale() 函数在站点树中查找该语言环境的所有页面...如果用户正在查看英文页面,则应将语言环境设置为英语等...
您还可以从当前页面获取区域设置,例如
Edit: I did some more digging and found out how to do this. You need to call "disable_locale_filter" before you get your SiteTree objects:
Then call "enable_locale_filter" once you've retrieved them:
These are other approaches which I'll leave here as I think they are still useful...
I believe you may have to do this using Translatable::get_by_locale() - I assume you only want people to be able to select a page to link to within their language??
Perhaps something like this?
Edit: see comments below but another option is to use the Translatable::get_current_locale() function to find all pages in the Site Tree for that locale... if the user is viewing an english page then the locale should be set to english etc...
You can also get the locale from the current page e.g.