PHP Classes

CodeIgniter GetText: Load locale texts for CodeIgniter applications

Recommend this page to a friend!
  Info   View files Documentation   View files View files (32)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 69 This week: 1All time: 10,266 This week: 560Up
Version License PHP version Categories
codeigniter-gettext 1.0.0Custom (specified...5Localization, PHP 5
Description 

Authors

Joël Gaujard
Joël Gaujard


Contributor

This package can load locale texts for CodeIgniter applications.

It can load the translation strings for given locale context defined configuration variables.

Enviroment variables are set to make gettext consider the configured locale language.

Picture of Joel Gaujard
Name: Joel Gaujard <contact>
Classes: 1 package by
Country: France France
Age: ???
All time rank: 4460112 in France France
Week rank: 411 Up15 in France France Up

Documentation

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.

Instructions

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

$this->load->config('gettext');

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

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

or include it with Loader library

$this->load->library('gettext');

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

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

or include it with Loader library

$this->load->helper('gettext');

  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:

<?php
class Your_controller extends CI_Controller
{
   public function __construct()
   {
        parent::__construct();

        $this->load->library(
            'gettext',
            array(
                'gettext_text_domain' => 'my-project',
                'gettext_locale' => 'fr_FR.UTF-8',
                'gettext_locale_dir' => 'language/gettext'
            )
        );
   }
}
?>

Issues

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 https://msdn.microsoft.com/en-us/library/cdax410z(v=vs.90).aspx
     * @link https://msdn.microsoft.com/en-us/library/39cwe7zf(v=vs.90).aspx
     * Localisation Strings Unix:
     * Verify that the selected locales are available by running `locale -a`. 
     * 
     * in addition take a look at
     * @link http://avenir.ro/create-cms-using-codeigniter-3/create-multilanguage-site-codeigniter/
     /

    $locale = Array(
        "de" => Array(
            'de_DE.UTF-8',
            'de_DE@euro',
            'de_DE',
            'german',
            'ger',
            'deu',
            'de'
        ),
        "en" => Array(
            "en_GB.UTF-8",
            "en_GB@euro",
            "en_GB",
            "english",
            "eng",
            "gbr",
            "en"
        )
    );

    $CI = &get_instance();
    $lang = $this->uri->segment(1);
    if(isset($locale[$lang])){
        $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 {
        $CI->load->library('gettext');
    }

};

  Files folder image Files  
File Role Description
Files folder imagesrc (2 files, 3 directories)
Files folder imagetests (7 files, 2 directories)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file build.xml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.html Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageconfig (2 files)
Files folder imagehelpers (2 files)
Files folder imagelibraries (2 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  src  /  config  
File Role Description
  Accessible without login Plain text file gettext.php Aux. Auxiliary script
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file gettext_helper.php Aux. Auxiliary script
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  src  /  libraries  
File Role Description
  Plain text file Gettext.php Class Class source
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  tests  
File Role Description
Files folder imagelanguage (1 file, 1 directory)
Files folder imagetranslations (1 file, 1 directory)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Plain text file ConfigTest.php Class Class source
  Accessible without login Plain text file gettext_test.inc.php Aux. Auxiliary script
  Plain text file HelperTest.php Class Class source
  Accessible without login HTML file index.html Doc. Documentation
  Plain text file LibraryTest.php Class Class source
  Plain text file TranslationTest.php Class Class source

  Files folder image Files  /  tests  /  language  
File Role Description
Files folder imagelocales (1 file, 1 directory)
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  tests  /  language  /  locales  
File Role Description
Files folder imageen_US.UTF-8 (1 file, 1 directory)
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  tests  /  language  /  locales  /  en_US.UTF-8  
File Role Description
Files folder imageLC_MESSAGES (2 files)
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  tests  /  language  /  locales  /  en_US.UTF-8  /  LC_MESSAGES  
File Role Description
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file override-domain.po Data Auxiliary data

  Files folder image Files  /  tests  /  translations  
File Role Description
Files folder imageen_GB.UTF-8 (1 file, 1 directory)
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  tests  /  translations  /  en_GB.UTF-8  
File Role Description
Files folder imageLC_MESSAGES (2 files)
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files  /  tests  /  translations  /  en_GB.UTF-8  /  LC_MESSAGES  
File Role Description
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login Plain text file my-domain.po Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:69
This week:1
All time:10,266
This week:560Up