Introduce _ex(), a hybrid between _e() and _x() -- translate with context, then echo. props westi, see #13395.

git-svn-id: http://svn.automattic.com/wordpress/trunk@14647 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2010-05-14 21:46:25 +00:00
parent 15f373629a
commit c6d21e7fbb
14 changed files with 51 additions and 36 deletions

View File

@ -159,7 +159,7 @@ if ( $comment->comment_approved != '0' ) { // if not unapproved
</tr>
<?php } ?>
<tr>
<th scope="row" valign="top"><?php /* translators: field name in comment form */ echo _x('Comment', 'noun'); ?></th>
<th scope="row" valign="top"><?php /* translators: field name in comment form */ _ex('Comment', 'noun'); ?></th>
<td><?php echo $comment->comment_content; ?></td>
</tr>
</table>

View File

@ -316,12 +316,12 @@ $page_links = paginate_links( array(
<option value="approve"><?php _e('Approve'); ?></option>
<?php endif; ?>
<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
<option value="spam"><?php echo _x('Mark as Spam', 'comment'); ?></option>
<option value="spam"><?php _ex('Mark as Spam', 'comment'); ?></option>
<?php endif; ?>
<?php if ( 'trash' == $comment_status ): ?>
<option value="untrash"><?php _e('Restore'); ?></option>
<?php elseif ( 'spam' == $comment_status ): ?>
<option value="unspam"><?php echo _x('Not Spam', 'comment'); ?></option>
<option value="unspam"><?php _ex('Not Spam', 'comment'); ?></option>
<?php endif; ?>
<?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
<option value="delete"><?php _e('Delete Permanently'); ?></option>
@ -416,7 +416,7 @@ if ( $page_links )
<option value="approve"><?php _e('Approve'); ?></option>
<?php endif; ?>
<?php if ( 'all' == $comment_status || 'approved' == $comment_status || 'moderated' == $comment_status ): ?>
<option value="spam"><?php echo _x('Mark as Spam', 'comment'); ?></option>
<option value="spam"><?php _ex('Mark as Spam', 'comment'); ?></option>
<?php endif; ?>
<?php if ( 'trash' == $comment_status ): ?>
<option value="untrash"><?php _e('Restore'); ?></option>
@ -424,7 +424,7 @@ if ( $page_links )
<?php if ( 'trash' == $comment_status || 'spam' == $comment_status || !EMPTY_TRASH_DAYS ): ?>
<option value="delete"><?php _e('Delete Permanently'); ?></option>
<?php elseif ( 'spam' == $comment_status ): ?>
<option value="unspam"><?php echo _x('Not Spam', 'comment'); ?></option>
<option value="unspam"><?php _ex('Not Spam', 'comment'); ?></option>
<?php else: ?>
<option value="trash"><?php _e('Move to Trash'); ?></option>
<?php endif; ?>

View File

@ -47,9 +47,9 @@ $comment->comment_author_email = esc_attr($comment->comment_author_email);
<div id="misc-publishing-actions">
<div class="misc-pub-section" id="comment-status-radio">
<label class="approved"><input type="radio"<?php checked( $comment->comment_approved, '1' ); ?> name="comment_status" value="1" /><?php /* translators: comment type radio button */ echo _x('Approved', 'adjective') ?></label><br />
<label class="waiting"><input type="radio"<?php checked( $comment->comment_approved, '0' ); ?> name="comment_status" value="0" /><?php /* translators: comment type radio button */ echo _x('Pending', 'adjective') ?></label><br />
<label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ echo _x('Spam', 'adjective'); ?></label>
<label class="approved"><input type="radio"<?php checked( $comment->comment_approved, '1' ); ?> name="comment_status" value="1" /><?php /* translators: comment type radio button */ _ex('Approved', 'adjective') ?></label><br />
<label class="waiting"><input type="radio"<?php checked( $comment->comment_approved, '0' ); ?> name="comment_status" value="0" /><?php /* translators: comment type radio button */ _ex('Pending', 'adjective') ?></label><br />
<label class="spam"><input type="radio"<?php checked( $comment->comment_approved, 'spam' ); ?> name="comment_status" value="spam" /><?php /* translators: comment type radio button */ _ex('Spam', 'adjective'); ?></label>
</div>
<div class="misc-pub-section curtime misc-pub-section-last">

View File

@ -33,20 +33,20 @@ do_action($taxonomy . '_pre_edit_form', $tag, $taxonomy); ?>
<?php wp_original_referer_field(true, 'previous'); wp_nonce_field('update-tag_' . $tag_ID); ?>
<table class="form-table">
<tr class="form-field form-required">
<th scope="row" valign="top"><label for="name"><?php echo _x('Name', 'Taxonomy Name'); ?></label></th>
<th scope="row" valign="top"><label for="name"><?php _ex('Name', 'Taxonomy Name'); ?></label></th>
<td><input name="name" id="name" type="text" value="<?php if ( isset( $tag->name ) ) echo esc_attr($tag->name); ?>" size="40" aria-required="true" />
<p class="description"><?php _e('The name is how it appears on your site.'); ?></p></td>
</tr>
<?php if ( !global_terms_enabled() ) { ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="slug"><?php echo _x('Slug', 'Taxonomy Slug'); ?></label></th>
<th scope="row" valign="top"><label for="slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label></th>
<td><input name="slug" id="slug" type="text" value="<?php if ( isset( $tag->slug ) ) echo esc_attr(apply_filters('editable_slug', $tag->slug)); ?>" size="40" />
<p class="description"><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p></td>
</tr>
<?php } ?>
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="parent"><?php echo _x('Parent', 'Taxonomy Parent'); ?></label></th>
<th scope="row" valign="top"><label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label></th>
<td>
<?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'name' => 'parent', 'orderby' => 'name', 'taxonomy' => $taxonomy, 'selected' => $tag->parent, 'exclude' => $tag->term_id, 'hierarchical' => true, 'show_option_none' => __('None'))); ?><br />
<?php if ( 'category' == $taxonomy ) : ?>
@ -56,7 +56,7 @@ do_action($taxonomy . '_pre_edit_form', $tag, $taxonomy); ?>
</tr>
<?php endif; // is_taxonomy_hierarchical() ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="description"><?php echo _x('Description', 'Taxonomy Description'); ?></label></th>
<th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
<td><textarea name="description" id="description" rows="5" cols="50" style="width: 97%;"><?php echo esc_html($tag->description); ?></textarea><br />
<span class="description"><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span></td>
</tr>

View File

@ -348,20 +348,20 @@ if ( current_user_can($tax->cap->edit_terms) ) {
<?php wp_nonce_field('add-tag'); ?>
<div class="form-field form-required">
<label for="tag-name"><?php echo _x('Name', 'Taxonomy Name'); ?></label>
<label for="tag-name"><?php _ex('Name', 'Taxonomy Name'); ?></label>
<input name="tag-name" id="tag-name" type="text" value="" size="40" aria-required="true" />
<p><?php _e('The name is how it appears on your site.'); ?></p>
</div>
<?php if ( ! global_terms_enabled() ) : ?>
<div class="form-field">
<label for="tag-slug"><?php echo _x('Slug', 'Taxonomy Slug'); ?></label>
<label for="tag-slug"><?php _ex('Slug', 'Taxonomy Slug'); ?></label>
<input name="slug" id="tag-slug" type="text" value="" size="40" />
<p><?php _e('The &#8220;slug&#8221; is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></p>
</div>
<?php endif; // is_multisite() ?>
<?php if ( is_taxonomy_hierarchical($taxonomy) ) : ?>
<div class="form-field">
<label for="parent"><?php echo _x('Parent', 'Taxonomy Parent'); ?></label>
<label for="parent"><?php _ex('Parent', 'Taxonomy Parent'); ?></label>
<?php wp_dropdown_categories(array('hide_empty' => 0, 'hide_if_empty' => false, 'taxonomy' => $taxonomy, 'name' => 'parent', 'orderby' => 'name', 'hierarchical' => true, 'show_option_none' => __('None'))); ?>
<?php if ( 'category' == $taxonomy ) : // @todo: Generic text for hierarchical taxonomies ?>
<p><?php _e('Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.'); ?></p>
@ -369,7 +369,7 @@ if ( current_user_can($tax->cap->edit_terms) ) {
</div>
<?php endif; // is_taxonomy_hierarchical() ?>
<div class="form-field">
<label for="tag-description"><?php echo _x('Description', 'Taxonomy Description'); ?></label>
<label for="tag-description"><?php _ex('Description', 'Taxonomy Description'); ?></label>
<textarea name="description" id="tag-description" rows="5" cols="40"></textarea>
<p><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></p>
</div>

View File

@ -1719,7 +1719,7 @@ jQuery(function($){
<?php _e('Sort Order:'); ?>
<a href="#" id="asc"><?php _e('Ascending'); ?></a> |
<a href="#" id="desc"><?php _e('Descending'); ?></a> |
<a href="#" id="clear"><?php echo _x('Clear', 'verb'); ?></a>
<a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
</div>
<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
<?php wp_nonce_field('media-form'); ?>

View File

@ -169,7 +169,7 @@ function install_search_form(){
<select name="type" id="typeselector">
<option value="term"<?php selected('term', $type) ?>><?php _e('Term'); ?></option>
<option value="author"<?php selected('author', $type) ?>><?php _e('Author'); ?></option>
<option value="tag"<?php selected('tag', $type) ?>><?php echo _x('Tag', 'Plugin Installer'); ?></option>
<option value="tag"<?php selected('tag', $type) ?>><?php _ex('Tag', 'Plugin Installer'); ?></option>
</select>
<input type="text" name="s" value="<?php echo esc_attr($term) ?>" />
<label class="screen-reader-text" for="plugin-search-input"><?php _e('Search Plugins'); ?></label>

View File

@ -3602,7 +3602,7 @@ function screen_meta($screen) {
<div id="screen-options-wrap" class="hidden">
<form id="adv-settings" action="" method="post">
<?php if ( isset($wp_meta_boxes[$screen->id]) ) : ?>
<h5><?php echo _x('Show on screen', 'Metaboxes') ?></h5>
<h5><?php _ex('Show on screen', 'Metaboxes') ?></h5>
<div class="metabox-prefs">
<?php meta_box_prefs($screen); ?>
<br class="clear" />

View File

@ -156,7 +156,7 @@ function install_theme_search_form() {
<select name="type" id="typeselector">
<option value="term" <?php selected('term', $type) ?>><?php _e('Term'); ?></option>
<option value="author" <?php selected('author', $type) ?>><?php _e('Author'); ?></option>
<option value="tag" <?php selected('tag', $type) ?>><?php echo _x('Tag', 'Theme Installer'); ?></option>
<option value="tag" <?php selected('tag', $type) ?>><?php _ex('Tag', 'Theme Installer'); ?></option>
</select>
<input type="text" name="s" size="30" value="<?php echo esc_attr($term) ?>" />
<input type="submit" name="search" value="<?php esc_attr_e('Search'); ?>" class="button" />

View File

@ -113,7 +113,7 @@ switch ( $action ) {
<?php } ?>
</tr>
<tr class="form-field">
<th scope="row"><?php echo _x( 'Registered', 'site' ) ?></th>
<th scope="row"><?php _ex( 'Registered', 'site' ) ?></th>
<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" size="40" /></td>
</tr>
<tr class="form-field">
@ -414,8 +414,8 @@ switch ( $action ) {
<select name="action">
<option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
<option value="delete"><?php _e( 'Delete' ); ?></option>
<option value="spam"><?php echo _x( 'Mark as Spam', 'site' ); ?></option>
<option value="notspam"><?php echo _x( 'Not Spam', 'site' ); ?></option>
<option value="spam"><?php _ex( 'Mark as Spam', 'site' ); ?></option>
<option value="notspam"><?php _ex( 'Not Spam', 'site' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction" id="doaction" class="button-secondary action" />
<?php wp_nonce_field( 'bulk-ms-sites' ); ?>
@ -665,8 +665,8 @@ switch ( $action ) {
<select name="action2">
<option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
<option value="delete"><?php _e( 'Delete' ); ?></option>
<option value="spam"><?php echo _x( 'Mark as Spam', 'site' ); ?></option>
<option value="notspam"><?php echo _x( 'Not Spam', 'site' ); ?></option>
<option value="spam"><?php _ex( 'Mark as Spam', 'site' ); ?></option>
<option value="notspam"><?php _ex( 'Not Spam', 'site' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
</div>

View File

@ -130,8 +130,8 @@ if ( isset( $_GET['updated'] ) && $_GET['updated'] == 'true' && ! empty( $_GET['
<select name="action">
<option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
<option value="delete"><?php _e( 'Delete' ); ?></option>
<option value="spam"><?php echo _x( 'Mark as Spam', 'user' ); ?></option>
<option value="notspam"><?php echo _x( 'Not Spam', 'user' ); ?></option>
<option value="spam"><?php _ex( 'Mark as Spam', 'user' ); ?></option>
<option value="notspam"><?php _ex( 'Not Spam', 'user' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction" id="doaction" class="button-secondary action" />
<?php wp_nonce_field( 'bulk-ms-users' ); ?>
@ -324,8 +324,8 @@ if ( isset( $_GET['updated'] ) && $_GET['updated'] == 'true' && ! empty( $_GET['
<select name="action2">
<option value="-1" selected="selected"><?php _e( 'Bulk Actions' ); ?></option>
<option value="delete"><?php _e( 'Delete' ); ?></option>
<option value="spam"><?php echo _x( 'Mark as Spam', 'user' ); ?></option>
<option value="notspam"><?php echo _x( 'Not Spam', 'user' ); ?></option>
<option value="spam"><?php _ex( 'Mark as Spam', 'user' ); ?></option>
<option value="notspam"><?php _ex( 'Not Spam', 'user' ); ?></option>
</select>
<input type="submit" value="<?php esc_attr_e( 'Apply' ); ?>" name="doaction2" id="doaction2" class="button-secondary action" />
</div>

View File

@ -172,7 +172,7 @@ if ($allowed_files) :
<li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&amp;theme=<?php echo urlencode($theme) ?>&amp;dir=theme"><?php echo $filedesc ?></a></li>
<?php endwhile; ?>
</ul>
<h3><?php /* translators: Theme stylesheets in theme editor */ echo _x('Styles', 'Theme stylesheets in theme editor'); ?></h3>
<h3><?php /* translators: Theme stylesheets in theme editor */ _ex('Styles', 'Theme stylesheets in theme editor'); ?></h3>
<ul>
<?php
$template_mapping = array();

View File

@ -363,9 +363,9 @@ if ( isset($_GET['detached']) ) { ?>
<tr>
<th scope="col" class="check-column"><input type="checkbox" /></th>
<th scope="col"></th>
<th scope="col"><?php /* translators: column name in media */ echo _x('Media', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ echo _x('Author', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ echo _x('Date Added', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ _ex('Media', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ _ex('Author', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ _ex('Date Added', 'media column name'); ?></th>
</tr>
</thead>
@ -373,9 +373,9 @@ if ( isset($_GET['detached']) ) { ?>
<tr>
<th scope="col" class="check-column"><input type="checkbox" /></th>
<th scope="col"></th>
<th scope="col"><?php /* translators: column name in media */ echo _x('Media', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ echo _x('Author', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ echo _x('Date Added', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ _ex('Media', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ _ex('Author', 'media column name'); ?></th>
<th scope="col"><?php /* translators: column name in media */ _ex('Date Added', 'media column name'); ?></th>
</tr>
</tfoot>

View File

@ -190,6 +190,21 @@ function _x( $single, $context, $domain = 'default' ) {
return translate_with_gettext_context( $single, $context, $domain );
}
/**
* Displays translated string with gettext context
*
* @see _x
* @since 3.0.0
*
* @param string $text Text to translate
* @param string $context Context information for the translators
* @param string $domain Optional. Domain to retrieve the translated text
* @return string Translated context string without pipe
*/
function _ex( $single, $context, $domain = 'default' ) {
echo _x( $single, $context, $domain );
}
function esc_attr_x( $single, $context, $domain = 'default' ) {
return esc_attr( translate_with_gettext_context( $single, $context, $domain ) );
}