繁体   English   中英

PHP Twig翻译文件

[英]PHP Twig translation files

我正在使用树枝模板引擎。 我添加了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框架。

1.创建正确的PO文件。 或者尝试使用此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"

2.基于app.po生成app.mo 例如,使用po2mo.net工具。

3.将app.mo放置在locale/fr_FR/LC_MESSAGES目录中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM