Codeigniter Gettext

License

Codeigniter Gettext is released under GPLv2 license.

Description

This is Codeigniter PHP framework library for dealing with gettext translation and localization.

Instructions

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

  1. Place gettext.php inside application/config.
  2. Place Gettext.php inside application/libraries.
  3. Adjust application/config/gettext.php with your $config['gettext_catalog_codeset'], $config['gettext_text_domain'], $config['gettext_locale_dir'] and $config['gettext_locale'].
  4. Create gettext locales directory according to your $config['gettext_locale_dir'] (application/language/locale by default). Inside that directory create locale_name/LC_MESSAGES path for each of your locales and place your .mo files inside.
  5. Add 'gettext' to Auto-load Config files array or use $this->config->load('gettext') inside your controller.
  6. Add 'gettext' to Auto-load Libraries array or use $this->load->library('gettext') inside your controller.

If you are loading this library inside your controller you can override any of the default configuration directives. For example if you want to override default $config['gettext_locale'] with hr_HR.UTF-8 you could use something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
class Example extends CI_Controller {
   public function __construct() {
        parent::__construct();
 
        $this->load->library(
            'gettext',
            array(
                'gettext_locale' => 'hr_HR.UTF-8'
            )
        );
   }
}
?>

Download

Codeigniter Gettext source code is hosted by GitHub from where you can download current copy of its master branch:

Codeigniter Gettext download

You can also fork or contribute to Codeigniter Gettext by visiting its official GitHub repository page:

Codeigniter Gettext on GitHub
DevGenii

A quality focused Magento specialized web development agency. Get in touch!

3 thoughts on “Codeigniter Gettext

  1. Miro

    Hello,
    Can you please write instructions how it is used in views?
    If i have .tpl file with content:
    Vous ĂȘtes:
    what should i insert to make the sentence translated?

    Reply
  2. Sarwar

    Would you please help me?
    What is the problem
    I have given my debug msg bellow:
    ———————————————————————
    DEBUG - 2016-10-24 03:05:52 --> UTF-8 Support Enabled
    DEBUG - 2016-10-24 03:05:52 --> Global POST, GET and COOKIE data sanitized
    DEBUG - 2016-10-24 03:05:52 --> Config file loaded: G:\WebProjects\Projects\rpos\application\config/gettext.php
    DEBUG - 2016-10-24 03:05:52 --> Try to bind gettext catalog_codeset: UTF-8 - Successful
    DEBUG - 2016-10-24 03:05:52 --> Try to bind gettext text domain (locale dir): G:\WebProjects\Projects\rpos/language/ - Successful
    DEBUG - 2016-10-24 03:05:52 --> Try to set gettext text_domain: default - Successful
    DEBUG - 2016-10-24 03:05:52 --> Try to set gettext locale: bn_BD*** FAILED ***
    DEBUG - 2016-10-24 03:05:52 --> Try to set Environment LANGUAGE: bn_BD - Successful
    DEBUG - 2016-10-24 03:05:52 --> Total execution time: 0.0496

    Screenshot Of my folder structure

    Reply

Leave a Reply

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