根据doc,我准备了我的本地化文件:
/src
/Locale
/...
/es_ES
default.po
我的default.po
包含类似
msgid "Oui"
msgstr "Sí"
msgid "Non"
msgstr "Non"
msgid "Continuer"
msgstr "Continuar"
我当然在我看来使用__("...")
。
我在控制器中添加了I18n::locale('es_ES');
。
但视图仍然是默认语言。
我想念什么?
如何通过以下方式选择语言:
// inconfig/bootstrap.php
DispatcherFactory::add('LocaleSelector');
// Limite locales to en_US and fr_FR only
DispatcherFactory::add('LocaleSelector', ['locales' => ['en_US', 'fr_FR']]);
修改 我想我现在必须在3.4中编写以下代码:
class Application extends BaseApplication
{
/**
* Setup the middleware your application will use.
*
* @param \Cake\Http\MiddlewareQueue $middleware The middleware queue to setup.
* @return \Cake\Http\MiddlewareQueue The updated middleware.
*/
public function middleware($middleware)
{
$middleware
// Catch any exceptions in the lower layers,
// and make an error page/response
->add(ErrorHandlerMiddleware::class)
// Handle plugin/theme assets like CakePHP normally does.
->add(AssetMiddleware::class)
// Apply routing
->add(RoutingMiddleware::class)
->add(new LocaleSelectorMiddleware(['de', 'fr','en', 'es', 'it', 'nl'])); // I added this to the skeleton
return $middleware;
}
}
我还修改了webroot/index.php