Load different language from class CI_Controller in codeigniter

坚强是说给别人听的谎言 提交于 2019-12-22 09:52:39

问题


I am developing multilingual website. I wrote following code in CI_Controller class file so that I don't have to load language to each controller file.

$this->lang->load('english');

Problem is when I have to change other language for example: let's say spanish.

$this->lang->load('spanish');

How to I load between these two language when I choose Language > English / Spanish from menu option?


回答1:


Checking and Loading

place this code in controller constructor

 $this->load->library('session');
 $lang= $this->session->userdata('language');

if($lang != ''){
    switch($lang){
        case    'en'    :   
            $this->lang->load('english', 'english');
            break;
        case    'sp'    :   
            $this->lang->load('spanish', 'spanish');
            break;
    }
}

Setting lang

place this code where you setting the lang

$this->session->set_userdata('language', '<set english or spanish>')



回答2:


if you have any application installed built in codeigniter or u are making 1 and u wanna add some language pack just follow these steps:
1: Add language files in folder application/language/arabic (i add arabic lang in stock manager advance built in codeigniter)
2: go to the file named setting.php in application/modules/settings/views/setting.php here u find the array

<?php /*

 $lang = array (
  'english' => 'English',

  'arabic' => 'Arabic',  // i add this here

  'spanish' => 'Español'

now save and run the application its worked fine



来源:https://stackoverflow.com/questions/15430734/load-different-language-from-class-ci-controller-in-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!