使 codeigniter 网站多语言的最佳方式.从 lang 数组调用取决于 lang 会话? [英] the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session?

查看:18
本文介绍了使 codeigniter 网站多语言的最佳方式.从 lang 数组调用取决于 lang 会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm researching hours and hours, but I could not find any clear, efficient way to make it :/

我有一个英文的 codeigniter 基础网站,现在我必须添加波兰语.根据访问者的选择,以 2 种语言制作我的网站的最佳方法是什么?

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!!

推荐答案

你看过CodeIgniter's Language图书馆?

语言类提供函数检索语言文件和行用于国际化的文本.

The Language Class provides functions to retrieve language files and lines of text for purposes of internationalization.

在您的 CodeIgniter 系统文件夹中,您将找到一种称为包含集合的语言语言文件.你可以创建你的根据需要拥有自己的语言文件显示错误和其他消息其他语言.

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.

语言文件通常存储在您的系统/语言目录.交替您可以创建一个名为语言的文件夹在您的应用程序文件夹和存储中他们在那里.CodeIgniter 将首先查看在您的应用程序/语言目录中.如果目录不存在或指定的语言不在那里CI 将改为查看您的全局系统/语言文件夹.

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.

就你而言...

  • 你需要在application/language/polish
  • 中创建一个polish_lang.phpenglish_lang.php
  • 然后在该文件中创建您的密钥(例如 $lang['hello'] = "Witaj";
  • 然后将其加载到您的控制器中,例如 $this->lang->load('polish_lang', 'polish');
  • 然后像 $this->lang->line('hello'); 一样获取该行只需将此函数的返回值存储在一个变量中,以便您可以在您的视图中使用它.
  • you need to create a polish_lang.php and english_lang.php inside application/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屋!

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