jcubic
jcubic

Reputation: 66490

How to use gettext on linux in php?

I've follow instructions from How to load language with gettext in PHP?

I've created ./locale/pl_PL/LC_MESSAGES/default.po file with:

msgid "categories"
msgstr "kategorie"

I've generated mo file using:

msgfmt default.po -o default.mo 

and I have code like this:

    $lang = 'pl_PL';
    $this->root = __DIR__ . DIRECTORY_SEPARATOR;
    echo $lang . "\n" . $this->root . "locale\n";
    putenv("LC_ALL=$lang");
    setlocale(LC_ALL, $lang);
    bindtextdomain("default", $this->root . "locale");
    textdomain("default");

    echo _("categories");

but I've got untranslated text, the output is:

pl_PL
/home/kuba/projects/jcubic/cataloger/locale
categories

I've also tried to use slash at the end of locale but that didn't help.

What's wrong? How can I use gettext to translate text? I'm running php from apache 2 on GNU/Linux. I'm using slim and twig frameworks.

Upvotes: 1

Views: 248

Answers (1)

jcubic
jcubic

Reputation: 66490

I've needed to add .utf8 to the locale (so it's pl_PL.utf8) and it work.

Upvotes: 2

Related Questions