简体   繁体   English

gettext仅在PHP中翻译成英文

[英]gettext only translate to English in PHP

I'm spanish, and making tests internacionalizing a text width PHP, i only get it translated to english. 我是西班牙人,并且对文本宽度PHP进行了国际化的测试,我只将其翻译成英语。 I got this structure of files: 我得到了这种文件结构:

locale/en_US/LC_MESSAGES/con los ficheros messages.mo y messages.po
locale/es_ES/LC_MESSAGES/con los ficheros messages.mo y messages.po
locale/fr_FR/LC_MESSAGES/con los ficheros messages.mo y messages.po

Every files have the key word "Servicios" translated to each languaje. 每个文件都将关键字“ Servicios”翻译成每个语言。

And in PHP i have this code: 在PHP中,我有以下代码:

<?php
putenv("LANG=en_US");
setlocale(LC_ALL, "en_US");
bindtextdomain("messages", "locale");
textdomain("messages");
?>

When i put the code 'en_US' show the good translation, but when i change it to 'es_ES' or 'fr_FR' that way: 当我将代码“ en_US”显示为良好的翻译时,但是当我将其更改为“ es_ES”或“ fr_FR”时,则这样:

<?php
putenv("LANG=es_ES");
setlocale(LC_ALL, "es_ES");
?>

or 要么

<?php
putenv("LANG=fr_FR");
setlocale(LC_ALL, "fr_FR");
?>

still showing the translation to English 仍显示翻译成英文

I am working on Widnows 7 and the function 我正在研究Widnows 7及其功能

echo $_SERVER['HTTP_ACCEPT_LANGUAGE'] ; 

returns to "es-ES,es;q=0.8" always, 始终返回“ es-ES,es; q = 0.8”,

Which problem could it be? 可能是哪个问题? Thank you 谢谢

It is quite likely that the languages are not installed on the server your running the script on - do you have shell access to the server? 在运行脚本的服务器上很可能没有安装语言-您是否可以通过Shell访问服务器? Then try 然后尝试

locale -a

to see which locales are installed. 查看安装了哪些语言环境。 Also have a look here Is it feasible to rely on setlocale, and rely on locales being installed? 在这里也可以看看依靠setlocale和依靠所安装的语言环境是否可行?

NOTE: 注意:

be careful with the LC_ALL setting, as it may introduce some unwanted conversions. 请注意LC_ALL设置,因为它可能会引入一些不必要的转换。 For example, I used 例如,我曾经

setlocale (LC_ALL, "Dutch");

to get my weekdays in dutch on the page. 在页面上让我的工作日在荷兰。 From that moment on (as I found out many hours later) my floating point values from MYSQL where interpreted as integers because the Dutch locale wants a comma (,) instead of a point (.) before the decimals. 从那一刻起(正如我几个小时后才发现的那样),我的MYSQL浮点值被解释为整数,因为荷兰语言环境希望用逗号(,)而不是小数点前的点(。)。 I tried printf , number_format , floatval .... all to no avail. 我尝试了printfnumber_formatfloatval ....都无济于事。 1.50 was always printed as 1.00 :( 1.50始终打印为1.00 :(

When I set my locale to : 当我将语言环境设置为时:

setlocale (LC_TIME, "Dutch");

my weekdays are good now and my floating point values too. 我的工作日现在很好,浮点值也很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM