the best way to make codeigniter website multi-language. calling from lang arrays depends on lang session?

后端 未结 11 1066
情深已故
情深已故 2020-11-27 10:34

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

11条回答
  •  执笔经年
    2020-11-27 11:23

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

提交回复
热议问题