PoEdit 和 PHP 注释 [英] PoEdit and PHP annotations

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

问题描述

我正在寻找一种方法让 PoEdit 理解 PHP 注释.这是我希望 PoEdit 提取并放入目录的代码示例:

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 似乎只能理解 _() 表达式,并且将 @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'); -> 字符串 'test'

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

_("test"); -> 字符串 'test'

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

_('test' -> 字符串 'test'

_('test' -> string 'test'

_ 'test -> 没有捕获

_('test -> 没有捕获

_(test) -> 没有捕获

_($test) -> 没有捕获

//_('test'); -> 没有捕获

/*_('test');*/ -> 没有捕获

您可以使用其他参数执行 xgettext,但我不确定您是否能够实现目标.

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

一个简单的解决方法(非标准 ofc)是添加其他关键字,如 placeholder 并创建一个 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');  
      ...
    }

}

在您的前端解析器中,只需使用简单的 _($value) 即可翻译标题.

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

不知道您的代码如何,但会假设它与此类似.

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

假设 $tag = 'title' 和 $value = 'Home'

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

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

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

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