Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template
https://dominus77.github.io/yii2-advanced-start/
MIT License
23 stars 12 forks source link

i18 message not found #3

Closed polinwei closed 7 years ago

polinwei commented 7 years ago

Hi Sir: When I set up 'language' => 'en-US' in common\config\main.php , backend & frontend not found the current message file. Which file I need to setup?

<?php return [ 'name' => 'Yii2-advanced-start', 'timeZone' => 'Asia/Taipei', 'language' => 'en-US', 'vendorPath' => dirname(dirname(__DIR__)) . '/vendor',

Dominus77 commented 7 years ago

Hi! On what page?

polinwei commented 7 years ago

In http://mysite.com , I see those words: NAV_HOME, NAV_ABOUT, NAV_CONTACT, NAV_MY_MENU

In http://mystart.com/admin , those words are TITLE_HOME ,TITLE_USERS,TITLE_USERS

polinwei commented 7 years ago

I change to 'language' => 'en' , then workable. strange.

polinwei commented 7 years ago

I found your layout will cut off the full word. I look the source code is <html lang="ru"> or <html lang="en">

Dominus77 commented 7 years ago

Yes! https://github.com/Dominus77/yii2-advanced-start/blob/288682261f87af0a72a6abb2693d55d0076c8fe5/frontend/views/layouts/main.php#L17

<html lang="<?= mb_substr(Yii::$app->language, 0, strrpos(Yii::$app->language, '-')); ?>">
<html lang="<?= Yii::$app->language; ?>">
polinwei commented 7 years ago

May I ask you which the rule for the i18 message? I found those message in modules, api, backend, common...

Dominus77 commented 7 years ago

In the main template, the translation is global, for its frontend, for backend its correspondingly \Yii::t('app', 'NAV_HOME'); Global translations are in the messages folder of the corresponding application frontend https://github.com/Dominus77/yii2-advanced-start/tree/master/frontend/messages backend https://github.com/Dominus77/yii2-advanced-start/tree/master/backend/messages In modules, the structure is the same, but it is called differently if the translation is not global Example: \modules\main\Module::t('module', 'Home'); The translations are in modules \ main \ messages \ en \ module.php and modules \ main \ messages \ ru \ module.php

Accordingly, you need to configure this in Module.php and Bootstrap.php https://github.com/Dominus77/yii2-advanced-start/tree/master/modules/main and connect in the config application Bootstrap.php https://github.com/Dominus77/yii2-advanced-start/blob/288682261f87af0a72a6abb2693d55d0076c8fe5/frontend/config/main.php#L16

Dominus77 commented 7 years ago

http://www.yiiframework.com/doc-2.0/guide-tutorial-i18n.html

polinwei commented 7 years ago

Understood. thanks.

polinwei commented 7 years ago

Sorry !! Ask other questions: After I changed the layout to <html lang="<?= Yii::$app->language ?>">

why not work?

Dominus77 commented 7 years ago

And in the config parameter language? https://github.com/Dominus77/yii2-advanced-start/blob/288682261f87af0a72a6abb2693d55d0076c8fe5/frontend/config/main.php#L11 This parameter is set there

polinwei commented 7 years ago

I setup 'language' => 'en-US' in common\config\main.php

layout: <html lang="<?= Yii::$app->language ?>">

polinwei commented 7 years ago

but Chinese is work !! Ha , It is I need.

'language' => 'zh-TW'

Dominus77 commented 7 years ago

Then this parameter in the backend and frontend should be removed or commented out https://github.com/Dominus77/yii2-advanced-start/blob/288682261f87af0a72a6abb2693d55d0076c8fe5/frontend/config/main.php#L11 frontend and backend //'language'=>'ru-RU', common 'language' => 'zh-TW'

polinwei commented 7 years ago

Yes , I did it . but not workable for 'en-US'

Dominus77 commented 7 years ago

Not displayed in code? <html lang="en-US">

polinwei commented 7 years ago

HTML code is show <html lang="en-US"> but message is the key 'NAV_HOME....'

Dominus77 commented 7 years ago

in the application's messages folder, there is an en-US folder and the app.php translation file in it? https://github.com/Dominus77/yii2-advanced-start/tree/288682261f87af0a72a6abb2693d55d0076c8fe5/frontend/messages/en-US

Dominus77 commented 7 years ago

At me all works, I switch language in common, the language changes to Russian or English

Dominus77 commented 7 years ago

Probably my work is English because by default I'm writing in English, now I'll check with the contants))

polinwei commented 7 years ago

I am only not work for 'en-US' , others is fine. FYI

Thanks , I am learning much from you.

Dominus77 commented 7 years ago

Checked, specify 'en' instead of 'en-US'

Dominus77 commented 7 years ago

I'm still that teacher))) I can tell if I know myself.

Dominus77 commented 7 years ago

By the way, recently made a plug-in for highlighting syntax, I advise you to look instead of SyntaxHighlighter https://github.com/Dominus77/yii2-highlight-plugin

polinwei commented 7 years ago

Got it . Thanks a lot.