php-gettext / Gettext

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

PoLoader Help #245

Closed Stephirio closed 4 years ago

Stephirio commented 4 years ago

From this code:

require_once __DIR__ . "/vendor/autoload.php";

use Gettext\Loader\PoLoader;

$loader = new PoLoader();

$dir = "/app/";

$t = $loader->loadFile($dir . "languages/fr.po");

How can I get a translation (for example "Hi") from the $t variable? Can i register ($t->register) it or is no longer available?

$t returns me this:

Gettext\Translation Object ( [id:protected] => Hi [context:protected] => [original:protected] => Hi [plural:protected] => [translation:protected] => Salut [pluralTranslations:protected] => Array ( ) [disabled:protected] => [references:protected] => Gettext\References Object ( ) [flags:protected] => Gettext\Flags Object ( ) [comments:protected] => Gettext\Comments Object ( ) [extractedComments:protected] => Gettext\Comments Object ( ) )

oscarotero commented 4 years ago

The register function is not longer available.

To use the translations in your code, you need to install gettext/translator: https://github.com/php-gettext/Translator

Similar question here: #240

If you only want to find a translation, other way is using the function find:

$text = $t->find(null, 'Hi');

echo $text->getTranslation();
Stephirio commented 4 years ago

The register function is not longer available.

To use the translations in your code, you need to install gettext/translator: https://github.com/php-gettext/Translator

Similar question here: #240

If you only want to find a translation, other way is using the function find:

$text = $t->find(null, 'Hi');

echo $text->getTranslation();

Thank you so much.