2014-01-16 79 views
1

我想要使用gettext字符串在我的網站PHP的gettext包括字符串phpcode

的gettext沒有問題,檢測字符串,例如

<? echo _("Donations"); ?> 

<? echo _("Donate to this site");?> 
翻譯

但很明顯,通常我們會用我們網站的代碼這樣的代碼

<? echo _("$siteName was developed with one thing in mind"); ?> 

當然在該網站的,如果我們把

$siteName = "My Website"; 

以前在$網站名稱正確顯示爲

My Website was developed with one thing in mind 

我的問題是,我使用poedit來提取需要翻譯的代碼中的所有字符串,並且它似乎poedit不會像上面描述的那樣使用php代碼提取所有字符串。那麼我怎麼才能用php代碼提取poedit字符串呢?還是有其他工具我應該使用?

回答

3

一種可能性是使用sprintf。只要確保你保持在poedit字符串中的百分比(%)!

echo sprintf(_("This %s can be translated "), 'string'); 

或者使用時,多個變量

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

謝謝...從來沒有想過PHP可以做到這一點..似乎更喜歡C到我笑 – imin