Gettext not working, no error messages, using php 5.3

折月煮酒 提交于 2019-12-08 01:04:00

问题


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.


回答1:


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');


来源:https://stackoverflow.com/questions/8917968/gettext-not-working-no-error-messages-using-php-5-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!