如何在我的数组codeigniter的“名称”字段中添加翻译?

时间:2019-02-05 07:53:21

标签: php codeigniter codeigniter-2

我在codeigniter代码中包含数组,如何在同一行中为名称字段添加翻译

        $ret = array(
        array(
            'y' => $open_projects,
            'name' => 'Open jobs',
            'color' => '#fc0',
        ),
        array(
            'y' => $completed_projects,
            'name' => 'Completed jobs',
            'color' => '#0c0',
        ),
        array(
            'y' => $active_projects,
            'name' => 'Processing jobs',
            'color' => '#f06',
        ),
        array(
            'y' => $cnl_projects,
            'name' => 'Cancelled jobs',
            'color' => '#0cf',
        ),
    );

我的语言根目录为lang密钥文件夹dashboard_lang.php:

application \ language \ arabic \ dashboard_lang.php

$lang['myprofile_emp_open_jobs_emp']='open project';

此显示代码

<li><i class="zmdi zmdi-label"></i><?php echo $v['name'] ?> : <?php echo $v['y'] ?></li>

1 个答案:

答案 0 :(得分:0)

首先,您加载lang()函数:

$this->load->helper('language');

然后您加载语言文件:

$this->lang->load('dashboard_lang', 'arabic');

然后您可以使用lang()获得翻译:

        array(
            'y' => $open_projects,
            'name' => lang('myprofile_emp_open_jobs_emp'),
            'color' => '#fc0',
        ),

有用的链接:

语言类文档: https://www.codeigniter.com/userguide2/libraries/language.html

语言帮助器文档: https://www.codeigniter.com/userguide2/helpers/language_helper.html