我正在使用twig模板引擎。我添加了I18n扩展名进行翻译,但它无法正常工作。它始终显示“密码”。
这是我的代码:
// index.php
putenv('LC_ALL=fr_FR');
setlocale(LC_ALL, 'fr_FR');
bindtextdomain('app', 'locale');
bind_textdomain_codeset('app', 'UTF-8');
textdomain('app');
require_once 'lib/vendor/autoload.php';
$loader = new Twig_Loader_Filesystem('templates');
$twig = new Twig_Environment($loader, array(
'charset' => 'utf-8',
'cache' => false,
'debug' => true
));
$twig->addExtension(new Twig_Extensions_Extension_I18n());
// templates/index.html
{% include 'header.html' %}
Translate that: {% trans "password" %}
{% include 'footer.html' %}
// locale/fr_FR/app.yml
password: mot de passe
有什么想法吗? 我没有使用symfony框架。
答案 0 :(得分:0)
app.po
:msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=iso-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr_FR\n"
"X-Generator: Poedit 1.8.7\n"
#: templates/1.php:3
msgid "password"
msgstr "mot de passe"
app.po
生成app.mo
。例如,使用po2mo.net工具。app.mo
放置到locale/fr_FR/LC_MESSAGES
目录。