本文介绍了如何将Poedit与smarty模板一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在带有以下Poedit配置的PHP解析器的Smarty模板(phtml和tpl文件)上使用PoEdit:

I'm using PoEdit on smarty templates (phtml and tpl files) with the following Poedit configuration for PHP parser :

扩展名:

*.php;*.phtml;*.tpl

解析器命令:

xgettext --language=PHP --force-po -o %o %C %K %F

如果我在PHP标记内使用gettext <?php _('test');?> Poedit按预期检测到该翻译.但是我使用Smarty {_('test')} 来显示翻译,Poedit不会检测到.

If i'm using gettext inside PHP tags <?php _('test'); ?> Poedit detect that translation as expected. But i'm using Smarty {_('test')} for displaying the translation, Poedit don't detect it.

有没有办法让Smarty将{和}字符检测为PHP标签?

Is there a way to make Smarty detect { and } characters as PHP tags ?

推荐答案

最近,我开始使用与Smarty和gettext一起使用的Yii.但是poedit不支持smarty的语法.

Recently I got to work with Yii used with Smarty and gettext. but poedit not support the syntax of smarty.

https://github.com/Garefild/PoeditSmarty

这里出现了PoeditSmarty的使用,允许Poedit识别Smarty的语法.

And here comes the use of PoeditSmarty allowed Poedit recognize the syntax of Smarty.

{t}Text to be localized{/t}
{"Text to be localized"|_}
{_("Text to be localized")}

PoeditSmarty非常易于使用,它创建了Poedit可以读取的"pot"文件.

Very simple to use, PoeditSmarty creates a "pot" file which Poedit know to read.

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

For example, I have a file "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

I'll run the PoeditSmarty via cmd

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文件的结果

    # [email protected].
    # Garefild <[email protected]>, 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 <[email protected]>\n"
    "Language-Team: LANGUAGE <[email protected]>\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

在此处输入图片描述

这篇关于如何将Poedit与smarty模板一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:45