unable to convert string eng to mh language using language translation

I have doing language translation in yiii .

Following steps are completed by me

  1. I have created file for message

Project Folder

      messages 


          mh


            app.php

content of app.php files are

<?php

return [

  'This is a string to translate&#33;' =&gt; 'Эта строка для перевода&#33;'

];

?>

also make following setting

<?php

$params = require(DIR . ‘/params.php’);

$config = [

  'id' =&gt; 'basic',


  'basePath' =&gt; dirname(__DIR__),


  'bootstrap' =&gt; ['log'],


  'components' =&gt; [


     'request' =&gt; [


        // &#33;&#33;&#33; insert a secret key in the following (if it is empty) - this


           //is required by cookie validation


        'cookieValidationKey' =&gt; 'ymoaYrebZHa8gURuolioHGlK8fLXCKjO',


     ],


     'cache' =&gt; [


        'class' =&gt; 'yii&#092;caching&#092;FileCache',


     ],


     'i18n' =&gt; [


        'translations' =&gt; [


           'app*' =&gt; [


              'class' =&gt; 'yii&#092;i18n&#092;PhpMessageSource',


              'fileMap' =&gt; [


                 'app' =&gt; 'app.php'


              ],


           ],


        ],


     ],


     'user' =&gt; [


        'identityClass' =&gt; 'app&#092;models&#092;User',


        'enableAutoLogin' =&gt; true,


     ],


     'errorHandler' =&gt; [


        'errorAction' =&gt; 'site/error',


     ],


     'mailer' =&gt; [


        'class' =&gt; 'yii&#092;swiftmailer&#092;Mailer',


        // send all mails to a file by default. You have to set


        // 'useFileTransport' to false and configure a transport


        // for the mailer to send real emails.


        'useFileTransport' =&gt; true,


     ],


     'log' =&gt; [


        'flushInterval' =&gt; 1,


        'traceLevel' =&gt; YII_DEBUG ? 3 : 0,


        'targets' =&gt; [


           [


              'class' =&gt; 'yii&#092;log&#092;FileTarget',


              'exportInterval' =&gt; 1,


              'logVars' =&gt; [],


           ],


        ],


     ],


     'db' =&gt; require(__DIR__ . '/db.php'),


  ],


  // set target language to be Russian


  'language' =&gt; 'mh',


  // set source language to be English


  'sourceLanguage' =&gt; 'en-US',


  'modules' =&gt; [


     'hello' =&gt; [


        'class' =&gt; 'app&#092;modules&#092;hello&#092;Hello',


     ],


  ],


  'params' =&gt; &#036;params,

];

if (YII_ENV_DEV) {

  // configuration adjustments for 'dev' environment


  &#036;config['bootstrap'][] = 'debug';


  &#036;config['modules']['debug'] = [


     'class' =&gt; 'yii&#092;debug&#092;Module',


  ];


  &#036;config['bootstrap'][] = 'gii';


  &#036;config['modules']['gii'] = [


     'class' =&gt; 'yii&#092;gii&#092;Module',


  ];

}

return $config;

?>

But when i print above translation…It shows only original text…nt translated text.

echo \Yii::$app->language;

echo \Yii::t(‘app’, ‘This is a string to translate!, {username}!’, [

'username' =&gt;'John',

]);

Output

This is a string to translate!

How about this code?




echo \Yii::t('app', 'This is a string to translate!');



I am using this to print the translation in controller.

but It showing only original text instead of displaying translated value

Are you using basic or an advanced application type?

The problem is string you are trying to translate isn’t the same as string in language file.

In your code:


'This is a string to translate!, {username}!'

In your language file:


'This is a string to translate!'