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?!
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.Sign up to join this community
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
(Hat tip to Brandon Kelly for helping me understand this better on Craft Slack)