我在智能模板(phtml和tpl文件)上使用PoEdit,并为PHP解析器配置了以下Poedit:
延期:
*.php;*.phtml;*.tpl
解析器命令:
xgettext --language=PHP --force-po -o %o %C %K %F
如果我在PHP中使用gettext,<?php _('test'); ?>
Poedit将检测到预期的翻译。但是我使用Smarty {_('test')}
来显示翻译,Poedit没有检测到它。
是否有办法使Smarty将{和}字符检测为PHP标记?
发布于 2015-12-28 00:49:43
最近我和Yii一起工作,用的是Smarty和gettext。但是poedit不支持智能的语法。
https://github.com/Garefild/PoeditSmarty
接下来是使用允许的PoeditSmarty来识别Smarty的语法。
{t}Text to be localized{/t}
{"Text to be localized"|_}
{_("Text to be localized")}
非常简单的使用,PoeditSmarty创建了一个pot文件,Poedit知道要读取。
例如,我有一个文件"Header.tpl“
<form class="login" method="post" id="login">
<h2>{__('login')}</h2>
<div class="wrap">
<input type="text" autofocus="" placeholder="{__('Username')}" class="form-control" name="username">
<br>
<input type="password" placeholder="{__('Password')}" class="form-control" name="password">
<div class="captcha">
<img alt="" src="" id="codeImage">
<label class="checkbox">
<span class="pull-right">
<a href="#" id="code" class="forgot">{__('Get a new code')}</a>
</span>
</label>
<input type="text" placeholder="{__('verify Code')}" class="form-control" name="verifyCode">
</div>
<button type="submit" class="btn login-btn" name="submitLogin">
<i class="fa fa-lock"></i>
{__('Log me in')}
</button>
<hr>
<div class="password">
<p>{__('Do you not remember your password')} ?</p>
<a data-toggle="modal" class="forgot">{__('Password Recovery')}</a>
</div>
<hr>
<h3 class="logo">{__('siteName')}</h3>
</div>
</form>
我将通过cmd运行PoeditSmarty
java -jar "C:\Program Files\Poedit\GettextTools\bin\PoeditSmarty.jar" -o C:\Users\Mike\Desktop\xxx\tempPot.pot -c UTF-8 -k __ -f header.tpl
pot文件的结果
# Garefild2@gmail.com.
# Garefild <Garefild2@gmail.com>, 2015-2020.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-12-29 16:47\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <Garefild2@gmail.com>\n"
"Language-Team: LANGUAGE <Garefild2@gmail.com>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: header.tpl:48
msgid "Password Recovery"
msgstr ""
#: header.tpl:36
msgid "Get a new code"
msgstr ""
#: header.tpl:29
msgid "Username"
msgstr ""
#: header.tpl:39
msgid "verify Code"
msgstr ""
#: header.tpl:51
msgid "siteName"
msgstr ""
#: header.tpl:27
msgid "login"
msgstr ""
#: header.tpl:47
msgid "Do you not remember your password"
msgstr ""
#: header.tpl:31
msgid "Password"
msgstr ""
#: header.tpl:43
msgid "Log me in"
msgstr ""
通过Poedit
在这里输入图像描述
发布于 2014-08-26 18:52:09
据我所知,那是不可能的。您可以更改Smarty分隔符,但不能强制Smarty将默认Smarty分隔符视为PHP代码。
发布于 2014-09-04 14:51:20
我的解决方案是使用templates_c文件夹中的Smarty编译文件作为PoEdit的源代码。我只是做了这个小脚本,以便在更新Po文件之前编译我的所有视图:
// ... smarty config here ...
$i = 0;
if ($handle = opendir('./views/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_file('./views/'.$file) {
$smarty->fetch('./views/'.$file);
$i++;
}
}
}
die('<h2>' . $i . ' templates compiled</h2>');
https://stackoverflow.com/questions/25503480
复制相似问题