php gettext无法正确显示法语口音

php gettext无法正确显示法语口音,php,utf-8,gettext,Php,Utf 8,Gettext,如果我在html页面上使用法语重音符号,它们将正确显示,如中所示: 雅芳美食传统餐厅 但是,使用gettext后,相同的短语显示为: 埃文斯�T� 利奇�尼德蒙特�al pour la cuisine indienne traditionnelle我也遇到了同样的问题,在检查了数千次不同的内容(HTTP编码头、页面编码头、po文件编码等)后,解决了这个问题: $gtDomain = "messages"; bindtextdomain($gtDomain, "/path/to/gettext/f

如果我在html页面上使用法语重音符号,它们将正确显示,如中所示:

雅芳美食传统餐厅

但是,使用gettext后,相同的短语显示为:


埃文斯�T� 利奇�尼德蒙特�al pour la cuisine indienne traditionnelle我也遇到了同样的问题,在检查了数千次不同的内容(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".
$gtLocale='fr_fr';
$gtLocaleEnc=“$gtLocale.UTF-8”;
//回显“gtLocale#$gtLocale#gtLocaleEnc#$gtLocaleEnc#
”; putenv(“语言=”.$gtLocale)//第一优先! putenv(“LANG=”.$gtLocale); putenv(“LC_ALL=”.$gtLocale); putenv(“LC_消息=”.$gtLocale); //回显“env LANG”,getenv('LANG'),“#
”; //回显“env LC#u ALL”,getenv('LC#u ALL'),“#
”; //echo“env LC#u MESSAGES”,getenv('LC#u MESSAGES'),“#
”; $gtIsLocaleSupported=setlocale(LC_ALL,$gtLocale); $gtIsLocaleSupportedT=setlocale(LC_消息,$gtLocale); //回显“GTISLOCALESupport#$GTISLOCALESupport#
”; //回声“gtIsLocaleSupportedT#$gtIsLocaleSupportedT#
”; //回显“getcwd#”,getcwd(),“#
”; //将文本域设置为“消息” $gtDomain=“消息”; //以下内容表示目录“消息” //e、 g.对于区域设置fr\u fr,fr应位于: ///path/to/gettext/folder/Locale/fr\u fr/LC\u MESSAGES/MESSAGES.mo: bindtextdomain($gtDomain,“/path/to/gettext/folder/Locale”); 绑定_textdomain_代码集($gtDomain,'UTF-8')//这是丢失的那块 //现在,将当前目录设置为“消息”,以便对其进行测试: textdomain($gtDomain); //如果fr_fr的.mo将“Reference”翻译为“Référence”,。。。 回声uu(“参考”);/。。。那么这应该会产生“Référence”。
我也遇到了同样的问题,在检查了数千次不同的内容(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".
$gtLocale='fr_fr';
$gtLocaleEnc=“$gtLocale.UTF-8”;
//回显“gtLocale#$gtLocale#gtLocaleEnc#$gtLocaleEnc#
”; putenv(“语言=”.$gtLocale)//第一优先! putenv(“LANG=”.$gtLocale); putenv(“LC_ALL=”.$gtLocale); putenv(“LC_消息=”.$gtLocale); //回显“env LANG”,getenv('LANG'),“#
”; //回显“env LC#u ALL”,getenv('LC#u ALL'),“#
”; //echo“env LC#u MESSAGES”,getenv('LC#u MESSAGES'),“#
”; $gtIsLocaleSupported=setlocale(LC_ALL,$gtLocale); $gtIsLocaleSupportedT=setlocale(LC_消息,$gtLocale); //回显“GTISLOCALESupport#$GTISLOCALESupport#
”; //回声“gtIsLocaleSupportedT#$gtIsLocaleSupportedT#
”; //回显“getcwd#”,getcwd(),“#
”; //将文本域设置为“消息” $gtDomain=“消息”; //以下内容表示目录“消息” //e、 g.对于区域设置fr\u fr,fr应位于: ///path/to/gettext/folder/Locale/fr\u fr/LC\u MESSAGES/MESSAGES.mo: bindtextdomain($gtDomain,“/path/to/gettext/folder/Locale”); 绑定_textdomain_代码集($gtDomain,'UTF-8')//这是丢失的那块 //现在,将当前目录设置为“消息”,以便对其进行测试: textdomain($gtDomain); //如果fr_fr的.mo将“Reference”翻译为“Référence”,。。。 回声uu(“参考”);/。。。那么这应该会产生“Référence”。
遵循?您可以使用函数
utf8\u encode()
正确显示它1)为什么您认为文本是用拉丁语编码的?2) 如果是的话,那么在某个地方就有一个根编码问题需要解决。3) 如果这样做有效,这可能适用于法语,但对非拉丁1语言毫无帮助,这也是一个糟糕的猴子补丁。如何将“utf8_encode()”与“gettext()”结合使用?我在.po文件中使用了html unicode字符串。例如,我使用é;而不是你。为了方便,我制作了一个php脚本来进行替换。该脚本使用以下php函数:函数accent2html($text){$text=htmlentities($text,ENT_NOQUOTES,“UTF-8”);$text=htmlspecialchars_decode($text);返回$text;}后跟?您可以使用函数
utf8_encode()
正确显示它1)为什么假设文本是用拉丁语编码的?2) 如果是的话,那么在某个地方就有一个根编码问题需要解决。3) 如果这样做有效,这可能适用于法语,但对非拉丁1语言毫无帮助,这也是一个糟糕的猴子补丁。如何将“utf8_encode()”与“gettext()”结合使用?我在.po文件中使用了html unicode字符串。例如,我使用é;而不是你。为了方便,我制作了一个php脚本来进行替换。脚本使用以下php函数:函数accent2html($text){$text=htmlentities($text,ENT_NOQUOTES,“UTF-8”);$text=htmlspecialchars_decode($text);返回$text;}这应该是可以接受的答案。绑定_textdomain_代码集($gtDomain,'UTF-8');这是我所需要的。这应该是公认的答案。绑定_textdomain_代码集($gtDomain,'UTF-8');这是我需要的