[英]Translation to hebrew with PHP/Gettext fails
我已經搜索了數小時以尋求解決方案,包括在文檔中。
試圖使用gettext進行希伯來語翻譯,
使用PHP 5.3.1和wamp,
它打印出“ 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");
我使用poedit創建mo / po文件,它們位於:./locale/he_IL/LC_MESSAGES/messages.mo
php文件位於“ ./”
為什么我看不到希伯來文字?
好了,解決了
必須更新到PHP版本5.3.5 / 5.3.10
並且因為我使用的是Windows,所以不得不使用此語言環境“ Hebrew_Israel.1255”而不是“ he_IL”(這是Windows始終調用希伯來語語言環境的方式)。
當然,我還必須將./locale中的文件夾重命名為“ Hebrew_Israel.1255”
現在,系統成功選擇了語言環境
正如MarcB指出的那樣,PHP不會為您神奇地將單詞翻譯成其他語言。 但是有幾種不同的解決方案可以幫助您。 例如,您可以利用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();
}
您可以在http://code.google.com/p/gtranslate-api-php/上了解有關Google翻譯API的更多信息
您應該檢查系統中是否安裝了“ he_IL”語言環境。 我不知道如何在Windows中執行此操作,但是在Linux中,您可以運行“ locale -a”(http://linux.about.com/library/cmd/blcmdl1_locale.htm)以查看所有已安裝的語言環境。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.