简体   繁体   English

将完整的 lang 文件发送到视图 [CodeIgniter]

[英]Sending a complete lang file to a view [CodeIgniter]

Is there any way to send a complete lang file to a view, so that I can access the $lang -variable inside the view.有什么方法可以将完整的 lang 文件发送到视图,以便我可以访问视图内的$lang变量。

At the moment the only thing I can find is sending seperate lines to the view (using $this->lang->line('lang_key') ) which sounds very antagonizing if I have a few dozen lines I want to print in the view.目前我唯一能找到的是将单独的行发送到视图(使用$this->lang->line('lang_key') )如果我有几十行我想在视图中打印,这听起来非常$this->lang->line('lang_key') .

My question is if there's a way to select a specific language file and make the whole $lang array in that language file accessible from a view.我的问题是是否有办法选择特定语言文件并使该语言文件中的整个$lang数组可从视图访问。

在您的视图中尝试此操作以查看您的所有 lang 数组。

print_r($this->lang);

You should put :你应该把:

$this->load->lang('your lang file name');

in the constructor of the controller from which you load your view.在您加载视图的控制器的构造函数中。

and use it in the view as :并在视图中使用它:

<?php lang->line('key');?>

Load the translation file in the constructor:在构造函数中加载翻译文件:

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

An then on the view, you can echo each line by:然后在视图上,您​​可以通过以下方式回显每一行:

<?php echo $this->lang->line('prod_not_found'); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM