Yii2 how to set default language in codemix url manager

923 Views Asked by At

This app ru language start

    'language'=>'uz',
'i18n' => [
            'translations' => [
                '*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@frontend/messages',
                    'sourceLanguage' => 'uz',
                    'fileMap' => [
                        'main' => 'main.php',
                        'yii' => 'yii.php',
                    ],
                ],
            ],
        ],
'urlManager' => [
            'class' => 'codemix\localeurls\UrlManager',
            'showScriptName' => false,
            'enableLanguageDetection' => true,
            'enablePrettyUrl' => true,
//            'defaultLanguage'=>'uz',
            'enableDefaultLanguageUrlCode' => true,
            'languages' => ['uz', 'ru','oz','en'],

I am set system langugae uz, source langugae uz and codemix url manager one method have defaultLangugae but its not working
this error picture

2

There are 2 best solutions below

4
Muhammad Omer Aslam On

Never used it but looking at the source code it says you need to use the languages option as an array of language codes. More specific patterns should come first, e.g. 'en_us' before 'en'. This can also contain mapping of <url_value> => <language>, e.g. 'english' => 'en'.

ou need to change the option to 'languages' => ['en_us'],

0
Abdualiym On

You must setup language for app config.

UPD: Setup config(frontend/config/main.php) to needed language for app. Then first time app will launch in this language: 'language' => 'en'.

If this not work check in incognito mode, you must clean old session saved cookies