带有phpcode的php gettext包含字符串

带有phpcode的php gettext包含字符串,gettext,poedit,Gettext,Poedit,我正在尝试使用gettext翻译网站中的字符串 gettext在检测字符串时没有问题,例如 <? echo _("Donations"); ?> 如果我们把 $siteName = "My Website"; 以前 我的问题是,我使用poedit来提取代码中需要翻译的所有字符串,而poedit似乎没有像上面所述那样用php代码提取所有字符串。那么,如何让poedit中的php代码提取字符串呢?或者我应该使用其他工具吗?一种可能是使用sprintf。只需确保将百分比(%)保留在po

我正在尝试使用gettext翻译网站中的字符串

gettext在检测字符串时没有问题,例如

<? echo _("Donations"); ?>
如果我们把

$siteName = "My Website";
以前


我的问题是,我使用poedit来提取代码中需要翻译的所有字符串,而poedit似乎没有像上面所述那样用php代码提取所有字符串。那么,如何让poedit中的php代码提取字符串呢?或者我应该使用其他工具吗?

一种可能是使用
sprintf
。只需确保将百分比(%)保留在poedit字符串中即可

echo sprintf( _("This %s can be translated "), 'string');
或者当使用多个变量时

echo vsprintf( _("This %s can be %s"), ['string', 'translated']);

非常感谢。从没想过php可以做到这一点。。对我来说更像是c哈哈
$siteName = "My Website";
echo sprintf( _("This %s can be translated "), 'string');
echo vsprintf( _("This %s can be %s"), ['string', 'translated']);