{"id":846,"date":"2015-09-25T13:30:58","date_gmt":"2015-09-25T13:30:58","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=846"},"modified":"2015-09-25T13:30:58","modified_gmt":"2015-09-25T13:30:58","slug":"multi-language-implementation-in-codeigniter","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/","title":{"rendered":"Multi-Language implementation in CodeIgniter"},"content":{"rendered":"<p>The Multi-Language feature is necessary for the modern web application. This feature is used for the purpose of internationalization. In this tutorial, we will discuss how to implement the multi-language feature in CodeIgniter framework. Using CodeIgniter&#8217;s Language class, you can easily make your site multi-language. CodeIgniter&#8217;s Language class provides some functions to retrieve language files and lines of text.<\/p>\n<div class=\"img_center\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png\" alt=\"multi-language-implementation-in-codeigniter-by-codexworld\" width=\"715\" height=\"341\" class=\"alignnone size-full wp-image-847\" srcset=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png 715w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld-300x143.png 300w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld-350x167.png 350w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld-320x153.png 320w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld-380x181.png 380w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld-200x95.png 200w, https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld-346x165.png 346w\" sizes=\"auto, (max-width: 715px) 100vw, 715px\" \/><\/div>\n<p>The following guides will drive you to the right way for building a multi-language website with CodeIgniter. If you are new to CodeIgniter, you can read <a href=\"http:\/\/www.codexworld.com\/codeigniter-tutorial-beginners-learn-codeigniter-scratch\/\">CodeIgniter Tutorial for Beginners<\/a> first.<\/p>\n<h2>Site Default Language<\/h2>\n<p>Open the <code>application\/config\/config.php<\/code> file and specify the site&#8217;s default language.<\/p>\n<pre><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'language'<\/span><span style=\"color: #007700\">]&nbsp;&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'english'<\/span><span style=\"color: #007700\">;<\/span><\/pre>\n<h2>Creating Language Files<\/h2>\n<p>Create multiple language files and insert those files into the <code>application\/language\/<\/code> directory with separate sub-directories for each language (for example, french, german, etc.).<\/p>\n<p>The language files must be named with <code>_lang<\/code> suffix. For example, if you want to create a file containing site&#8217;s message translation then the file name might be <code>message_lang.php<\/code>.<\/p>\n<p>Language files structure would look like following.<\/p>\n<ul class=\"folder_structure\">\n<li><b>application\/<\/b>\n<ul>\n<li><b>language\/<\/b>\n<ul>\n<li><b>english\/<\/b>\n<ul>\n<li>message_lang.php<\/li>\n<li>&#8230;&#8230;<\/li>\n<\/ul>\n<\/li>\n<li><b>french\/<\/b>\n<ul>\n<li>message_lang.php<\/li>\n<li>&#8230;&#8230;<\/li>\n<\/ul>\n<\/li>\n<li><b>german\/<\/b>\n<ul>\n<li>message_lang.php<\/li>\n<li>&#8230;&#8230;<\/li>\n<\/ul>\n<\/li>\n<li>&#8230;&#8230;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Within the language file (<code>message_lang.php<\/code>) you would need to assign each line of text to <code>$lang<\/code> array. <\/p>\n<pre><span style=\"color: #0000BB\">$lang<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'language_key'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'The&nbsp;actual&nbsp;message&nbsp;to&nbsp;be&nbsp;shown'<\/span><span style=\"color: #007700\">;<\/span><\/pre>\n<p>Sample language files are given below.<\/p>\n<ul>\n<li>\n        <code>english\/message_lang.php<\/code> file would be look like the following.<\/p>\n<pre><span style=\"color: #000000\"><span style=\"color: #0000BB\">&lt;?php<br \/>$lang<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'welcome_message'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'Welcome&nbsp;to&nbsp;CodexWorld'<\/span><span style=\"color: #007700\">;<\/span><\/span><\/pre>\n<\/li>\n<li>\n        <code>french\/message_lang.php<\/code> file would be look like the following.<\/p>\n<pre><span style=\"color: #000000\"><span style=\"color: #0000BB\">&lt;?php<br \/>$lang<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'welcome_message'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'Bienvenue&nbsp;\u00e0&nbsp;CodexWorld'<\/span><span style=\"color: #007700\">;<\/span><\/span><\/pre>\n<\/li>\n<li>\n        <code>german\/message_lang.php<\/code> file would be look like the following.<\/p>\n<pre><span style=\"color: #000000\"><span style=\"color: #0000BB\">&lt;?php<br \/>$lang<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'welcome_message'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #DD0000\">'Willkommen&nbsp;in&nbsp;CodexWorld'<\/span><span style=\"color: #007700\">;<\/span><\/span><\/pre>\n<\/li>\n<\/ul>\n<h2>Loading Language Files<\/h2>\n<p>In order to fetch a line from a particular language file, you need to load the language file first. There are two options for loading a language file.<\/p>\n<p><b>In Controller:<\/b><br \/>\nInto the controller&#8217;s <code>__construct()<\/code> function write the following code.<\/p>\n<pre><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">lang<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">load<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'message'<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #DD0000\">'english'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<p>If you choose this option, you need to load language file in all controller of your application.<\/p>\n<p><b>Using Hooks:<\/b><br \/>\nFor using the hooks option you need to enable the hooks feature in <code>application\/config\/config.php<\/code> file.<\/p>\n<pre><span style=\"color: #0000BB\">$config<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'enable_hooks'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;<\/span><span style=\"color: #0000BB\">TRUE<\/span><span style=\"color: #007700\">;<\/span><\/pre>\n<p>Open <code>application\/config\/hooks.php<\/code> file and define a hook.<\/p>\n<pre><span style=\"color: #0000BB\">$hook<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'post_controller_constructor'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'class'&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'LanguageLoader'<\/span><span style=\"color: #007700\">,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'function'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'initialize'<\/span><span style=\"color: #007700\">,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'filename'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'LanguageLoader.php'<\/span><span style=\"color: #007700\">,<br \/>&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #DD0000\">'filepath'&nbsp;<\/span><span style=\"color: #007700\">=&gt;&nbsp;<\/span><span style=\"color: #DD0000\">'hooks'<br \/><\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<p>Create LanguageLoader class in <code>LanguageLoader.php<\/code> file inside the <code>application\/hooks\/<\/code> directory. <code>LanguageLoader.php<\/code> file contain the following code.<\/p>\n<pre><span style=\"color: #000000\"><span style=\"color: #0000BB\">&lt;?php<br \/><\/span><span style=\"color: #007700\">class&nbsp;<\/span><span style=\"color: #0000BB\">LanguageLoader<br \/><\/span><span style=\"color: #007700\">{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">initialize<\/span><span style=\"color: #007700\">()&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci&nbsp;<\/span><span style=\"color: #007700\">=&amp;&nbsp;<\/span><span style=\"color: #0000BB\">get_instance<\/span><span style=\"color: #007700\">();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">load<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">helper<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'language'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">lang<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">load<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'message'<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #DD0000\">'english'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>}<\/span><\/span><\/pre>\n<h2>Fetching line of text<\/h2>\n<p>After loading the language file you can fetch the line text using the following code.<\/p>\n<pre><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">lang<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">line<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'welcome_message'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<h2>Switch Different Languages<\/h2>\n<p>Now it&#8217;s time to switch different languages and make your site multilingual. We will use the session to store user&#8217;s requested language and load the respective language.<\/p>\n<p>Before starting to implement multilingual features, open the <code>application\/config\/autoload.php<\/code> file and load <b>SESSION<\/b> library and <b>URL<\/b> helper.<\/p>\n<pre><span style=\"color: #0000BB\">$autoload<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'libraries'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'session'<\/span><span style=\"color: #007700\">);<br \/><\/span><span style=\"color: #0000BB\">$autoload<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'helper'<\/span><span style=\"color: #007700\">]&nbsp;=&nbsp;array(<\/span><span style=\"color: #DD0000\">'url'<\/span><span style=\"color: #007700\">);<\/span><\/pre>\n<p>We will create LanguageSwitcher controller for handing the language switch. <code>application\/controllers\/LanguageSwitcher.php<\/code> file contain the following code.<\/p>\n<pre><span style=\"color: #000000\"><span style=\"color: #0000BB\">&lt;?php&nbsp;<\/span><span style=\"color: #007700\">if&nbsp;(&nbsp;!&nbsp;<\/span><span style=\"color: #0000BB\">defined<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'BASEPATH'<\/span><span style=\"color: #007700\">))&nbsp;exit(<\/span><span style=\"color: #DD0000\">'No&nbsp;direct&nbsp;script&nbsp;access&nbsp;allowed'<\/span><span style=\"color: #007700\">);<br \/>class&nbsp;<\/span><span style=\"color: #0000BB\">LanguageSwitcher&nbsp;<\/span><span style=\"color: #007700\">extends&nbsp;<\/span><span style=\"color: #0000BB\">CI_Controller<br \/><\/span><span style=\"color: #007700\">{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">__construct<\/span><span style=\"color: #007700\">()&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">parent<\/span><span style=\"color: #007700\">::<\/span><span style=\"color: #0000BB\">__construct<\/span><span style=\"color: #007700\">();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">switchLang<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$language&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #DD0000\">\"\"<\/span><span style=\"color: #007700\">)&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$language&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;(<\/span><span style=\"color: #0000BB\">$language&nbsp;<\/span><span style=\"color: #007700\">!=&nbsp;<\/span><span style=\"color: #DD0000\">\"\"<\/span><span style=\"color: #007700\">)&nbsp;?&nbsp;<\/span><span style=\"color: #0000BB\">$language&nbsp;<\/span><span style=\"color: #007700\">:&nbsp;<\/span><span style=\"color: #DD0000\">\"english\"<\/span><span style=\"color: #007700\">;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$this<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">session<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">set_userdata<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'site_lang'<\/span><span style=\"color: #007700\">,&nbsp;<\/span><span style=\"color: #0000BB\">$language<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">redirect<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #0000BB\">$_SERVER<\/span><span style=\"color: #007700\">[<\/span><span style=\"color: #DD0000\">'HTTP_REFERER'<\/span><span style=\"color: #007700\">]);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>}<\/span><\/span><\/pre>\n<p>Open the <code>application\/hooks\/LanguageLoader.php<\/code> file and replace file&#8217;s code with the following code.<\/p>\n<pre><span style=\"color: #000000\"><span style=\"color: #0000BB\">&lt;?php<br \/><\/span><span style=\"color: #007700\">class&nbsp;<\/span><span style=\"color: #0000BB\">LanguageLoader<br \/><\/span><span style=\"color: #007700\">{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;<\/span><span style=\"color: #0000BB\">initialize<\/span><span style=\"color: #007700\">()&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci&nbsp;<\/span><span style=\"color: #007700\">=&amp;&nbsp;<\/span><span style=\"color: #0000BB\">get_instance<\/span><span style=\"color: #007700\">();<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">load<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">helper<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'language'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$siteLang&nbsp;<\/span><span style=\"color: #007700\">=&nbsp;<\/span><span style=\"color: #0000BB\">$ci<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">session<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">userdata<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'site_lang'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(<\/span><span style=\"color: #0000BB\">$siteLang<\/span><span style=\"color: #007700\">)&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">lang<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">load<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'message'<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #0000BB\">$siteLang<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;{<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000BB\">$ci<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">lang<\/span><span style=\"color: #007700\">-&gt;<\/span><span style=\"color: #0000BB\">load<\/span><span style=\"color: #007700\">(<\/span><span style=\"color: #DD0000\">'message'<\/span><span style=\"color: #007700\">,<\/span><span style=\"color: #DD0000\">'english'<\/span><span style=\"color: #007700\">);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br \/>}<\/span><\/span><\/pre>\n<p>Display the languages dropdown into view. Once the language option is changed, the <code>switchLang()<\/code> function of LanguageSwitcher controller would be called. <code>switchLang()<\/code> function set the site language into session based on the requested language and redirected to the view page. The sample languages dropdown and multi-language welcome message code is given below.<\/p>\n<pre>&lt;<span style=\"color:#bf4f24\">select<\/span> <span style=\"color:#bf4f24\">onchange<\/span>=<span style=\"color:#0b6125\">\"javascript:window.location.href='<span style=\"background:rgba(111,139,186,0.15);color:#080808\">&lt;?php <span style=\"color:#693a17\">echo<\/span> base_url(); ?><\/span>LanguageSwitcher\/switchLang\/'+this.value;\"<\/span>>\r\n    &lt;<span style=\"color:#bf4f24\">option<\/span> <span style=\"color:#bf4f24\">value<\/span>=<span style=\"color:#0b6125\">\"english\"<\/span> <span style=\"background:rgba(111,139,186,0.15)\">&lt;?php<span style=\"color:#794938\"> if<\/span>(<span style=\"color:#234a97\">$this<\/span><span style=\"color:#794938\">-><\/span>session<span style=\"color:#794938\">-><\/span>userdata(<span style=\"color:#0b6125\">'site_lang'<\/span>) <span style=\"color:#794938\">==<\/span> <span style=\"color:#0b6125\">'english'<\/span>) <span style=\"color:#693a17\">echo<\/span> <span style=\"color:#0b6125\">'selected=\"selected\"'<\/span>; ?><\/span>>English&lt;\/<span style=\"color:#bf4f24\">option<\/span>>\r\n    &lt;<span style=\"color:#bf4f24\">option<\/span> <span style=\"color:#bf4f24\">value<\/span>=<span style=\"color:#0b6125\">\"french\"<\/span> <span style=\"background:rgba(111,139,186,0.15)\">&lt;?php<span style=\"color:#794938\"> if<\/span>(<span style=\"color:#234a97\">$this<\/span><span style=\"color:#794938\">-><\/span>session<span style=\"color:#794938\">-><\/span>userdata(<span style=\"color:#0b6125\">'site_lang'<\/span>) <span style=\"color:#794938\">==<\/span> <span style=\"color:#0b6125\">'french'<\/span>) <span style=\"color:#693a17\">echo<\/span> <span style=\"color:#0b6125\">'selected=\"selected\"'<\/span>; ?><\/span>>French&lt;\/<span style=\"color:#bf4f24\">option<\/span>>\r\n    &lt;<span style=\"color:#bf4f24\">option<\/span> <span style=\"color:#bf4f24\">value<\/span>=<span style=\"color:#0b6125\">\"german\"<\/span> <span style=\"background:rgba(111,139,186,0.15)\">&lt;?php<span style=\"color:#794938\"> if<\/span>(<span style=\"color:#234a97\">$this<\/span><span style=\"color:#794938\">-><\/span>session<span style=\"color:#794938\">-><\/span>userdata(<span style=\"color:#0b6125\">'site_lang'<\/span>) <span style=\"color:#794938\">==<\/span> <span style=\"color:#0b6125\">'german'<\/span>) <span style=\"color:#693a17\">echo<\/span> <span style=\"color:#0b6125\">'selected=\"selected\"'<\/span>; ?><\/span>>German&lt;\/<span style=\"color:#bf4f24\">option<\/span>>   \r\n&lt;\/<span style=\"color:#bf4f24\">select<\/span>>\r\n&lt;<span style=\"color:#bf4f24\">p<\/span>><span style=\"background:rgba(111,139,186,0.15)\">&lt;?php <span style=\"color:#693a17\">echo<\/span> <span style=\"color:#234a97\">$this<\/span><span style=\"color:#794938\">-><\/span>lang<span style=\"color:#794938\">-><\/span>line(<span style=\"color:#0b6125\">'welcome_message'<\/span>); ?><\/span>&lt;\/<span style=\"color:#bf4f24\">p<\/span>>\r\n<\/pre>\n<p>Also, you can notice that we are used the language switcher URL without <code>index.php<\/code>. So, you should need to create a <code>.htaccess<\/code> file in root directory and this file will contain the following code.<\/p>\n<pre>RewriteEngine on\r\nRewriteCond $1 !^(index\\.php)\r\nRewriteRule ^(.*)$ \/codeigniter\/index.php\/$1 [L]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Multi-Language feature is necessary for the modern web application. This feature is used for the purpose of internationalization. In this tutorial, we will discuss how to implement the multi-language feature in CodeIgniter framework. Using <\/p>\n","protected":false},"author":1,"featured_media":847,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8],"tags":[55,64,63],"class_list":["post-846","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-codeigniter","tag-codeigniter","tag-internationalization","tag-multi-language","cat-8-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Multi-Language implementation in CodeIgniter - CodexWorld<\/title>\n<meta name=\"description\" content=\"Best way to make CodeIgniter framework multi-language using language class. Step by step tutorial on multi-language support of CodeIgniter website for purposes of internationalization.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Multi-Language implementation in CodeIgniter - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"Best way to make CodeIgniter framework multi-language using language class. Step by step tutorial on multi-language support of CodeIgniter website for purposes of internationalization.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-25T13:30:58+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"715\" \/>\n\t<meta property=\"og:image:height\" content=\"341\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Multi-Language implementation in CodeIgniter\",\"datePublished\":\"2015-09-25T13:30:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/\"},\"wordCount\":495,\"commentCount\":21,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/09\\\/multi-language-implementation-in-codeigniter-by-codexworld.png\",\"keywords\":[\"CodeIgniter\",\"Internationalization\",\"Multi-Language\"],\"articleSection\":[\"CodeIgniter\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/\",\"name\":\"Multi-Language implementation in CodeIgniter - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/09\\\/multi-language-implementation-in-codeigniter-by-codexworld.png\",\"datePublished\":\"2015-09-25T13:30:58+00:00\",\"description\":\"Best way to make CodeIgniter framework multi-language using language class. Step by step tutorial on multi-language support of CodeIgniter website for purposes of internationalization.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/09\\\/multi-language-implementation-in-codeigniter-by-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2015\\\/09\\\/multi-language-implementation-in-codeigniter-by-codexworld.png\",\"width\":715,\"height\":341,\"caption\":\"multi-language-implementation-in-codeigniter-by-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/multi-language-implementation-in-codeigniter\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Multi-Language implementation in CodeIgniter\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Multi-Language implementation in CodeIgniter - CodexWorld","description":"Best way to make CodeIgniter framework multi-language using language class. Step by step tutorial on multi-language support of CodeIgniter website for purposes of internationalization.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/","og_locale":"en_US","og_type":"article","og_title":"Multi-Language implementation in CodeIgniter - CodexWorld","og_description":"Best way to make CodeIgniter framework multi-language using language class. Step by step tutorial on multi-language support of CodeIgniter website for purposes of internationalization.","og_url":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2015-09-25T13:30:58+00:00","og_image":[{"width":715,"height":341,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Multi-Language implementation in CodeIgniter","datePublished":"2015-09-25T13:30:58+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/"},"wordCount":495,"commentCount":21,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png","keywords":["CodeIgniter","Internationalization","Multi-Language"],"articleSection":["CodeIgniter"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/","url":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/","name":"Multi-Language implementation in CodeIgniter - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png","datePublished":"2015-09-25T13:30:58+00:00","description":"Best way to make CodeIgniter framework multi-language using language class. Step by step tutorial on multi-language support of CodeIgniter website for purposes of internationalization.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png","width":715,"height":341,"caption":"multi-language-implementation-in-codeigniter-by-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/multi-language-implementation-in-codeigniter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Multi-Language implementation in CodeIgniter"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2015\/09\/multi-language-implementation-in-codeigniter-by-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-dE","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=846"}],"version-history":[{"count":1,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/846\/revisions"}],"predecessor-version":[{"id":848,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/846\/revisions\/848"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/847"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}