michalsn/codeigniter-gettext

Gettext support for the CodeIgniter 4 framework

v1.0.0 2023-07-23 10:32 UTC

README

This library gives users the ability to use gettext more friendly way.

PHPUnit PHPStan Deptrac

PHP CodeIgniter

Installation

Composer

composer require michalsn/codeigniter-gettext

Manually

In the example below we will assume, that files from this project will be located in app/ThirdParty/gettext directory.

Download this project and then enable it by editing the app/Config/Autoload.php file and adding the Michalsn\CodeIgniterGettext namespace to the $psr4 array, like in the below example:

<?php

namespace Config;

use CodeIgniter\Config\AutoloadConfig;

class Autoload extends AutoloadConfig
{
    // ...
    public $psr4 = [
        APP_NAMESPACE => APPPATH, // For custom app namespace
        'Config'      => APPPATH . 'Config',
        'Michalsn\CodeIgniterGettext' => APPPATH . 'ThirdParty/gettext/src',
    ];

    // ...

Example

service('gettext')->setLocale('pl');

echo _('Hello');