如果我在html中的页面上使用法语口音,它们会正确显示:
avonsétél'icônedeMontréalpourla cuisine indienne traditionnelle。
但是,使用gettext后,相同的短语显示为:
avons t l'ic nedeMontr alpourla cuisine indienne traditionnelle<
po文件正确显示,据我所知,所有内容都以utf-8编码。我在HEX中查看了.mo文件并且值是正确的,例如C3 A9表示“é”。
有什么想法吗? 感谢
答案 0 :(得分:2)
我遇到了同样的问题,在检查了数千次不同的事情(HTTP编码标题,页内编码标题,.po文件编码等)后,这解决了它:
$gtDomain = "messages";
bindtextdomain($gtDomain, "/path/to/gettext/folder/Locale");
bind_textdomain_codeset($gtDomain, 'UTF-8'); //This was the missing piece.
这是一个更完整的摘录:
$gtLocale = 'fr_FR';
$gtLocaleEnc = "$gtLocale.UTF-8";
//echo "gtLocale #$gtLocale# gtLocaleEnc #$gtLocaleEnc#<br />";
putenv("LANGUAGE=" . $gtLocale); //First priority!
putenv("LANG=" . $gtLocale);
putenv("LC_ALL=" . $gtLocale);
putenv("LC_MESSAGES=" . $gtLocale);
//echo "env LANG #", getenv('LANG'), "#<br />";
//echo "env LC_ALL #", getenv('LC_ALL'), "#<br />";
//echo "env LC_MESSAGES #", getenv('LC_MESSAGES'), "#<br />";
$gtIsLocaleSupported = setlocale(LC_ALL, $gtLocale);
$gtIsLocaleSupportedT = setlocale(LC_MESSAGES, $gtLocale);
//echo "gtIsLocaleSupported #$gtIsLocaleSupported#<br />";
//echo "gtIsLocaleSupportedT #$gtIsLocaleSupportedT#<br />";
//echo "getcwd #", getcwd(), "#<br />";
// Set the text domain as "messages"
$gtDomain = "messages";
//The following means that the catalog "messages"
//e.g. for the locale fr_FR is to be in:
///path/to/gettext/folder/Locale/fr_FR/LC_MESSAGES/messages.mo:
bindtextdomain($gtDomain, "/path/to/gettext/folder/Locale");
bind_textdomain_codeset($gtDomain, 'UTF-8'); //This was the missing piece
//Now set the current catalog to be "messages" in order to test it:
textdomain($gtDomain);
//If your .mo for fr_FR translates "Reference" as "Référence",...
echo _("Reference"); //...then this should yield "Référence".