0
運行php-5.3.10PHP Gettext不能通過cli或apache工作
這是我第一次通過gettext設置i18n的網站。但是,英文文本仍在印刷中,而不是我期待的荷蘭文本。我已經使用谷歌搜索兩天了,但我仍然沒有找到解決方案。
PHP代碼,從CLI運行,即使它不給翻譯,所以Apache的緩存是不是這裏的問題。代碼:
<?php
// no errors are thrown, sadly
error_reporting(E_ALL);
$domain = 'test';
setlocale(LC_ALL, 'nl_NL.utf8'); // returns 'nl_NL.utf8', I've also tried without '.utf8' etc.
bindtextdomain($domain, dirname(__FILE__) '/locale'); // returns correct path
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain); // returns 'test'
// this prints the date in Dutch so setlocale works
echo strftime("%A %e %B %Y", mktime(0, 0, 0, 12, 22, 1978));
// this should print the translated version but just prints 'Home'
echo ' ' . gettext('Home');
荷蘭的語言環境是根據安裝 '區域設置-a',被列爲:
nl_AW
nl_AW.utf8
nl_BE.utf8
nl_NL.utf8
這是.po文件:
msgid ""
msgstr ""
"Language: nl\n"
"Content-Transfer-Encoding: 8bit\n"
"Content-Type: text/plain; charset=UTF-8\n"
msgid "Home"
msgstr "Thuis"
而且它的正確編譯爲.mo文件,msgunfmt至少不會產生錯誤。我試圖把這個文件放入locale/nl/LC_MESSAGES /,locale/nl_NL/LC_MESSAGES /和locale/nl_NL.utf8/LC_MESSAGES /。無濟於事。
我主要是在尋找一種調試方法。整個試驗和錯誤的方法有點費時。