本文整理汇总了PHP中SiteTree::getTranslations方法的典型用法代码示例。如果您正苦于以下问题:PHP SiteTree::getTranslations方法的具体用法?PHP SiteTree::getTranslations怎么用?PHP SiteTree::getTranslations使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SiteTree
的用法示例。
在下文中一共展示了SiteTree::getTranslations方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testTranslationGroups
function testTranslationGroups()
{
// first in french
$frPage = new SiteTree();
$frPage->Locale = 'fr_FR';
$frPage->write();
// second in english (from french "original")
$enPage = $frPage->createTranslation('en_US');
// third in spanish (from the english translation)
$esPage = $enPage->createTranslation('es_ES');
// test french
$this->assertEquals($frPage->getTranslations()->column('Locale'), array('en_US', 'es_ES'));
$this->assertNotNull($frPage->getTranslation('en_US'));
$this->assertEquals($frPage->getTranslation('en_US')->ID, $enPage->ID);
$this->assertNotNull($frPage->getTranslation('es_ES'));
$this->assertEquals($frPage->getTranslation('es_ES')->ID, $esPage->ID);
// test english
$this->assertEquals($enPage->getTranslations()->column('Locale'), array('fr_FR', 'es_ES'));
$this->assertNotNull($frPage->getTranslation('fr_FR'));
$this->assertEquals($enPage->getTranslation('fr_FR')->ID, $frPage->ID);
$this->assertNotNull($frPage->getTranslation('es_ES'));
$this->assertEquals($enPage->getTranslation('es_ES')->ID, $esPage->ID);
// test spanish
$this->assertEquals($esPage->getTranslations()->column('Locale'), array('fr_FR', 'en_US'));
$this->assertNotNull($esPage->getTranslation('fr_FR'));
$this->assertEquals($esPage->getTranslation('fr_FR')->ID, $frPage->ID);
$this->assertNotNull($esPage->getTranslation('en_US'));
$this->assertEquals($esPage->getTranslation('en_US')->ID, $enPage->ID);
}
示例2: SiteTree
function testTranslationGroupsWhenTranslationIsSubclass()
{
// create an English SiteTree
$enST = new SiteTree();
$enST->Locale = 'en_US';
$enST->write();
// create French and Spanish translations
$frST = $enST->createTranslation('fr_FR');
$esST = $enST->createTranslation('es_ES');
// test that we get the right translations back from each instance
$this->assertArrayEqualsAfterSort(array('fr_FR', 'es_ES'), $enST->getTranslations()->column('Locale'));
$this->assertArrayEqualsAfterSort(array('en_US', 'es_ES'), $frST->getTranslations()->column('Locale'));
$this->assertArrayEqualsAfterSort(array('en_US', 'fr_FR'), $esST->getTranslations()->column('Locale'));
// this should be considered an edge-case, but on some sites translations
// may be allowed to be a subclass of the default locale's translation of
// the same page. In this case, we need to support getTranslations returning
// all of the translations, even if one of the translations is a different
// class from others
$esST->setClassName('Page');
$esST->write();
$esPg = DataObject::get_by_id('Page', $esST->ID, $cache = false);
// make sure we successfully changed the class
$this->assertClass('Page', $esPg);
// and make sure that the class of the others did not change
$frST = DataObject::get_by_id('SiteTree', $frST->ID, $cache = false);
$this->assertClass('SiteTree', $frST);
$enST = DataObject::get_by_id('SiteTree', $enST->ID, $cache = false);
$this->assertClass('SiteTree', $enST);
// now that we know our edge case is successfully configured, we need to
// make sure that we get the right translations back from everything
$this->assertArrayEqualsAfterSort(array('fr_FR', 'es_ES'), $enST->getTranslations()->column('Locale'));
$this->assertArrayEqualsAfterSort(array('en_US', 'es_ES'), $frST->getTranslations()->column('Locale'));
$this->assertArrayEqualsAfterSort(array('en_US', 'fr_FR'), $esPg->getTranslations()->column('Locale'));
$this->assertEquals($enST->ID, $esPg->getTranslation('en_US')->ID);
$this->assertEquals($frST->ID, $esPg->getTranslation('fr_FR')->ID);
$this->assertEquals($esPg->ID, $enST->getTranslation('es_ES')->ID);
$this->assertEquals($esPg->ID, $frST->getTranslation('es_ES')->ID);
}