Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2 translation

I have Yii2 - advanced template I kept source language english And the target language is french The system mesages are translated like : Yii::t('yii','Update') is translated "Modifier"

But all my custom translations do not work - here is what I did :

modified : backend\config\main.php :

    'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@common/messages',
                'sourceLanguage' => 'en-US',
                'fileMap' => [
                    'app' => 'app.php',
                    'app/error' => 'error.php',
                ],
            ],
        ],
    ],
],
'language' => 'fr',

created : common\config\i18n.php

<?php
return [
    'sourcePath' => __DIR__. '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR,
    'languages' => ['fr-FR','en-EN'], //Add languages to the array for the language files to be generated.
    'translator' => 'Yii::t',
    'sort' => false,
    'removeUnused' => false,
    'only' => ['*.php'],
    'except' => [
        '.svn',
        '.git',
        '.gitignore',
        '.gitkeep',
        '.hgignore',
        '.hgkeep',
        '/messages',
        '/vendor',
    ],
    'format' => 'php',
    'messagePath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages',
    'overwrite' => true,
];

Sure that I must have mixed up something but I can't find - Some help would be nice !

like image 515
G. Trennert Avatar asked Mar 09 '15 20:03

G. Trennert


People also ask

What language is Yii?

Yii is a high-performance, component-based PHP framework for developing large-scale Web applications rapidly. It enables maximum reusability in Web programming and can significantly accelerate your Web application development process. The name Yii (pronounced Yee or [ji:] ) is an acroynym for "Yes It Is!".

What is Yii:: t()?

The Yii::t() method will call the i18n application component translate method to perform the actual translation work.


1 Answers

Your configuration looks correct. I assume you have the fr folder in your common/messages folder for your custom translations.

You need to use Yii::t('app','your_custom_word');.

your_custom_word should be defined in the common/messages/fr/app.php file.

like image 106
Chinmay Waghmare Avatar answered Sep 30 '22 22:09

Chinmay Waghmare