Unable To Locate Message Source For Category

I am using the default language configuration as outlined here:




	'i18n' => [

		'translations' => [

			'*' => [

				'class' => 'yii\i18n\PhpMessageSource'

			],

		],

	],



I am receiving the error message "Unable to locate message source for category" (Invalid Configuration).

I have a standard directory structure using the ‘advanced’ option. Where exactly within this directory structure should the /messages/ directory be located? Or is there something else wrong with the configuration? (is the example in the docs incomplete?)

1 Like

Not sure what I did, but I no longer get the error, however the language definitions are not loaded, so I assume that the /messages/directory is not being found. I have placed it in various locations to no avail.

The docs are not particularly helpful since they do not contain complete information.

Who knows?

Run




./yii help message

./yii help message/config

./yii help message/extract



Basically you need to create config file for translations first.

Thank you very much for your help. Is the above documented somewhere other than the "help" in the commands?

Ok, I have it working, but something is not as I expected.

The default language in Yii is ‘en-US’. Yii::t() will not look for the default language in the /messages/ directory.

I wish to use placeholders in my code and not have language strings anywhere other than /messages/, eg.


$this->title = \Yii::t('signup', 'PAGE_TITLE');

How can I make Yii look for the default language in /messages/ ?

*EDIT:

Ok, this works. In my main config file:


'sourceLanguage'=>'',

Well, I’m not sure… Also I don’t remember how I have come to this. Probably I was browsing the API and not the docs.

Anyway, since Yii2 is officially beta now (so API is stabilized), there’ll be a great improvements in documentation soon.

That’s great to hear. I am looking at starting a major project with Yii2 and if it’s now beta that’s fabulous!

Hi,

i have the same problem, but i can’t solve it.

I have an advanced Yii install.

I put messages in root (not in common, neither front, neither backend).

I have messages/fr/login.php

I generate a config.php file on which i set up only ‘languages’ => [‘fr’],

I set in one of my controllers


\Yii::$app->language = 'fr';

and in the login view :


<?= \Yii::t('login','Password'); ?>

But I’m stuck with ‘Password’ word which is not translated into ‘Mot de passe’, which stands in login.php in messages/fr/login.php

Do you know how i can go beyond this ?

Thx

Hi! I’m the same problem with internationalization…

I configure it on my advanced template in common/config/main.php as :

‘i18n’ => [

        'translations' =&gt; [


            'app' =&gt; [


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


                'basePath' =&gt; '@app/messages',


                


            ],


        ],


    ],

it run but using messages folder located in vendor…so I want use a new messages folder to no use that

But I’can’t map for others files as different category from default and divide backend to frontend for messages mapped path

can you help me please :unsure:

I was using devout and getting same error. And solve problem with above setting. Thanks