i18n with Yii 2 Advanced Template

Hey everyone,

Since I cannot post on the wiki yet, I have created a blog post about setting up i18n with the Advanced template. Here is a link to the post:

Can you please tell me if this is a good way to do it? Anything I can improve on?

Looking forward to your feedback.

Would be nice to see how this would work with DbMessageSource instead of the PhpMessageSource.

I have tried working with translations and DbMessageSource, but for some reason Gii keeps crashing on not existing category’s when I check the i18n checkboxes when I generate models and crud. Can’t figure out how to solve this (yet).

Hi Lifelogger,

DbMessageSource seems to be working fine here, even with Gii. Are you sure that you have defined the base message categories in your i18n components.

My i18n component configuration looks like this:




'i18n' => [

    'translations' => [

        'frontend*' => [

            'class' => 'yii\i18n\DbMessageSource',

        ],

        'backend*' => [

            'class' => 'yii\i18n\DbMessageSource',

        ],

    ],

],



In my case, once I define ‘frontend’ category in the i18n component with DbMessageSource class, I can then use Gii to generate message categories like frontend, frontend/home, frontend/pages,… etc.

Test and let me know if it works for you. Just remember all base categories for messages must be configured when configuring the component.

cheers!

Hmmm, guess I have done something wrong before. It copied your settings and now it works. Thanks!