php - PHP + Poedit + Gettext 不适用于西班牙语
问题描述
我正在开发一个使用 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),但没有得到翻译。
有什么帮助吗?
谢谢。
解决方案
推荐阅读
- python - 如何在 Ubuntu 上的 LibreOffice 中打开 xlsx 文件?
- angular - 处理 Angular 材料反应形式错误消息的最佳方法是什么?
- unity3d - Unity 中有什么方法可以在内置管道中使用 HDRP 制作贴花投影仪之类的东西吗?
- php - Laravel Nova 条件验证:required_if + 存在规则
- linux - 如何向 docker 容器添加 SSH 访问权限
- java - 如何在具有@ManyToMany关系JPA springboot的同时摆脱循环冗余
- javascript - 在 javascript 或 c# 中从 Html 源中查找重定向 URL
- unity3d - Unity - 如何根据 3D 中另一个对象的间距计算一个对象的新位置
- node.js - 无法从 App Engine 连接到 CloudSQL 数据库 - Node JS
- kotlin - 为什么函数在同一范围内优先于类属性的可调用对象?