WordPress l18n _x() function

2019-03-03 06:26发布

问题:

I'm trying to understand WordPress function _x(). According to WordPress website explanation that uses _x() when disambiguation by context. The example is as follows:

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

From my understanding: for "Comment", there are two translations. One is for "noun", another is for "column name". If i am right, then:

1) what is the format of PO file?

2) how to retrieve the translation by using second parameter: "noun" or "column name"?

回答1:

This is what the function _x() looks like

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

The usage in WordPress is that $context is the "area" of which the string is used. I found _x() in the file /wp-admin/network/users.php where it was used like this:

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

I don't think that there's any reason in your case to use _x() instead of __() and multiple strings.

For editing PO files you could use something like Poedit: http://www.poedit.net/download.php



标签: wordpress