2

I've been bouncing my head in this for a couple of days now without any success. I just want to get gettext to work.

What happens is that the string as it is written in the php-file is printed, not the translated one. I.e. if i do "echo gettext("Service");" then "Service" is printed, not the swedish "Tjänster".

There are absolutely no error messages in httpd/error_log. Not when running the app or (re-)starting apache.

Using Centos 6.2 and php 5.3.

This is my directory structure:

/path/to/locale/sv_SE.utf8/LC_MESSAGES/messages.mo
/path/to/setlocale.php

My messages.po file:

msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-01-18 20:09+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: setlocale.php:29
msgid "Service"
msgstr "Tjänst"

#: setlocale.php:30
msgid "Name"
msgstr "Tjänst"

setlocale.php:

<?php
  if (!function_exists("gettext"))
    {
        echo "gettext is not installed";
    }
    else
    {
        echo "gettext is supported";
    }

    echo "Exist?: ".setlocale(LC_MESSAGES, 'sv_SE.utf8').";  //Prints 'sv_SE.utf8, hence it exist in the system. 

    bindtextdomain('messages', '/var/www/html/smic/modules/core/localization/locale');
    textdomain('messages');
    bind_textdomain_codeset('messages', 'UTF-8');

    echo gettext("Service");
    echo _("Name");

?>

Since "gettext is supported " is printed, gettext is at least working to some degree.

'sv_SE.utf8' is also printed, hence it exist in the system

I've been doing everything I can in order to install correct packages (well, at least according to my understand but of course here may be some problems). PHP 5.3 comes with intl as part of the core. I have not managed to compile using ./configure --enable-intl. I do get error when trying to use that and I guess it's because it's part of php 5.3. Am I right?

I cannot find any intl.so (updatedb done and searched for it) to add to the php.ini file as well, no extension=intl.so added. I have done that without success as well, but if I cannot find intl.so I guess it's no point adding extension=intl.so?

Some threads mention some packages to install and I tried that as well:

yum install libicu-devel
yum install libicu

Would be great if anyone can help, I' don't see how to move forward and most posts/threads are discussing how to install when using PHP 5.2 in which intl is not part. But I don't even know if the problem is related to the system setup or anything else.

Nicsoft
  • 3,644
  • 9
  • 41
  • 70
  • Same problem here. What kind of librairy doesn't have error messages ? :( – Manu Aug 06 '12 at 18:05
  • I had a similar question but I solved it : http://stackoverflow.com/questions/11828542/nothing-gets-translated-using-gettext/11835265#11835265 – Manu Aug 06 '12 at 20:16

1 Answers1

0

Not sure if this can help you, but this snippet worked for me.

$lang_path = FCPATH.APPPATH.'language/locale';
putenv('LANG='.$code.'.UTF-8');
setlocale(LC_ALL, $code.'.UTF-8');
bindtextdomain('lang', $lang_path);
textdomain('lang');
Davorin
  • 1,160
  • 15
  • 31
  • If you're testing gettext on console (PHP-CLI) and not on a webserver, you have to reset the LANGUAGE environment variable too. putenv("LANGUAGE="); – Ali Nadalizadeh Jun 12 '17 at 07:06