PHP code example of yii1tech / i18n-fallback

1. Go to this page and download the library: Download yii1tech/i18n-fallback library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yii1tech / i18n-fallback example snippets




return [
    'components' => [
        'messages' => [
            'class' => CDbMessageSource::class, // use database source, controlled via admin panel
            'forceTranslation' => true,
            'behaviors' => [
                'fallbackBehavior' => [
                    'class' => yii1tech\i18n\fallback\MessageSourceFallbackBehavior::class,
                    'fallbackMessageSource' => [
                        'class' => CPhpMessageSource::class, // fallback to local translation files, if message is missing in the database
                        'forceTranslation' => true,
                    ],
                ],
            ],
        ],
        // ...
    ],
    // ...
];



return [
    'components' => [
        'messages' => [
            'class' => CPhpMessageSource::class, // setup single message source
            'forceTranslation' => true,
            'behaviors' => [
                'fallbackBehavior' => [
                    'class' => yii1tech\i18n\fallback\MessageSourceFallbackBehavior::class,
                    'fallbackLanguage' => 'en_us', // fallback to 'en_us', if translation is missing in some language (like 'es', 'ru', etc.)
                ],
            ],
        ],
        // ...
    ],
    // ...
];



return [
    'components' => [
        'messages' => [
            'class' => CDbMessageSource::class, // use database source, controlled via admin panel
            'forceTranslation' => true,
            'behaviors' => [
                'fallbackBehavior' => [
                    'class' => yii1tech\i18n\fallback\MessageSourceFallbackBehavior::class,
                    'fallbackMessageSource' => [
                        'class' => CPhpMessageSource::class, // fallback to local translation files, if message is missing in the database
                        'forceTranslation' => true,
                        'behaviors' => [
                            'fallbackBehavior' => [
                                'class' => yii1tech\i18n\fallback\MessageSourceFallbackBehavior::class,
                                'fallbackLanguage' => 'en_us', // fallback to 'en_us', if translation is missing in some language (like 'es', 'ru', etc.)
                            ],
                        ],
                    ],
                ],
            ],
        ],
        // ...
    ],
    // ...
];