yii的gii工具很方便,但是生成后默认的是英文,虽然可以逐个更改成中文的,但这显然不是好的办法。下面是我遇到的问题。
1、表单数据提示错误,显示是cannot be blank。将这个cannot be blank变成中文的,解决办法是在配置文件中添加:
'language'=>'zh_cn',
2、如何将下面的情况变成中文的:
包括导航的英文。解决办法是更改框架中默认的模板文件:F:\yii\framework\gii\generators\crud\templates\default。
下面这篇文章讲解的很好,摘抄如下:
修改CRUD的模板中的英文变中文步骤: 打开目录 framework\gii\generators\crud\templates\default 修改_form.php 找到: <p class="note">Fields with <span class="required">*</span> are required.</p> 修改为: <p>字段带<span class="required">*</span> 的为必填项.</p> 找到: <?php echo "<?php echo CHtml::submitButton(\$model->isNewRecord ? 'Create' : 'Save'); ?>\n"; ?> 修改为: <?php echo "<?php echo CHtml::submitButton(\$model->isNewRecord ? '新增' : '更新'); ?>\n"; ?> 修改_search.php 找到: <?php echo "<?php echo CHtml::submitButton('Search'); ?>\n"; ?> 修改为: <?php echo "<?php echo CHtml::submitButton('搜索'); ?>\n"; ?> 修改admin.php 找到: echo "\$this->breadcrumbs=array( '$label'=>array('index'), 'Manage', );\n"; 修改为: echo "\$this->breadcrumbs=array( '$label'=>array('index'), '管理', );\n"; 找到: $this->menu=array( array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')), ); 修改为: $this->menu=array( array('label'=>'列表 <?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'新增 <?php echo $this->modelClass; ?>', 'url'=>array('create')), ); 找到: <h1>Manage <?php echo $this->pluralize($this->class2name($this->modelClass)); ?></h1> 修改为 <h1>管理<?php echo $this->pluralize($this->class2name($this->modelClass)); ?></h1> 找到: <p> You may optionally enter a comparison operator (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b> or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done. </p> 修改为: <p> 你可以输入一个比较运算符 (<b><</b>, <b><=</b>, <b>></b>, <b>>=</b>, <b><></b> 或者 <b>=</b>) 在你要进行比较搜索的值之前. </p> 找到: <?php echo "<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>"; ?> 修改为: <?php echo "<?php echo CHtml::link('高级搜索','#',array('class'=>'search-button')); ?>"; ?> 修改create.php 找到: echo "\$this->breadcrumbs=array( '$label'=>array('index'), 'Create', );\n"; 修改为: echo "\$this->breadcrumbs=array( '$label'=>array('index'), '新增', );\n"; 找到: $this->menu=array( array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')), ); 修改为: $this->menu=array( array('label'=>'列表 <?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'管理e<?php echo $this->modelClass; ?>', 'url'=>array('admin')), ); 找到: <h1>Create <?php echo $this->modelClass; ?></h1> 修改为: <h1>新增 <?php echo $this->modelClass; ?></h1> 修改index.php 找到: array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')), array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')), 修改为: array('label'=>'新增<?php echo $this->modelClass; ?>', 'url'=>array('create')), array('label'=>'管理<?php echo $this->modelClass; ?>', 'url'=>array('admin')), 修改update.php 找到: echo "\$this->breadcrumbs=array( '$label'=>array('index'), \$model->{$nameColumn}=>array('view','id'=>\$model->{$this->tableSchema->primaryKey}), 'Update', );\n"; 修改为: echo "\$this->breadcrumbs=array( '$label'=>array('index'), \$model->{$nameColumn}=>array('view','id'=>\$model->{$this->tableSchema->primaryKey}), '更新', );\n"; 找到: array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')), array('label'=>'View <?php echo $this->modelClass; ?>', 'url'=>array('view', 'id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>)), array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')), 修改为: array('label'=>'列表<?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'新增 <?php echo $this->modelClass; ?>', 'url'=>array('create')), array('label'=>'查看<?php echo $this->modelClass; ?>', 'url'=>array('view', 'id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>)), array('label'=>'管理<?php echo $this->modelClass; ?>', 'url'=>array('admin')), 找到: <h1>Update <?php echo $this->modelClass." <?php echo \$model->{$this->tableSchema->primaryKey}; ?>"; ?></h1> 修改为: <h1>更新 <?php echo $this->modelClass." <?php echo \$model->{$this->tableSchema->primaryKey}; ?>"; ?></h1> 修改view.php 找到: <h1>View <?php echo $this->modelClass." #<?php echo \$model->{$this->tableSchema->primaryKey}; ?>"; ?></h1> 修改为: <h1>查看 <?php echo $this->modelClass." #<?php echo \$model->{$this->tableSchema->primaryKey}; ?>"; ?></h1> 找到: $this->menu=array( array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')), array('label'=>'Update <?php echo $this->modelClass; ?>', 'url'=>array('update', 'id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>)), array('label'=>'Delete <?php echo $this->modelClass; ?>', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>),'confirm'=>'Are you sure you want to delete this item?')), array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('admin')), ); ?> 修改为: $this->menu=array( array('label'=>'列表<?php echo $this->modelClass; ?>', 'url'=>array('index')), array('label'=>'新增<?php echo $this->modelClass; ?>', 'url'=>array('create')), array('label'=>'更新<?php echo $this->modelClass; ?>', 'url'=>array('update', 'id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>)), array('label'=>'删除<?php echo $this->modelClass; ?>', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model-><?php echo $this->tableSchema->primaryKey; ?>),'confirm'=>'Are you sure you want to delete this item?')), array('label'=>'管理<?php echo $this->modelClass; ?>', 'url'=>array('admin')), ); ?> 打开 \protected\views\layouts\column2.php 找到: $this->beginWidget('zii.widgets.CPortlet', array( 'title'=>'Operations', )); 修改为: $this->beginWidget('zii.widgets.CPortlet', array( 'title'=>'操作', ));
文章地址:http://cdc.zhaopin.com/infomation/Industryinfo/contentinfo?articleid=1711747951&Category=all