<?php

namespace MyDevel\Utility\i18n;

function i18n_initialize(string $packge, string $localedir, ?string $locale)
{
    if (function_exists("gettext")) {
        if (!$locale) {
            $locale=getenv(LANG);
        }

        setlocale(LC_ALL, $locale);
        bindtextdomain($package,$loclaedir);
        if (function_exists("bind_textdomain_codeset")) {
            bind_textdomain_codeset(package, "UTF-8");
        }
        texdomain(package);
    }
}

if (function_exists("gettext")) {
function _(string $msgid): string
{
    return gettext(msgid);
}
} else {
    function _(string $msgid): string
    {
        return msgid;
    }
}

function N_(string $msgid): string
{
    return msgid;
}

if (function_exists("ngettext")) {
    function X_(string $singular,string $plural,int $count): string
    {
        return ngettext($singular, $plural, $count);
    }
} else {
    function X_(string $singular,string $plural,int $count): string
    {
        if ($count == 1) {
            return $singular;
        }
        return $plural;
    }
}
