SilverStripe Fluent模块具有现成的模板,可在前端显示简单的语言切换菜单.
$Title.XML
当它循环“Locales”时它在技术上是什么循环?没有名为“Locales”的数据库表.
我的目标是最终找到返回语言缩写的变量(或编写函数)(而不是国家!).所以我需要返回的东西,例如nl而不是nl-NL(因为$LocaleRFC1766返回).
解决方法:
FluentExtension扩展中的Locales is a function:
/**
* Templatable list of all locales
*
* @return ArrayList
*/
public function Locales()
{
$data = array();
foreach (Fluent::locales() as $locale) {
$data[] = $this->owner->LocaleInformation($locale);
}
return new ArrayList($data);
}
$data = array(
'Locale' => $locale,
'LocaleRFC1766' => i18n::convert_rfc1766($locale),
'Alias' => Fluent::alias($locale),
'Title' => i18n::get_locale_name($locale),
'LanguageNative' => Fluent::locale_native_name($locale),
'Language' => i18n::get_lang_from_locale($locale),
'Link' => $link,
'AbsoluteLink' => $link ? Director::absoluteURL($link) : null,
'LinkingMode' => $linkingMode
);
最近添加了语言以允许仅检索语言缩写.
要使用它,我们可以创建一个使用$Language变量的自定义LocaleMenu.ss模板:
标签:php,silverstripe
来源: https://codeday.me/bug/20190608/1200841.html