php-gettext / Gettext

PHP library to collect and manipulate gettext (.po, .mo, .php, .json, etc)
MIT License
687 stars 134 forks source link

Cannot use Translator with .po files #237

Closed Stephirio closed 4 years ago

Stephirio commented 4 years ago

I tried to do this in my code use Gettext\Translator; $t = new Translator(); $t->loadTranslations('locales/en.po'); echo $t->gettext('hi'); $t->register(); echo __('hi'); but i get nothing

oscarotero commented 4 years ago

To use Translator, you have to export the .po file to PhpArray format.

$translations = Translations::fromPoFile('locales/en.po');
$translations->toPhpArrayFile('locales/en.php');

//load the php array in the translator:
$t->loadTranslations('locales/en.php');

Here's more info: https://github.com/php-gettext/Gettext#translator

Stephirio commented 4 years ago

To use Translator, you have to export the .po file to PhpArray format.

$translations = Translations::fromPoFile('locales/en.po');
$translations->toPhpArrayFile('locales/en.php');

//load the php array in the translator:
$t->loadTranslations('locales/en.php');

Here's more info: https://github.com/php-gettext/Gettext#translator

Thank you very much! Sorry my ignorance but I'm trying to learn. Anyway you answered very fast!