我正在尝试使用 PHP 设置 getText()
$locale = "en_GB";
//if (isset($_GET["locale"])) $locale = $_GET["locale"];
$domain = 'messages';
bindtextdomain($domain, "./locale");
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
var_dump( file_exists("locale/".$locale."/LC_MESSAGES/".$domain.".mo" ) );
$results = gettext("Velkommen");
if ($results === "Velkommen") {
echo "Original English was returned. Something wrong\n";
}
echo $results . "\n";
?>
<?= _("Velkommen"); ?>`
var_dump 返回 true,但我收到错误消息,指出出现问题。
检查 locale -a 我知道服务器上存在 en_GB。
有什么想法吗?
我尝试了在谷歌上找到的多种建议。 尝试更改bindtextdomain中的路径
这个例子对我有用。
print date("d-m-Y H:i:s", date("U"));
$locale = "en_GB";
if (!function_exists("gettext")){ echo "gettext is not installed\n"; } else{ echo "gettext is supported\n"; }
//if (isset($_GET["locale"])) $locale = $_GET["locale"];
putenv('LC_ALL='.$locale);
if (false === setlocale(LC_ALL, $locale)) {
throw new LocaleNotSupportedException(sprintf('Locale "%s" is not installed in the system.', $locale));
}
$domain = 'messages';
bindtextdomain($domain, "locale");
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
var_dump( file_exists("locale/".$locale."/LC_MESSAGES/".$domain.".mo" ) );
$results = gettext("Velkommen");
if ($results === "Velkommen") {
echo "Original Danish was returned. Something wrong\n";
}
echo $results . "\n";
?>
<?= _("Velkommen"); ?>