本文整理匯總了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);
}