PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 19, 2022

[FIXED] How to configure gettext with Yii::t() in Yii2 advanced?

 March 19, 2022     gettext, multilingual, php, yii, yii2     No comments   

Issue

I'm installed Yii2 advanced template and configure Yii::t() with PhpMessageSource, but i need configure it with GettextMessageSource. I'm added to common/config/main-local.php this code:

'i18n' => [
            'translations' => [
                'app*' => [
                    'class' => 'yii\i18n\GettextMessageSource',
                    'basePath' => '@app/messages',
                    'sourceLanguage' => 'en-US',
                ],
            ],
        ],

Put at frontend/messages/ru-RU app.po file sample text:

msgid "TEST"
msgstr "Текст"

Add in view file:

Yii::t('app', 'TEST');

But it doesn't work, where i need to store .po files or what i'm doing wrong?


Solution

'basePath' => '@app/messages',

change to 'basePath' => '@common/messages', or 'basePath' => '@root/common/messages

and replace your messages to common/messages.



Answered By - zelenin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing