Language Translation desn't work on Linux

[size="5"]the problem is solved.[/size]

see:

http://www.yiiframework.com/forum/index.php/topic/75516-language-translation-desnt-work-on-linux/page__view__findpost__p__312162

The Yii2.0.12 works fine on my windows xp with xampp. So I have copiered it on the Linux server with CentOs 7.1 and apache with cpanel 12. I have run


php init

All other work fine but the Language Translation. The requirement of yii2 has passed. See Attchment.

Thans in advance.

7445

requirement.PNG

Please give us more information in order to pinpoint the cause of your error. Is there any clue in the application log, for instance?

But the most probable cause is the case-sensitivity problem when something runs fine on Windows but not on linux. Check the filenames involved in the language translation.

Yes, I thought it WAS. There are not many cases to check and I did it, found nothing.

Do you say that built-in translations of yii (e.g. “OK”, “Cancel”, “Next”, “Prev”) failed to work? Or is it your custom translation that didn’t work?

And have you found nothing in the application log?

only the custom translation doesn’t work.

I test in the following way:

[size="4"]site/index:[/size]


    

public function actionIndex()

    {

        echo "PHP: " . PHP_VERSION . "<br>";

        echo "ICU: " . INTL_ICU_VERSION . "<br>";

        yii::$app->language = 'de-DE';

        //yii::$app->language = 'zh-CN';

        echo yii::$app->language . "<br>"; 

        echo Yii::t('app', 'testEN') . "<br>";

        echo yii::t('app', 'testEN') . "<br>";

        //exit;



result:

[size="4"]common/messages/de-DE/app.php:[/size]




<?php

return [

    'testEN' => 'testGerman',

];



[size="4"]common/config/main-local.php:[/size]




            'i18n' =>

                [

                    'translations' =>

                        [

                            'app*' =>

                                [

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

                                    'basePath' => dirname(__DIR__) . '\messages',

                                    'sourceLanguage' => 'en-US',

                                    'forceTranslation' => true,


                                    'fileMap' =>

                                        [

                                            'app*' => 'app.php',

                                            'frontend*' => 'app.php',

                                            'app/error' => 'error.php',

                                        ],

                                        

                                    'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']

                                ],


                            'frontend*' =>

                                [

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

                                    'basePath' => dirname(__DIR__) . '\messages',

                                    'sourceLanguage' => 'en-US',

                                    //'sourceLanguage' => 'de-DE',

                                    'forceTranslation' => true,


                                    'fileMap' =>

                                        [

                                            'app*' => 'app.php',

                                            'frontend' => 'app.php',

                                            'app/error' => 'error.php',

                                        ],

                                        

                            

                                    'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']          

                                ],


                            'backend*' =>

                                [

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

                                    'basePath' => dirname(__DIR__) . '\messages',

                                    'sourceLanguage' => 'en-US',

                            

                                    'forceTranslation' => true,

                                    

                                    'fileMap' =>

                                        [

                                            'app*' => 'app.php',

                                            'backend*' => 'app.php',

                                            'app/error' => 'error.php',

                                        ],

                                

                                

                                'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']          

                                ],

                                

                            '*' =>

                                [

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

                                    'basePath' => dirname(__DIR__) . '\messages',

                                    'sourceLanguage' => 'en-US',

                        

                                    'forceTranslation' => true,

                                    

                                    'fileMap' =>

                                        [

                                            'app*' => 'app.php',

                                            'frontend*' => 'app.php',

                                            'backend*' => 'app.php',

                                            'app/error' => 'error.php',

                                        ],

                                        

                                    'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']                                         


                                ],

                     ],

                ],



[size="4"]common/messages/config.php[/size]

I think we don’t need this config at all.




<?php


return [


    'languages' => 

               [

                    'en-US',

                    'de-DE',

                    'tr-TR',

                    'ro-RO',

                    'hu-HU',

                    'cs-CZ',

                    'pl-PL',

                    'bg-BG',

                    'fr-FR',

                    'es-ES',

                    'pt-PT',

                    'ru-RU',

                    'zh-CN'

                ],


    'translator' => 'Yii::t',


    'sort' => false,


    'removeUnused' => false,


    'only' => ['*.php'],


    'except' => [

        '.svn',

        '.git',

        '.gitignore',

        '.gitkeep',

        '.hgignore',

        '.hgkeep',

        '/messages',

    ],


    'format' => 'php',


    'messagePath' => __DIR__,


    'overwrite' => true,


    'catalog' => 'app',

    'catalog' => 'frondend',

    'catalog' => 'backend',

    'catalog' => 'messages',


    'overwrite' => true,

];



Thanks for reading.

[size="4"]the problem is solved.[/size]

reason:

in the i18n config:


'basePath' => dirname(__DIR__) . '\messages',

the ‘\’ works in windows but in linux, in linux works with ‘/’.

solution:

use:“DIRECTORY_SEPARATOR”


'basePath' => dirname(__DIR__) . DIRECTORY_SEPARATOR . 'messages',

Thanks anyway.

Congrats!