Codeigniter中的多语言 [英] Multilanguage in Codeigniter

查看:89
本文介绍了Codeigniter中的多语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用框架Codeigniter。
我写了一个图书馆(类)用四种语言的数组单词翻译。

I use a framework Codeigniter. I have written a library(class) translate with a array words on four language.

class Translate
{

public function __construct(){

        $this->CI =& get_instance();
        $this->CI->load->library("countrylang");
        $this->settings = $this->CI->countrylang->GetSettings();
        $this->words = array(

        'news feed' => array(20 => 'Leunta', 153 => 'Laita', 3 => 'News feed', 109 => 'Leuita'));

}
}

$this->data['lang'] = $this->load->library('translate');

在我可以访问视图 like as:

After I can get access to words from view like as:

<?=$lang['news feed']?>

问题是在helpers文件中有一些单词必须用选定的语言翻译: p>

Problem is that in helpers files there are a words that also must be translate on selected language:

function Calendar($type = 'articles'){
      $number =  ($daysRepeat[$i] > 0) ? ' data-original-title = "'.count($daysRepeat[$i]).' записей"' : '';
}

因此在helpers Codeigniter中有一个词必须替换所选择的语言,

So in helpers Codeigniter there are a words that must be replace on selected language and return to view.

我如何做?

推荐答案

如果你想从辅助文件中访问模型,库等,只需创建一个对全局CI对象的引用,就像你在其他地方一样:

If you'd like to access models, libraries etc from a helper file, just create a reference to the global CI object like you would anywhere else:

function someHelperFunction() 
{
  $CI =& get_instance();
  $CI->load->library('somelibrary');
  $CI->somelibrary->doSomething();

  //  ....
}

这篇关于Codeigniter中的多语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆