Dominus77 / yii2-advanced-start

Yii2 Start Project Advanced Template

Home Page:https://dominus77.github.io/yii2-advanced-start/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

i18 in ActiveForm field does not work

polinwei opened this issue · comments

$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'),
		];
	}

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

  1. public static function t($category, $message, $params = [], $language = null)

  2. $app->i18n->translations['modules/users/*'] = [

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

  4. Connecting Bootstrap.php in the application configuration

    'modules\users\Bootstrap',

  5. Connecting the module string

    use modules\users\Module;

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

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
    ];
}
//...

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

sendtextform

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

Yes, it should be 1 in 1

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

return [
    //...
    'cellPhoneNo' => 'This cellPhoneNo',
    //...
];

thanks a lot.