我正在开发一个使用 Poedit 进行翻译的多语言 PHP 网站,但我遇到了特定语言的问题,即西班牙语。
我将开始说,在服务器中(网站发布后)两种语言都可以正常工作,但在我的 DEV 环境中,只有英语被翻译。
仅供参考,我的 Ubunto 系统上没有安装西班牙语语言环境,所以我通过以下方式安装它们:sudo apt-get install language-pack-es并通过以下方式生成相关内容: sudo locale-gen es。
我的网站下有下一个文件夹结构:
languages => en_US => LC_MESSAGES => .po + .mo (compiled) files
languages => es_ES => LC_MESSAGES => .po + .mo (compiled) files
set_locale.php 文件是下一个:
<?php
// Include the Composer autoloader
require_once 'vendor/autoload.php';
// Update include path
require_once 'Audero/SharedGettext/SharedGettext.php';
$translationsPath = 'languages';
$language = 'es_ES'; //en_ZM
if (isset($_GET['lng'])) {
$getLocale = $_GET['lng'];
if($getLocale=="en") {
$language="en_US";
}
}
$domain = 'audero';
putenv('LC_ALL=' . $language);
setlocale(LC_ALL, $language);
try {
$sharedGettext = new Audero\SharedGettext\SharedGettext($translationsPath, $language, $domain);
// Create the mirror copy of the translation and return the new domain
$newDomain = $sharedGettext->updateTranslation();
$sharedGettext->deleteOldTranslations();
// Sets the path for the current domain
bindtextdomain($newDomain, $translationsPath);
// Specifies the character encoding
bind_textdomain_codeset($newDomain, 'UTF-8');
// Choose domain
textdomain($newDomain);
//die(print_r("", true ));
} catch(\Exception $ex) {
echo $ex->getMessage();
}
?>
我用以下方式翻译文本:
...
<title><?php echo _("home_title"); ?></title>
...
但是对于西班牙语,我得到了密钥(示例后面的 home_title),但没有得到翻译。
有什么帮助吗?
谢谢。