PHP Classes


Recommend this page to a friend!
  Classes of Joel Gaujard  >  CodeIgniter GetText  >  >  Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: CodeIgniter GetText
Load locale texts for CodeIgniter applications
Author: By
Last change: Update README from
Date: 4 years ago
Size: 5,298 bytes


Class file image Download

CodeIgniter Gettext

Latest Stable Version Build Status Code Coverage Scrutinizer Code Quality License

This is CodeIgniter PHP framework package for dealing with Gettext.

This package is a fork from Marko Martivovi? library.

Please use Composer to install it and include it as a package in your CodeIgniter application.


Please note that following steps assume that you have correctly installed gettext and configured Codeigniter on your server.

  1. Use composer to install this package

composer require joel-depiltech/codeigniter-gettext

  1. Add this package to auto-load packages array (application/config/autoload.php)

$autoload['packages'] = array(FCPATH . 'vendor/joel-depiltech/codeigniter-gettext/src');

or include it with Loader library

$this->load->add_package_path(FCPATH . 'vendor/joel-depiltech/codeigniter-gettext/src');

  1. Add default configuration file to auto-load config array (application/config/autoload.php)

$autoload['config'] = array('gettext');

or include it with Loader library


  1. Add the library to auto-load library array (application/config/autoload.php)

$autoload['library'] = array('gettext');

or include it with Loader library


  1. Add the helper to auto-load library array (application/config/autoload.php)

$autoload['helper'] = array('gettext');

or include it with Loader library


  1. Create gettext locales directory according to your `gettext_locale_dir` (application/language/locales by default). Inside that directory create locale_name/LC_MESSAGES path for each of your locales and place your .mo files inside.

This is an example how to load Library overwriting default configuration:

class Your_controller extends CI_Controller
   public function __construct()

                'gettext_text_domain' => 'my-project',
                'gettext_locale' => 'fr_FR.UTF-8',
                'gettext_locale_dir' => 'language/gettext'


If you have some issues with this package or is not working properly, please check your CodeIgniter log files. 'INFO' message is just for giving informations about the process, pay attention to 'ERROR' message which help you to resolve your issues.

Submit a new issue if you can't solve your problem and help us to enhance this package.

Additional Usage

If you want to use URIs in i18n Style, you can easily add a Post-Controller-Hook like the sample below. Place the following code inside your application/config/hooks.php.

$hook['post_controller_constructor'] = function()
     * Localisation Strings Windows:
     * @link
     * @link
     * Localisation Strings Unix:
     * Verify that the selected locales are available by running `locale -a`. 
     * in addition take a look at
     * @link

    $locale = Array(
        "de" => Array(
        "en" => Array(

    $CI = &get_instance();
    $lang = $this->uri->segment(1);
        $getTextConfig = Array( 
            'gettext_catalog_codeset' => 'UTF8',
            'gettext_text_domain' => 'example',
            'gettext_locale_dir' => './language/locale/';
            'gettext_locale' => $locale[$lang]
        $CI->load->library('gettext', $getTextConfig);
    else {

For more information send a message to info at phpclasses dot org.