2011-06-18 107 views
0

的Gettext根本不爲我工作:PHP的gettext不起作用

putenv('LC_ALL=zh_CN.utf8'); 
    setlocale(LC_ALL, 'zh_CN.utf8'); 
    bindtextdomain('messages', __DIR__.'/locale'); 
    textdomain('messages'); 

messages.mo位置區域/ zh_CN.utf8/LC_MESSAGES。

$locale -a 
C 
en_AG 
en_US.utf8 
en_ZA.utf8 
en_ZW.utf8 
POSIX 
zh_CN.utf8 
zh_SG.utf8 

我在Ubuntu上。

有什麼想法?

+4

這是不是以某種特定的方式工作,你想與我們分享? –

+0

@ÁlvaroNope。它在gettext()和_()中顯示而不是翻譯後返回原始文本。 – umpirsky

+0

嘗試:'bindtextdomain('messages',__DIR __。'/ locale');',也許它有幫助。我認爲你需要完整的練習。 – hakre

回答

4

判斷this note,你很可能會丟失UTF-8位。這些幫助我解決了「Gettext無法正常工作」的問題。

$directory = dirname(__FILE__).'/locale'; 
$domain = 'mydomain'; 

$locale ="fi_FI.utf8"; 

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

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

內部區域,應該有

./locale/pt/LC_MESSAGES/mydomain.mo 

或類似的文件結構。

重要提示:如果mo文件已被Apache讀取,則需要重新啓動才能讀取新文件。換句話說,有一些我仍然不知道的緩存系統。

+0

我知道Apache緩存,但我在CLI工作。謝謝。 – umpirsky

+1

我花時間解決了Statusnet(http://status.net/ - 它使用gettext)不顯示我的語言的問題。我在這裏找到了答案! 運行'make'(生成* .mo文件)後,我需要**重新啓動Apache **。現在一切正常。 – kaorukobo

0

對我來說,它通過重新啓動Apache。