0

根据文档,我准备了本地化文件:

/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

4

0 回答 0