Setting default values for Yii:t


I am writing you regarding this particular question I have. Is it possible to override default Yii:t behaviour and produce blank (’ ') messages for values that do not exist in particular translate file(s)? For example, we have a translation string somewhere within a view echo Yii:t(‘app’, ‘string’);. Supposedly, in app, ‘string’ value is defined

as follows: ‘[size=“4”]string’ => ‘’[/size].

Would it be possible to override default behaviour and return blank values instead of the labels themselves even if they are not defined in translation file? At the moment Yii:t will return a ‘string’ value if it is not defined in translation file, would it be possible to retrieve blank/space string for all possible occurances? Or should I just define translations as [size=“4”]‘string’ => ’ '[/size] to deal with it?

Best regards,

In configuration ‘components’ add:

    'i18n' => [

        'translations' => [

            'app*' => [

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

                'on missingTranslation' => function ($event) {

                    $event->translatedMessage = '';






As far as I understand your question:

The translation is ‘sourceLangString’ => ‘translatedLangString’

When there is no "translatedLangString" you see the "sourceLangString" (default behaviour)

But you want to see nothing at all when there is no "translatedLangSting"?

Take a look at:

Nearly at the end of the document is part called "Handling missing translations".

Follow the instructions there…

But build a diferent "handleMissingTranslation" function.

Like for example:

    public static function handleMissingTranslation(MissingTranslationEvent $event) {

        $event->translatedMessage = "";


Should do what you want.


EDIT: Bizley was much faster. :)