Internationalization on CodeIgniter config files?

不问归期 提交于 2019-12-02 21:47:51

问题


I'm trying to do something like:

$config['first_link'] = 'lang:pagination_first_link';
$config['prev_link'] = 'lang:pagination_prev_link';
$config['next_link'] = 'lang:pagination_next_link';
$config['last_link'] = 'lang:pagination_last_link';

Is there a simple way to do this ?

This configuration is specific to the Pagination config file, but the question is generic.


回答1:


You have language folders for that. If you take a look at system/language/english, you can see how CodeIgniter deals with internationalization.

For your example, you would create a file in system/language/english, called pagination.php, for example.

$lang['first_link'] = 'First Link';
$lang['prev_link']  = 'Previous Link';
etc...

If you wanted to create more languages, you could just create folders for them under system/language. Then you could just load the language file before setting the configurations, and then it's as easy as writing this:

$config['first_link'] = $this->lang->line('first_link');

If you have those pagination configurations inside a config file, not on your controller, I can't think of an easy to do it, without a bit of a hack. You would have this:

$CI =& get_instance();
$CI->lang->load('pagination', 'english');

$config['first_link'] = $CI->lang->line('first_link');
$config['prev_link']  = $CI->lang->line('prev_link');

I hope I was able to help.




回答2:


My answer in the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session? might help.



来源:https://stackoverflow.com/questions/1291318/internationalization-on-codeigniter-config-files

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