我正在使用Silverstripe Translatable Plugin提供多种语言的网站。但是,我也想翻译内置页面,如Login或Password Reset页面。只是在URL的末尾应用?local=en_US
似乎没有帮助,也无法用第二语言创建一个deidcated登录页面。有没有办法让它发挥作用?
答案 0 :(得分:1)
这是一个解决方案。它的工作原理是扩展Controller类,该类足够低,对处理登录的Security等控制器也有影响。
它会记住上一页的区域设置,然后使用它来呈现“内置页面”。
<强> ControllerDecorator.php 强>
<?php
class ControllerDecorator extends Extension {
function onBeforeInit() {
// If we're on a page, use its Locale information
if($this->getOwner() instanceof ContentController) {
$locale = $this->getOwner()->Locale;
i18n::set_locale($locale);
Cookie::set('Locale', $locale);
}
// Otherwise, use the stored Locale
else if(Cookie::get('Locale')) {
i18n::set_locale(Cookie::get('Locale'));
}
}
}
<强> config.yml 强>
Controller:
extensions:
- ControllerDecorator