Gettext *.mo files reader for PHP. Original package https://launchpad.net/php-gettext
- PHP >= 5.3
$ composer require kasseler/config
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.
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);