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 in ActiveForm field does not work #11

Closed polinwei closed 6 years ago

polinwei commented 6 years ago

$form->field($model, 'cellPhoneNo')->textInput(['class' => 'form-control']) the wording cellPhoneNo can not translate correct.

model code

    public function attributeLabels()
    {
        return [
                'cellPhoneNo' => Module::t('module', 'cellPhoneNo'),
                'message' => Yii::t('app', 'Message'),
        ];
    }
Dominus77 commented 6 years ago

Hi! Check the module configuration Using the users module as an example

  1. https://github.com/Dominus77/yii2-advanced-start/blob/9b32ccbb57c3624e00c038609f845c10482fce33/modules/users/Module.php#L67

  2. https://github.com/Dominus77/yii2-advanced-start/blob/9b32ccbb57c3624e00c038609f845c10482fce33/modules/users/Bootstrap.php#L21

  3. Existence of folders https://github.com/Dominus77/yii2-advanced-start/tree/master/modules/users/messages

  4. Connecting Bootstrap.php in the application configuration https://github.com/Dominus77/yii2-advanced-start/blob/9b32ccbb57c3624e00c038609f845c10482fce33/frontend/config/main.php#L17

  5. Connecting the module string https://github.com/Dominus77/yii2-advanced-start/blob/9b32ccbb57c3624e00c038609f845c10482fce33/modules/users/models/User.php#L12

polinwei commented 6 years ago

Hi Sir: I did all above steps. In the view: sendtext.php , only outside of ActiveForm like Module::t('module', 'SendCHTMessage'); can work.

View: view

Bootstrap bootstrap

config config frontend frontend

model model

module module

Dominus77 commented 6 years ago

Model SendtextForm

namespace modules\sms\models;
use modules\sms\Module;

//...
public function attributeLabels()
{
    return [
        'cellPhoneNo' => Module::t('module', 'cellPhoneNo'), // This lang file in: /modules/sms/messages/zh-TW/module.php
        'message' => Yii::t('app', 'Message'), // This lang file in: /frontend/messages/zh-TW/app.php
    ];
}
//...
polinwei commented 6 years ago

Yes , I also did it. It can not show the message: zh-TW\module.php

sendtextform

polinwei commented 6 years ago

Hi Sir: I found out the key point . The key word is sensitive. I correct it then can work.

Dominus77 commented 6 years ago

Yes, it should be 1 in 1

Dominus77 commented 6 years ago

/modules/sms/messages/zh-TW/module.php

return [
    //...
    'cellPhoneNo' => 'This cellPhoneNo',
    //...
];
polinwei commented 6 years ago

thanks a lot.