5

I'm trying to update my plugin to Craft 3 and I'm getting this error message:

Unable to locate message source for category ''.

What does it mean?!

4

In Craft 2, the Craft default Yii translation method was overridden to only require one value, the value of the translatable string:

Craft::t('My Translatable String');

In Craft 3, Craft reverts to using the default Yii behavior for the Translate method t() and there are two arguments needed. The first argument is now the category and the second is the translatable string:

Craft::t('pluginhandle', 'My Translatable String');

Adding the category back allows translations from different contexts to avoid conflicts with each other.

Craft uses the app category. Yii uses the yii category. And plugins should use their own plugin handles.

The front-end of a site should use site category, and the actual translation files should be saved in translations/locale/category.php (whether that's in craft/ or craft/plugins/mypluginname/)

(Hat tip to Brandon Kelly for helping me understand this better on Craft Slack)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.