CakePHP3:无法实现本地化工作

时间:2017-04-05 13:32:11

标签: cakephp localization internationalization cakephp-3.4

根据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

0 个答案:

没有答案