arrays - 使 Codeigniter 网站多语言化的最佳方法。从 lang 数组调用取决于 lang session ?

标签 arrays session codeigniter multilingual

我正在研究时间和时间,但我找不到任何清晰、有效的方法来实现它:/

我有一个英文版的 codeigniter 基础网站,现在我必须添加波兰语。根据访问者的选择将我的网站设置为两种语言的最佳方法是什么?

有没有办法为每种语言创建数组文件,并根据语言选择中的 session 在 View 文件中调用它们?我不想使用数据库。

感谢帮助!我的截止日期快到了:/谢谢!!

最佳答案

你见过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.

就你而言...

  • 您需要创建一个 polish_lang.phpenglish_lang.php里面application/language/polish
  • 然后在该文件中创建 key (例如 $lang['hello'] = "Witaj";
  • 然后将其加载到您的 Controller 中,例如 $this->lang->load('polish_lang', 'polish');
  • 然后获取像 $this->lang->line('hello'); 这样的行只需将此函数的返回值存储在变量中,以便您可以在 View 中使用它。

对英语和您需要的所有其他语言重复这些步骤。

关于arrays - 使 Codeigniter 网站多语言化的最佳方法。从 lang 数组调用取决于 lang session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1328420/

相关文章:

arrays - 将两个循环合二为一

arrays - Scala 二维数组按主列和辅助列排序

ruby - 使用 Rack::Session::Datamapper

php - 在 PHP 中维护 MySQL select 的正斜杠

java - 比较字符串数组

session - 使用 ServiceStack 的多个 ICacheClient 实现

node.js - Nodejs Express session 错误

php - MYSQL如何发出多个请求

PHP:Codeigniter 在两个日期内获得即将到来的生日

arrays - 使用 lambda 捕获的 constexpr 值作为数组维度