本文整理汇总了PHP中Translatable::get_one_by_locale方法的典型用法代码示例。如果您正苦于以下问题:PHP Translatable::get_one_by_locale方法的具体用法?PHP Translatable::get_one_by_locale怎么用?PHP Translatable::get_one_by_locale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translatable
的用法示例。
在下文中一共展示了Translatable::get_one_by_locale方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetOneByLocale
function testGetOneByLocale()
{
Translatable::disable_locale_filter();
$this->assertEquals(0, TranslatableTest_OneByLocaleDataObject::get()->count(), 'should not be any test objects yet');
Translatable::enable_locale_filter();
$obj = new TranslatableTest_OneByLocaleDataObject();
$obj->TranslatableProperty = 'test - en';
$obj->write();
Translatable::disable_locale_filter();
$this->assertEquals(1, TranslatableTest_OneByLocaleDataObject::get()->count(), 'should not be any test objects yet');
Translatable::enable_locale_filter();
$found = Translatable::get_one_by_locale('TranslatableTest_OneByLocaleDataObject', $obj->Locale);
$this->assertNotNull($found, 'should have found one for ' . $obj->Locale);
$this->assertEquals($obj->ID, $found->ID);
$translated = $obj->createTranslation('de_DE');
$translated->write();
Translatable::disable_locale_filter();
$this->assertEquals(2, TranslatableTest_OneByLocaleDataObject::get()->count(), 'should not be any test objects yet');
Translatable::enable_locale_filter();
$found = Translatable::get_one_by_locale('TranslatableTest_OneByLocaleDataObject', $translated->Locale);
$this->assertNotNull($found, 'should have found one for ' . $translated->Locale);
$this->assertEquals($translated->ID, $found->ID);
// test again to make sure that get_one_by_locale works when locale filter disabled
Translatable::disable_locale_filter();
$found = Translatable::get_one_by_locale('TranslatableTest_OneByLocaleDataObject', $translated->Locale);
$this->assertEquals($translated->ID, $found->ID);
Translatable::enable_locale_filter();
}
示例2: LanguageChooser
/**
* Returns a DataList containing Pages.
* The provided links point to their translated pages.
* You can use it in templates like this:
*
* <% loop LanguageChooser %>
* $Title, $Current, and any other vars in your page instance
* <% end_loop %>
*
* @return DataList
*/
public function LanguageChooser()
{
if (!Controller::curr()) {
return;
}
if ($langs = Translatable::get_allowed_locales()) {
$data = ArrayList::create();
foreach ($langs as $key => $code) {
if ($code == Translatable::get_current_locale()) {
$this->owner->Current = 'current';
$data->push($this->owner);
} else {
$translation = $this->owner->getTranslation($code);
if ($translation) {
$data->push($translation);
} else {
$page = Translatable::get_one_by_locale("SiteTree", $code, "URLSegment LIKE 'home%'");
if ($page) {
$data->push($page);
}
}
}
}
return $data;
}
return false;
}
示例3: PageByDefaultLocale
/**
* PageByDefaultLocale
* gets a page in the default locale
*
* @param string $pageURL url of a page in the default locale
* @return DataObject requested page in the current locale, null if none exists.
*/
function PageByDefaultLocale($pageURL)
{
$defLoc = Translatable::default_locale();
if ($pg = Translatable::get_one_by_locale('Page', $defLoc, "URLSegment = '{$pageURL}'")) {
return $pg;
}
return null;
}
示例4: get_homepage_urlsegment_by_locale
/**
* Gets a URLSegment value for a homepage in another language.
* The value is inferred by finding the homepage in default language
* (as identified by RootURLController::$default_homepage_urlsegment).
* Returns NULL if no translated page can be found.
*
* @param string $locale
* @return string|boolean URLSegment (e.g. "home")
*/
static function get_homepage_urlsegment_by_locale($locale)
{
$origHomepageObj = Translatable::get_one_by_locale('SiteTree', Translatable::default_locale(), sprintf('`URLSegment` = \'%s\'', RootURLController::get_default_homepage_urlsegment()));
if ($origHomepageObj) {
$translatedHomepageObj = $origHomepageObj->getTranslation($locale);
if ($translatedHomepageObj) {
return $translatedHomepageObj->URLSegment;
}
}
return null;
}
示例5: current_site_config
/**
* Get the current sites SiteConfig, and creates a new one
* through {@link make_site_config()} if none is found.
*
* @param string $locale
* @return SiteConfig
*/
static function current_site_config($locale = null)
{
if (Object::has_extension('SiteConfig', "Translatable")) {
$locale = isset($locale) ? $locale : Translatable::get_current_locale();
$siteConfig = Translatable::get_one_by_locale('SiteConfig', $locale);
} else {
$siteConfig = DataObject::get_one('SiteConfig');
}
if (!$siteConfig) {
$siteConfig = self::make_site_config($locale);
}
return $siteConfig;
}