https://github.com/bkader/ci-gettext-hook

This hook enables the use of php_gettext for CodeIgniter framework

https://github.com/bkader/ci-gettext-hook

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.6%) to scientific vocabulary

Keywords

application codeigniter framework gettext hooks i18n internationalization multilanguage multilingual multilingual-websites php
Last synced: 5 months ago · JSON representation

Repository

This hook enables the use of php_gettext for CodeIgniter framework

Basic Info
Statistics
  • Stars: 7
  • Watchers: 3
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Archived
Topics
application codeigniter framework gettext hooks i18n internationalization multilanguage multilingual multilingual-websites php
Created about 9 years ago · Last pushed about 8 years ago
Metadata Files
Readme

README.md

CI-Gettext-Hook (Demo)

This hook enables the use of php_gettext for CodeIgniter framework.

How to use?

Unlike my former CI-Gettext Library that requires a little bit of configuration and alteration to CodeIgniter core files, this hooks does not really alter a thing and needs a meaningless configuration. Simply drop includes files into your CodeIgniter installation and enable hooks inside your application/config/config.php file

$config['enable_hooks'] = TRUE;

If you have any additional hooks used, open hooks.php file provided and copy lines insde.

This hooks requires at least two (2) languages enabled inside your application/config/gettext.php configuration file.

$config['gettext_languages'] = array('arabic', 'english', 'french');

By default, you will find all languages that I included enabled, simply delete any language that you don't want to use.

How to add lines?

Simply go to the corresponding language (let's say french) and use a PO editor (example: Poedit), add as many needed lines as you want then save the file and generate the .MO file. DONE!

How to print lines?

I provided some functions that help you printing your lines:

line($msgid, $domain[optional], $args[optional])

This function uses gettext() function or dgettext() function if a text domain is provided. It returns the requested line and use arguments if there are any. Examples:

echo line('Hello %s!', NULL, 'Kader'); // Using default domain
echo line('Hello %s!', 'welcome', 'Kader'); // Using welcome(*) domain
// Output: Hello Kader! (english), Salut Kader! (french)
nline($singular, $plural, $number, $domain[optional])

This function uses ngettext() function or dngettext() function if a domain is provided.

echo nline('%s item found', '%s items found', 1);
// Output: 1 item found
echo nline('%s item found', '%s items found', 5, 'welcome');
// output: 5 items found found inside 'welcome' text domain
xline($msgid, $context, $domain[optional])

This function uses pgettext() function or dpgettext() function if a text domain is provided. This handles gettext contexts.

There are some functions aliases that you can use as well - line() function has two (2) aliases: - _t() which is a little short version of it. - _e() which echoes the retrieved string. - nline() function has two (2) aliases: - _n() which is a little short version of it. - _en() which echoes the retrieved string. - xline() function has two (2) aliases: - _x() which is a little short version of it. - _ex() which echoes the retrieved string.

Even if I included these functions, you can still use gettext functions as well. If you don't know if your hosting has gettext enabled or not, prepend T_ to any gettext function you want to use. This way, whether enabled or not, you will get the string. Example:

echo T_gettext($msgid);
echo T_ngettext($singular, $plural, $number);

Get languages details

Other functions are included so you can manage your site languages

currentlanguage(), defaultlanguage(), client_language()

These functions return an array of current, default and client languages details.

languages()

This function returns an array of site enabled languages. If called with no parameters, it returns the full array of languages details. If any parameter is passed, it will only returns the requested key from languages arrays Example:

print_r(languages('name', 'name_en', 'folder'));
Output:
array(
    'english' => array(
        'name'    => 'English'
        'name_en' => 'english',
        'folder'  => 'english'
    ),
    'french' => array(
        'name'    => 'Français'
        'name_en' => 'French',
        'folder'  => 'french'
    )
);

switch_language($code = 'en')

As its name tell, if simply changes site current language.

Using HMVC?

If you are using HMVC structure (wiredesignz), check (HMVC Branch).

Credits and Licenses

All credits go to their respective owners CodeIgniter & Launchpad and a little bit of the rest for Me :D.

Owner

  • Name: Kader Bouyakoub
  • Login: bkader
  • Kind: user
  • Location: Algeria
  • Company: @ianhubnet

Simple dynamic guy, a developer, a gamer, a geek and specialized in anything as long as I can learn it.

GitHub Events

Total
Last Year

Issues and Pull Requests

Last synced: over 1 year ago

All Time
  • Total issues: 2
  • Total pull requests: 1
  • Average time to close issues: about 1 hour
  • Average time to close pull requests: 4 minutes
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 7.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • mehdibo (2)
Pull Request Authors
  • mehdibo (1)
Top Labels
Issue Labels
Pull Request Labels