且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PoEdit 和 PHP 注释

更新时间:2023-02-20 07:44:24

简而言之,你不能.

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.'>';