简体   繁体   English

用PHP / Gettext转换为希伯来语失败

[英]Translation to hebrew with PHP/Gettext fails

I've searched hours for a solution for this including in the documentation. 我已经搜索了数小时以寻求解决方案,包括在文档中。

trying to use gettext for hebrew translations, 试图使用gettext进行希伯来语翻译,

using PHP 5.3.1 and wamp, 使用PHP 5.3.1和wamp,

it prints out "hello world" and not the Hebrew equivalent 它打印出“ hello world”而不是希伯来语

$directory = '/locale';
$domain = 'messages';
$locale ="he_IL";

putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows

setlocale( LC_ALL, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');

echo _("hello world");

I use poedit to create the mo/po files, they are located on: ./locale/he_IL/LC_MESSAGES/messages.mo 我使用poedit创建mo / po文件,它们位于:./locale/he_IL/LC_MESSAGES/messages.mo

the php file is at "./" php文件位于“ ./”

Why don't I get the hebrew text? 为什么我看不到希伯来文字?

Ok solved, 好了,解决了

Had to update to PHP version 5.3.5/5.3.10 必须更新到PHP版本5.3.5 / 5.3.10

and because I'm using windows I had to use this locale "Hebrew_Israel.1255" instead of "he_IL" (that's how windows calls the hebrew locale anyway). 并且因为我使用的是Windows,所以不得不使用此语言环境“ Hebrew_Israel.1255”而不是“ he_IL”(这是Windows始终调用希伯来语语言环境的方式)。

Of course I had to also rename the folders in the ./locale to "Hebrew_Israel.1255" 当然,我还必须将./locale中的文件夹重命名为“ Hebrew_Israel.1255”

Now the system successfully chooses the locale 现在,系统成功选择了语言环境

as pointed out by MarcB, PHP isn't magically going to translate the words into different language for you. 正如MarcB指出的那样,PHP不会为您神奇地将单词翻译成其他语言。 but there are several different solutions out there to help you out. 但是有几种不同的解决方案可以帮助您。 you can make use of google translator API to convert the text between different languages for example. 例如,您可以利用Google翻译器API在不同语言之间转换文本。

 try {
       $gt = new Gtranslate;
       echo "Translating [Hello World] from English to German => ".$gt->english_to_german("hello world")."<br/>";
       echo "Translating [Ciao mondo] Italian to English => ".$gt->it_to_en("Ciao mondo")."<br/>";
 } catch (GTranslateException $ge) {
       echo $ge->getMessage();
 }

you can read more about google translator API here http://code.google.com/p/gtranslate-api-php/ 您可以在http://code.google.com/p/gtranslate-api-php/上了解有关Google翻译API的更多信息

You should check that "he_IL" locale is installed in your system. 您应该检查系统中是否安装了“ he_IL”语言环境。 I don't know how to do it in Windows, but in Linux you can run "locale -a"(http://linux.about.com/library/cmd/blcmdl1_locale.htm) to see all locales installed. 我不知道如何在Windows中执行此操作,但是在Linux中,您可以运行“ locale -a”(http://linux.about.com/library/cmd/blcmdl1_locale.htm)以查看所有已安装的语言环境。

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

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