Gettext的总是会使用系统默认的语言环境 [英] Gettext will always use system default locale

查看:353
本文介绍了Gettext的总是会使用系统默认的语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要本地化仅适用于Windows的PHP的Web应用程序,我评估 gettext扩展但我中号有困难的时候试图让它在我的Windows 7开发工作盒。我用试错连同进程监视器战胜贫困和不准确的文档,我已经设法让从*对应于计算机的默认语言环境(现代西班牙在我的情况)的.po目录_()显示字符串。 所有我尝试设置不同的区域会被忽略。

我写了一个测试脚本,有很多冗余的东西:

 < D​​L>< PHP定义('DIR_LOCALE',__DIR__ DIRECTORY_SEPARATOR'区域'。);
bindtextdomain('将军',DIR_LOCALE);
bind_textdomain_ codeSET('一般','utf-8');
textdomain('一般');如果(!定义(LC_MESSAGES')){
    定义('LC_MESSAGES',5);
}$ pruebas =阵列(
    'ENU',
    es_ES',
    EN_GB',
    英英,
    Spanish_Spain.1252',
    ESN,
    '西班牙',
    西班牙现代,
);
的foreach($ pruebas为$区域){
    传给putenv(LC_ALL = $语言环境);
    的setlocale(LC_ALL,$区域);    传给putenv(LC_MESSAGES = $语言环境);
    的setlocale(LC_MESSAGES,$区域);    传给putenv(LANGUAGE = $语言环境);
    传给putenv(LANG = $语言环境);
?>
    < D​​T><?=用htmlspecialchars($区域)>< / DT>
    < D​​D>< = _('codigo_idioma')>< / DD>
< PHP} GT?;
< / DL>

在我的情况下,< = _('codigo_idioma')> 始终打印 es_ES @现代

我有PHP / 5.4.5但我希望得到它在任何合理的了最新的服务器客户自己的工作。

我读过许多关于甚至在Windows上,但没有确切的细节安装语言环境的需要模糊引用。 什么可问题是什么?

(我知道,常见的意见是转储ge​​ttext和使用任何其他图书馆。)


进一步测试:

我的code完美运行的,在另外两个计算机:32位Windows Vista和32位Windows 7 32位。它没有在我的电脑(64位Windows 7),另一个(32位Windows Server 2003)


  • Apache的版本好像无关(这也与命令行间preTER发生)。

  • PHP版本似乎不相关的(也试过最新的32位PHP /在我的电脑5.5.5)。

  • 我的 [HKEY_LOCAL_MACHINE \\系统\\ CurrentControlSet \\控制\\ NLS] 注册表树是相同的其他七框。

编辑:虽然在命令行测试,我发现,在运行PHP脚本之前设置 LANG 环境变量的变化最终语言:

  C:\\>设置LANG = EN_GB
C:\\> PHP的C:\\测试\\ gettext.php

这明确地证明了我的电脑有正确的资产,但也让我想知道为什么PHP声称 putenv()函数的作品,然后忽略它:

 的var_dump(GETENV('郎'),传给putenv('LANG = EN_GB'),GETENV('郎'));

布尔(假)
布尔(真)
串(5)把zh_CN

甚至这个没有任何影响:

  $ _ ENV ['LANG'] ='EN_GB';
$ _ SERVER ['LANG'] ='EN_GB';


解决方案

这是一个问题这就是被承认和部分固定由PHP团队。

这是一个相当技术性的东西,显然涉及到路的环境变量(上gettext的严重依赖)基础平台进行处理。此外,一些已在Visual C运行时库改为从VC9到VC11影响这一切。

要总结一下:


  • 非线程安全的建立已经固定在源代码树21 ST 2014年11月。

  • 线程安全的建立(如Apache模块)没有并没有在视线清晰的解决方案。

I need to localise a Windows-only PHP web application and I'm evaluating the gettext extension but I'm having the hardest time trying to make it work in my Windows 7 development box. I've used trial and error together with Process Monitor to overcome the poor and inaccurate documentation and I've managed to make _() display strings from the *.po catalogue that corresponds to the computer's default locale (Modern Spanish in my case). All my attempts to set a different locale are silently ignored.

I've written a test script with lots of redundant stuff:

<dl><?php

define('DIR_LOCALE', __DIR__ . DIRECTORY_SEPARATOR . 'locale');
bindtextdomain('general', DIR_LOCALE);
bind_textdomain_codeset('general', 'UTF-8');
textdomain('general');

if(!defined('LC_MESSAGES')){
    define('LC_MESSAGES', 5);
}

$pruebas = array(
    'enu',
    'es_ES',
    'en_GB',
    'english-uk',
    'Spanish_Spain.1252',
    'esn',
    'spanish',
    'spanish-modern',
);
foreach($pruebas as $locale){
    putenv("LC_ALL=$locale");
    setlocale(LC_ALL, $locale);

    putenv("LC_MESSAGES=$locale");
    setlocale(LC_MESSAGES, $locale);

    putenv("LANGUAGE=$locale");
    putenv("LANG=$locale");
?>
    <dt><?=htmlspecialchars($locale)?></dt>
    <dd><?=_('codigo_idioma')?></dd>
<?php } ?>
</dl>

In my case, <?=_('codigo_idioma')?> always prints es_ES@modern.

I have PHP/5.4.5 but I'm expecting to get it working in any reasonably up-to-date server our customers own.

I've read lots of vague references about the need to install locales even on Windows but no exact details. What can the problem be?

(I'm aware that the common advice is to dump gettext and use any other library.)


Further testing:

My code run flawlessly as-is in another two computers: 32-bit Windows Vista and 32-bit Windows 7 32-bit. It fails in my computer (64-bit Windows 7) and another one (32-bit Windows Server 2003)

  • Apache version seems irrelevant (it also happens with the command-line interpreter).
  • PHP version seems irrelevant (also tried latest 32-bit PHP/5.5.5 in my PC).
  • My [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls] registry tree is identical to the other Seven box.

Edit: While testing on the command-line, I've discovered that setting the LANG environment variable before running the PHP script finally changes the language:

C:\>set LANG=en_GB
C:\>php C:\test\gettext.php

This definitively proves that my computer has the correct assets but also makes me wonder why PHP claims that putenv() works and then ignores it:

var_dump( getenv('LANG'), putenv('LANG=en_GB'), getenv('LANG') );

bool(false)
bool(true)
string(5) "en_GB"

Even this doesn't have any effect:

$_ENV['LANG'] = 'en_GB';
$_SERVER['LANG'] = 'en_GB';

解决方案

It's an issue that's been acknowledged and partially fixed by the PHP team.

It's a fairly technical thing, apparently related to the way environment variables (on which gettext heavily depends) are handled by the underlying platform. Also, something has changed in the Visual C Runtime libraries from VC9 to VC11 that affects all this.

To sum up:

  • Non thread-safe builds have been fixed in the source tree on 21st Nov. 2014.
  • Thread-safe builds (e.g. Apache module) haven't and there isn't a clear solution in sight.

这篇关于Gettext的总是会使用系统默认的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆