最好的方式使codeigniter网站多语言。从lang数组调用取决于lang会话? [英] the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session?
问题描述
我正在研究时间和小时,但我找不到任何清晰,有效的方式:/
我有一个codeigniter基本网站的英语和我现在要添加一个波兰语。根据访问者选择,我的网站使用2种语言的最佳方式是什么?
有任何方法可以为每种语言创建数组文件,会话从lang选择?我不想使用数据库。
欣赏有助!我已经用尽了截止日期:/ thanks !!
您见过 CodeIgniter的语言库?
语言类提供函数
来检索语言文件和行
的文本用于国际化。
在您的CodeIgniter系统文件夹中, ll
找到一个包含语言文件集合
的语言。您可以根据需要创建
自己的语言文件,以便
在
其他语言中显示错误和其他消息。
语言文件通常存储在
的系统/语言目录中。或者
,您可以在应用程序文件夹中创建一个名为language
的文件夹,并在那里存储
。 CodeIgniter将首先在您的应用程序/语言目录中查找
。
如果目录不存在或者
指定的语言不在其中,那么
CI将改为查找您的全局
系统/语言文件夹。
在您的情况下...
- 您需要创建
polish_lang.php
和english_lang.php
里面application / language / polish
- 然后在该文件中创建您的密钥(例如
$ lang ['hello'] =Witaj;
- 然后将它加载到您的控制器中
$ this-> lang-> load('polish_lang','polish');
- 然后获取
$ this-> lang-> line('hello');
只需存储此函数的返回值
对您需要的英语语言和所有其他语言重复上述步骤。 p>
I'm researching hours and hours, but I could not find any clear, efficient way to make it :/
I have a codeigniter base website in English and I have to add a Polish language now. What is the best way to make my site in 2 language depending visitor selection?
is there any way to create array files for each language and call them in view files depends on Session from lang selection? I don't wanna use database.
Appreciate helps! I'm running out of deadline :/ thanks!!
Have you seen CodeIgniter's Language library?
The Language Class provides functions to retrieve language files and lines of text for purposes of internationalization.
In your CodeIgniter system folder you'll find one called language containing sets of language files. You can create your own language files as needed in order to display error and other messages in other languages.
Language files are typically stored in your system/language directory. Alternately you can create a folder called language inside your application folder and store them there. CodeIgniter will look first in your application/language directory. If the directory does not exist or the specified language is not located there CI will instead look in your global system/language folder.
In your case...
- you need to create a
polish_lang.php
andenglish_lang.php
insideapplication/language/polish
- then create your keys inside that file (e.g.
$lang['hello'] = "Witaj";
- then load it in your controller like
$this->lang->load('polish_lang', 'polish');
- then fetch the line like
$this->lang->line('hello');
Just store the return value of this function in a variable so you can use it in your view.
Repeat the steps for the english language and all other languages you need.
这篇关于最好的方式使codeigniter网站多语言。从lang数组调用取决于lang会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!