2
我正在使用Silverstripe Translatable Plugin提供多種語言的網站。不過,我也想翻譯內置頁面,例如登錄或密碼重置頁面。只要在網址末尾應用?local=en_US
似乎沒有幫助,也無法使用第二種語言創建一個已註冊的登錄頁面。有什麼方法可以使這個工作?翻譯Silverstripe登錄表單和其他內置頁面
我正在使用Silverstripe Translatable Plugin提供多種語言的網站。不過,我也想翻譯內置頁面,例如登錄或密碼重置頁面。只要在網址末尾應用?local=en_US
似乎沒有幫助,也無法使用第二種語言創建一個已註冊的登錄頁面。有什麼方法可以使這個工作?翻譯Silverstripe登錄表單和其他內置頁面
這是一個解決方案。它通過擴展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
我想你必須檢查在控制器初始化::該參數()自己和手動設置語言環境。 – wmk