Don't save translated role names to the DB. Instead, translate them on the fly. fixes #3442 #5537

git-svn-id: https://develop.svn.wordpress.org/trunk@6916 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-02-19 20:28:54 +00:00
parent 761397a148
commit b96affbfd5
4 changed files with 48 additions and 15 deletions

View File

@ -267,11 +267,19 @@ function populate_roles() {
function populate_roles_160() {
// Add roles
add_role('administrator', _c('Administrator|User role'));
add_role('editor', _c('Editor|User role'));
add_role('author', _c('Author|User role'));
add_role('contributor', _c('Contributor|User role'));
add_role('subscriber', _c('Subscriber|User role'));
// Dummy gettext calls to get strings in the catalog.
_c('Administrator|User role');
_c('Editor|User role');
_c('Author|User role');
_c('Contributor|User role');
_c('Subscriber|User role');
add_role('administrator', 'Administrator|User role');
add_role('editor', 'Editor|User role');
add_role('author', 'Author|User role');
add_role('contributor', 'Contributor|User role');
add_role('subscriber', 'Subscriber|User role');
// Add caps for Administrator role
$role = get_role('administrator');

View File

@ -545,12 +545,13 @@ function user_row( $user_object, $style = '', $role = '' ) {
} else {
$edit = $user_object->user_login;
}
$role_name = translate_with_context($wp_roles->role_names[$role]);
$r = "<tr id='user-$user_object->ID'$style>
<td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></td>
<td><strong>$edit</strong></td>
<td>$user_object->first_name $user_object->last_name</td>
<td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
<td>{$wp_roles->role_names[$role]}</td>";
<td>$role_name</td>";
$r .= "\n\t\t<td>";
if ( $numposts > 0 ) {
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
@ -891,11 +892,13 @@ function the_attachment_links( $id = false ) {
function wp_dropdown_roles( $default = false ) {
global $wp_roles;
$r = '';
foreach( $wp_roles->role_names as $role => $name )
foreach( $wp_roles->role_names as $role => $name ) {
$name = translate_with_context($name);
if ( $default == $role ) // Make default first in list
$p = "\n\t<option selected='selected' value='$role'>$name</option>";
else
$r .= "\n\t<option value='$role'>$name</option>";
}
echo $p . $r;
}

View File

@ -263,6 +263,7 @@ foreach ( $wp_roles->get_names() as $role => $name ) {
if ( $role == $_GET['role'] )
$class = ' class="current"';
$name = translate_with_context($name);
$name = sprintf(_c('%1$s (%2$s)|user role with count'), $name, $avail_roles[$role]);
$role_links[] = "<li><a href=\"users.php?role=$role\"$class>" . $name . '</a>';
}

View File

@ -64,7 +64,7 @@ function get_locale() {
* @param string $domain Domain to retrieve the translated text
* @return string Translated text
*/
function translate($text, $domain) {
function translate($text, $domain = 'default') {
global $l10n;
if (isset($l10n[$domain]))
@ -73,6 +73,33 @@ function translate($text, $domain) {
return $text;
}
/**
* translate_with_context() - Retrieve the translated text and strip context
*
* If the domain is set in the $l10n global, then the text is run
* through the domain's translate method. After it is passed to
* the 'gettext' filter hook, along with the untranslated text as
* the second parameter.
*
* If the domain is not set, the $text is just returned.
*
* @since 2.5
* @uses translate()
*
* @param string $text Text to translate
* @param string $domain Domain to retrieve the translated text
* @return string Translated text
*/
function translate_with_context($text, $domain = 'default') {
$whole = translate($text, $domain);
$last_bar = strrpos($whole, '|');
if ( false == $last_bar ) {
return $whole;
} else {
return substr($whole, 0, $last_bar);
}
}
/**
* __() - Retrieve a translated string
*
@ -130,13 +157,7 @@ function _e($text, $domain = 'default') {
* @return string Translated context string without pipe
*/
function _c($text, $domain = 'default') {
$whole = translate($text, $domain);
$last_bar = strrpos($whole, '|');
if ( false == $last_bar ) {
return $whole;
} else {
return substr($whole, 0, $last_bar);
}
return translate_with_context($text, $domain);
}
/**