seniorpreacher
seniorpreacher

Reputation: 666

Using Yii2's default messages

I can't figure out, how to use Yii's default messages, without overwriting them with the message command.

I have 2 translation categories: app, data.

I'd like to use the default messages, like "Are you sure you want to delete this item?" and "(not set)" from the Yii2 core, but if I use Yii::t('yii', 'Are you sure you want to delete this item?') and then run the yii message command, it creates a yii.php file in the messages folder with this token.

Part of my config:

    'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages',
            ],
            'data*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@app/messages',
            ],
        ],
    ],

How should I set up my config to use the built in texts and not to overwrite them?

Upvotes: 0

Views: 946

Answers (1)

Blizz
Blizz

Reputation: 8408

You don't have to do anything. The yii-category is automatically defined as soon as you use translation and it points to the messages in the framework.

That it creates an empty file is for 'yii' is normal, because you actually use that category in your code. This is unrelated to where the messages will be loaded from during normal execution.

Just make sure that you configure your apps' language and sourceLanguage correctly if not already done.

Upvotes: 1

Related Questions