Search code examples
translationcraftcms

Craft static translation defaults


When using Craft::t('category', 'string') it would look in the "category" file for the "key" called "string" and then take that value as the translation.

Right now when I tested where the key "string" was not present in the translation file it would just output the word string.

What if I wanted to have fallback or default translated value for those cases?

Couldn't find it in the docs so far...
https://docs.craftcms.com/v3/static-translations.html#prep-your-messages
https://www.yiiframework.com/doc/api/2.0/yii-baseyii#t()-detail

Is it possible to have a fallback/default or default translation when the key is missing in the translationfile?


Solution

  • It seems Craft is just being a little agnostic here as it probably depends on your workflow. For example sometime ensuring translations are defined are built into CI processes.

    Yii does have a build in feature you could implement relatively quickly. https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n#missing-translations

    But to answer your question directly - no there's no built in function for missing translations.