php-gettext / Gettext

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

what is the equivilent of v4 Gettext->register() in v5? #286

Closed lachlan-00 closed 1 year ago

lachlan-00 commented 1 year ago

I'm sorry i have to raise this issue but i don't really understand how this code works.

Ampache loads the MO and uses __() for translations using a helper function so migration should be simple?

I've looked at the the guide https://github.com/php-gettext/Gettext/wiki/Migration-from-v4-to-v5

But i can't see a function in the v5 code that functions the same as register()

function load_gettext()
{
    $lang   = AmpConfig::get('lang');
    $mopath = __DIR__ . '/../../locale/' . $lang . '/LC_MESSAGES/messages.mo';
    if (file_exists($mopath)) {
        $gettext      = new Translator();
        $translations = Gettext\Translations::fromMoFile($mopath);
        $gettext->loadTranslations($translations);
    }
    $gettext->register();

    return true;
} // load_gettext

I'm assuming all i need to do is load the MO file using Gettext\Loader\MoLoader and then register them somehow to the __() function but the wiki page is about loading and generating files and i don't really understand.

oscarotero commented 1 year ago

In Gettext v5, the translator was moved to a different package: https://github.com/php-gettext/Translator#translator-functions

lachlan-00 commented 1 year ago

excellent! thank you.

lachlan-00 commented 1 year ago

@oscarotero do you mind if i edit the wiki page there to provide that info as well?

oscarotero commented 1 year ago

No problem. Do you need permissions or something?

lachlan-00 commented 1 year ago

No, I was just asking out of politeness. Thanks for being so responsive to my queries and I'll update the wiki tomorrow. :)