Php SilverStripe可翻译保存值在默认区域设置中,并将其复制到非默认区域设置
我用Php SilverStripe可翻译保存值在默认区域设置中,并将其复制到非默认区域设置,php,translation,silverstripe,Php,Translation,Silverstripe,我用SilverStripe3.1.13(CMS和框架)构建了我的项目,我正在使用SilverStripe translateable和dataobjecttranslateable来组织我在网站上的翻译 假设我有Post.php(这是DataObject,用于在我的网站上处理帖子),每个帖子都有自己的类别(many-many关系在这里,但这并不重要) 问题是:在创建新的Post数据对象时,我点击了Save按钮,我希望这些类别将自动复制到其他地区 我如何在我的应用程序中实现这一点?我想将这些值(
SilverStripe
3.1.13(CMS和框架)构建了我的项目,我正在使用SilverStripe translateable
和dataobjecttranslateable
来组织我在网站上的翻译
假设我有Post.php
(这是DataObject
,用于在我的网站上处理帖子),每个帖子都有自己的类别(many-many
关系在这里,但这并不重要)
问题是:在创建新的Post
数据对象时,我点击了Save
按钮,我希望这些类别将自动复制到其他地区
我如何在我的应用程序中实现这一点?我想将这些值(它们是布尔值)保存到这些数据对象的另一个翻译中。可能没有内置功能,但您可以在onAfterWrite()方法中编写类似的内容:
更新$many\u many关系需要处理添加和删除的项目,但不需要再次发布页面。
public function onAfterWrite() {
$this->syncCategories();
}
public function syncCategories() {
//check if you're in main language, assuminig en_US here
if ($this->Locale !== 'en_US') return;
foreach ($this->getTranslations() as $translatedPage) {
//sync relations here
$translatedPage->RelationName = $this->RelationName;
//maybe more fine grained locic for only publishing when translated page is alredy published
$translatedPage->doPublish(); //writes and publishes in one
}
}