1

I am having a strange problem with gettext on a server I am forced to use to redesign a website. The customer is used to having Network Solutions as provider so currently it's not an option to change providers. Anyway the problem is the following:

  • I thought it might not have gettext installed so I checked phpinfo and it is enabled.

    gettext GetText Support enabled

  • I also checked using

    if (!function_exists("gettext")) { echo "gettext is not installed\n"; } else { echo "gettext is supported\n"; }

The output says gettext is supported

I then thought perhaps the server is having issues with the native gettext so I tried using this one https://launchpad.net/php-gettext/. I uploaded it to the server and it's not working either.

The configuration in my header is

putenv("LC_ALL=".$locale.".utf8");
putenv("LANGUAGE=".$locale."utf8");
setlocale(LC_ALL, $locale.".utf8");
bindtextdomain($domain, "./locale");
bind_textdomain_codeset($domain, "UTF-8");
textdomain($domain);`

The $locale and $domain server are assigned before the functions.

The same code with gettext worked fine on my local apache server.

What could be the issue? As the site is not really that big I am considering using a database storage for the translations although I am not really into the idea but I am out of ideas why this is happening.

I have my locale file correctly located in ./locale/language_code/LC_MESSAGES/file.po and file.mo when I echo the return of the bindtextdomain it shows the full path to the locale.

Any suggestions?

4

2 回答 2

1

您将语言环境与翻译文件混淆了。语言环境是有用的基于区域和语言的常量,用于为最终用户适当地格式化文本、日期等。PHP 的gettext函数将使用语言环境来寻找正确的翻译查找文件,但这是它们共享的唯一属性。

使用 时setlocale,您不提供文件路径,而是提供语言环境标识符。这些准常数因系统而异(可能不存在),这最终可能是您使用网络解决方案的问题的一部分,但 PHP 的示例很有用。

然后可以使用bindtextdomain来指定翻译目录路径,然后调用textdomain来指定当前作用域中要使用的域。

SitePoint 有一篇名为“本地化 PHP 应用程序的“正确方式””的文章可能对您有所帮助。

于 2014-01-02T23:12:26.383 回答
0

通过聊天联系 Network Solutions 后,他们告诉我,使用他们的共享主机不能使用语言环境。特定的 .htaccess 语法也存在问题,尤其是对于他们的服务器,这在 a** 中是一个痛苦。我绝对不会推荐他们托管共享服务器。无论如何,感谢@jacob-budin 和@mike 的帮助。

于 2014-01-16T16:59:28.757 回答