Ian
Ian

Reputation: 25356

PHP Gettext Not Working

Here's my ./locale/fr/LC_MESSAGES/messages.po file:

msgid "NO GOOD"
msgstr "IT WORKED!"

Command used to generate the .mo file:

$ msgfmt -o locale/fr/LC_MESSAGES/messages.mo locale/fr/LC_MESSAGES/messages.po

My PHP file (being run via CLI, for testing purposes, as root).

<?php 
    bindtextdomain('messages','./locale');
    textdomain('messages');
    setlocale(LC_MESSAGES, 'fr');
    echo gettext("NO GOOD");

Here's my output:

$ NO GOOD

PHPInfo:

GetText Support => enabled

Any ideas why this might not work?

Upvotes: 1

Views: 6773

Answers (2)

Maskipaps
Maskipaps

Reputation: 11

  1. make sure language is supported
  2. install gettext and enable it in php.ini
  3. check correct format of po (it should have the headers)
  4. make sure mbstring.internalcoding is set to UTF-8 ()uncomment for utf8 in php.ini)
  5. restart php and web server

Upvotes: 1

Ian
Ian

Reputation: 25356

Turns out the reason it wasn't working is the locale I choose has to be a recognized one by the system.

In my case, fr is not a valid locale, I had to pick fr_FR.UTF-8 which the system recognizes...

Upvotes: 8

Related Questions