Multi-language support or internationalization is an important feature of web applications. Most of PHP frameworks comes with multi-language support to add functionality using existing class and functions. CodeIgniter also comes with Language class to support multi-language. The Language class provides functions to retrieve language files and lines of text for purposes of internationalization. So in this tutorial you will learn how to implement multi-language support in your CodeIgniter project.

Step 1: Site Default Language
Open the application/config/config.php file and specify the site’s default language.

Step 2: Creating Language Files
Create multiple language files and insert those files into the application/language/ directory with separate sub-directories for each language (for example, english, french, german, hindi, etc.).
Language files structure like
1- Eglish

  • application/language/english/header_lang.php
  • application/language/english/content_lang.php
  • application/language/english/footer_lang.php

1- French

  • application/language/french/header_lang.php
  • application/language/french/content_lang.php
  • application/language/french/footer_lang.php

1- German

  • application/language/german/header_lang.php
  • application/language/german/content_lang.php
  • application/language/german/footer_lang.php

1- Hindi

  • application/language/hindi/header_lang.php
  • application/language/hindi/content_lang.php
  • application/language/hindi/footer_lang.php

Step 3: enable hooks
For using the hooks option you need to enable the hooks feature in application/config/config.php file.

Step 4: Create Hooks file
create hook file named “MultiLanguageLoader.php” inside “application/hooks folder.

Step 5: Open application/config/hooks.php file and define a hook.

Step 6: Before starting to implement multilingual features, open the application/config/autoload.php

Step 7: Create a controller file for handing the language switch
Create a controller file named “MultiLanguageSwitcher.php” inside “application/controllers” folder.

Step 8: Create a controller file
Create a controller file named Home.php” inside “application/controllers” folder.

Step 9: Add dropdown your template file

Step 10: Create a view
Create a view file named “index.php” inside “application/views/ folder.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">