2011-04-27 42 views
1

我想了解WordPress函數_x()。根據WordPress網站的解釋,當用上下文消除歧義時,使用_x()。示例如下:WordPress l18n _x()函數

if (false === $commenttxt) $commenttxt = _x('Comment', 'noun'); 
if (false === $trackbacktxt) $trackbacktxt = __('Trackback'); 
if (false === $pingbacktxt) $pingbacktxt = __('Pingback'); 
... 
// some other place in the code 
echo _x('Comment', 'column name'); 

從我的理解:對於「評論」,有兩種翻譯。一個是「名詞」,另一個是「列名」。如果我是對的,那麼:

1)PO文件的格式是什麼?

2)如何通過使用第二個參數來檢索翻譯:「名詞」或「列名」?

回答

1

這就是功能_x()看起來像

_x($single, string $context, [string $domain = 'default'], string $text) 

在WordPress的用法是$上下文是其中使用該字符串的「區域」。我發現_x()在它被用於這樣的文件/wp-admin/network/users.php:

_x('Users', 'users per page (screen options)') 

我不認爲有任何理由,你的情況使用_x()代替__()和多字符串。

要編輯PO文件,您可以使用類似Poedit的東西:http://www.poedit.net/download.php