首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Poedit与智能模板?

如何使用Poedit与智能模板?
EN

Stack Overflow用户
提问于 2014-08-26 10:23:37
回答 3查看 2.1K关注 0票数 0

我在智能模板(phtml和tpl文件)上使用PoEdit,并为PHP解析器配置了以下Poedit:

延期:

代码语言:javascript
运行
复制
*.php;*.phtml;*.tpl

解析器命令:

代码语言:javascript
运行
复制
xgettext --language=PHP --force-po -o %o %C %K %F

如果我在PHP中使用gettext,<?php _('test'); ?> Poedit将检测到预期的翻译。但是我使用Smarty {_('test')}来显示翻译,Poedit没有检测到它。

是否有办法使Smarty将{和}字符检测为PHP标记?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-12-28 00:49:43

最近我和Yii一起工作,用的是Smarty和gettext。但是poedit不支持智能的语法。

https://github.com/Garefild/PoeditSmarty

接下来是使用允许的PoeditSmarty来识别Smarty的语法。

代码语言:javascript
运行
复制
{t}Text to be localized{/t}
{"Text to be localized"|_} 
{_("Text to be localized")}

非常简单的使用,PoeditSmarty创建了一个pot文件,Poedit知道要读取。

例如,我有一个文件"Header.tpl“

代码语言:javascript
运行
复制
        <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

代码语言:javascript
运行
复制
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文件的结果

代码语言:javascript
运行
复制
    # 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

在这里输入图像描述

票数 0
EN

Stack Overflow用户

发布于 2014-08-26 18:52:09

据我所知,那是不可能的。您可以更改Smarty分隔符,但不能强制Smarty将默认Smarty分隔符视为PHP代码。

票数 0
EN

Stack Overflow用户

发布于 2014-09-04 14:51:20

我的解决方案是使用templates_c文件夹中的Smarty编译文件作为PoEdit的源代码。我只是做了这个小脚本,以便在更新Po文件之前编译我的所有视图:

代码语言:javascript
运行
复制
// ... 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>');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25503480

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档