poEdit后PHP注释 [英] PoEdit and PHP annotations

查看:175
本文介绍了poEdit后PHP注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,使理解PoEdit软件PHP注释。这是我想向PoEdit软件捡起并放入目录code的样本:

I'm looking for a way to make PoEdit understand PHP annotations. Here's a sample of code I want PoEdit to pick up and put into catalog:

class MyController extends Controller {

    /**
     * @Title "Home"
     */
    public function index() {
        ...
    }

}

有趣的部分是 @Title 注释。它是在前端控制器访问和分配给主视图,内有效地结束了<标题> ...< /标题方式> 标签

The interesting part is @Title annotation. It is accessed in front controller and assigned to master view, effectively ending up inside <title>...</title> tag.

现在我需要的字符串翻译,但似乎PoEdit软件只能理解 _()前pressions,并加入 @Title 关键字不起作用。这可能是因为在PHP中的注释在注释块。

Now I need that string translated, but PoEdit seems to only understand _() expressions, and adding @Title to keywords does not work. This is probably because annotations in PHP are in comment block.

有没有办法强制给PoEdit软件了解注解?

Is there any way to force PoEdit to understand annotations?

推荐答案

简短的回答,你不能。

poEdit的使用 了xgettext到因此,使用特定的语法,忽略注释行扫描您的文件。

POEdit uses xgettext to scan your files therefore using specific syntax, ignoring commented lines.

例如,如果您的关键字 _ 下面的例子将被解析如下:

For example, if your keywords are _ the following examples will be parsed like:

_('测试'); - >字符串测试

_('test'); -> string 'test'

_(测试); - >字符串测试

_("test"); -> string 'test'

_(测试 - >字符串测试

_('test' -> string 'test'

_'测试 - >没有赶上

_('测试 - >没有赶上

_(测试) - >没有赶上

_($测试) - >没有赶上

// _('测试'); - >没有赶上

/ * _('测试'); * / - >没有赶上

您可以执行了xgettext 使用其他参数,但我不知道,如果你将能够实现自己的目标。

You can execute xgettext using other parameters but I'm not sure if you will be able to achieve your goal.

一个简单的解决方法(不是标准OFC)是添加其他的关键字,比如占位符,并作出PHP函数像

One easy fix (not standard ofc) is to add other keyword like placeholder and make a php function like

function placeholder($string){}

和使用它,可以poEdit的解析

and use it so POEdit can parse it

class MyController extends Controller {

    /**
     * @Title "Home"
     */
    public function index() {
      placeholder('Home');  
      ...
    }

}

在你的前端解析器只使用简单的 _($值),你将有你的标题翻译。

At your frontend parser just use the simple _($value) and you will have your title translated.

说不上怎么是你的code,但将承担其与此类似。

Dunno how is your code but will assume its something similar to this.

假设$标签='标题'和$值='家'

Assuming that $tag = 'title' and $value = 'Home'

echo '<'.$tag.'>'._($value).'</'.$tag.'>';

这篇关于poEdit后PHP注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆