From b96affbfd5af275a168bc8047a894d45a26842e3 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 19 Feb 2008 20:28:54 +0000 Subject: [PATCH] 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 --- wp-admin/includes/schema.php | 18 ++++++++++++----- wp-admin/includes/template.php | 7 +++++-- wp-admin/users.php | 1 + wp-includes/l10n.php | 37 ++++++++++++++++++++++++++-------- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index 2cbd45e6d4..ece6b5beec 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -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'); diff --git a/wp-admin/includes/template.php b/wp-admin/includes/template.php index 39651f874d..83aab1ae80 100644 --- a/wp-admin/includes/template.php +++ b/wp-admin/includes/template.php @@ -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 = " $edit $user_object->first_name $user_object->last_name $email - {$wp_roles->role_names[$role]}"; + $role_name"; $r .= "\n\t\t"; if ( $numposts > 0 ) { $r .= ""; @@ -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"; else $r .= "\n\t"; + } echo $p . $r; } diff --git a/wp-admin/users.php b/wp-admin/users.php index 0e292ea900..be61f0a5ea 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -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[] = "
  • " . $name . ''; } diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 4701282331..2d43dbbb37 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -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); } /**