kasseler/gettext

This package is abandoned and no longer maintained. No replacement package was suggested.

Gettext library

1.0.1 2015-03-25 19:31 UTC

This package is not auto-updated.

Last update: 2020-01-24 15:46:41 UTC


README

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Latest Unstable Version License

Gettext *.mo files reader for PHP. Original package https://launchpad.net/php-gettext

Requirements

  • PHP >= 5.3

Installation

$ composer require kasseler/config

Introduction

How many times did you look for a good translation tool, and found out that gettext is best for the job? Many times. How many times did you try to use gettext in PHP, but failed miserably, because either your hosting provider didn't support it, or the server didn't have adequate locale? Many times. Well, this is a solution to your needs. It allows using gettext tools for managing translations, yet it doesn't require gettext library at all. It parses generated MO files directly, and thus might be a bit slower than the (maybe provided) gettext library. PHP-gettext is a simple reader for GNU gettext MO files. Those are binary containers for translations, produced by GNU msgfmt.

Usage

To force the use of the class, you must install define:

define('GETTEXT_CLASS', true);

You must use the initialization function:

//                    filename   locale   charset
init_translate_domain('message', 'fr',    'UTF-8',  'path_to_locales_dir');

Native

echo gettext('Add');
echo ngettext('Minute', 'Minutes', 2);

Usage class

echo _gettext('Add');
echo _ngettext('Minute', 'Minutes', 2);