Make WordPress Core

Ticket #3442: translate_roles.diff

File translate_roles.diff, 4.4 KB (added by ryan, 18 years ago)
  • wp-includes/l10n.php

     
    7474}
    7575
    7676/**
     77 * translate_with_context() - Retrieve the translated text and strip context
     78 *
     79 * If the domain is set in the $l10n global, then the text is run
     80 * through the domain's translate method. After it is passed to
     81 * the 'gettext' filter hook, along with the untranslated text as
     82 * the second parameter.
     83 *
     84 * If the domain is not set, the $text is just returned.
     85 *
     86 * @since 2.5
     87 * @uses translate()
     88 *
     89 * @param string $text Text to translate
     90 * @param string $domain Domain to retrieve the translated text
     91 * @return string Translated text
     92 */
     93function translate_with_context($text, $domain) {
     94        $whole = translate($text, $domain);
     95        $last_bar = strrpos($whole, '|');
     96        if ( false == $last_bar ) {
     97                return $whole;
     98        } else {
     99                return substr($whole, 0, $last_bar);
     100        }
     101}
     102
     103/**
    77104 * __() - Retrieve a translated string
    78105 *
    79106 * __() is a convenience function which retrieves the translated
     
    130157 * @return string Translated context string without pipe
    131158 */
    132159function _c($text, $domain = 'default') {
    133         $whole = translate($text, $domain);
    134         $last_bar = strrpos($whole, '|');
    135         if ( false == $last_bar ) {
    136                 return $whole;
    137         } else {
    138                 return substr($whole, 0, $last_bar);
    139         }
     160        return translate_with_context($text, $domain);
    140161}
    141162
    142163/**
  • wp-admin/users.php

     
    263263        if ( $role == $_GET['role'] )
    264264                $class = ' class="current"';
    265265
     266        $name = translate_with_context($name);
    266267        $name = sprintf(_c('%1$s (%2$s)|user role with count'), $name, $avail_roles[$role]);
    267268        $role_links[] = "<li><a href=\"users.php?role=$role\"$class>" . $name . '</a>';
    268269}
  • wp-admin/includes/schema.php

     
    267267
    268268function populate_roles_160() {
    269269        // Add roles
    270         add_role('administrator', _c('Administrator|User role'));
    271         add_role('editor', _c('Editor|User role'));
    272         add_role('author', _c('Author|User role'));
    273         add_role('contributor', _c('Contributor|User role'));
    274         add_role('subscriber', _c('Subscriber|User role'));
    275270
     271        // Dummy gettext calls to get strings in the catalog.
     272        _c('Administrator|User role');
     273        _c('Editor|User role');
     274        _c('Author|User role');
     275        _c('Contributor|User role');
     276        _c('Subscriber|User role');
     277
     278        add_role('administrator', 'Administrator|User role');
     279        add_role('editor', 'Editor|User role');
     280        add_role('author', 'Author|User role');
     281        add_role('contributor', 'Contributor|User role');
     282        add_role('subscriber', 'Subscriber|User role');
     283
    276284        // Add caps for Administrator role
    277285        $role = get_role('administrator');
    278286        $role->add_cap('switch_themes');
  • wp-admin/includes/template.php

     
    545545        } else {
    546546                $edit = $user_object->user_login;
    547547        }
     548        $role_name = translate_with_context($wp_roles->role_names[$role]);
    548549        $r = "<tr id='user-$user_object->ID'$style>
    549550                <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></td>
    550551                <td><strong>$edit</strong></td>
    551552                <td>$user_object->first_name $user_object->last_name</td>
    552553                <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
    553                 <td>{$wp_roles->role_names[$role]}</td>";
     554                <td>$role_name</td>";
    554555        $r .= "\n\t\t<td>";
    555556        if ( $numposts > 0 ) {
    556557                $r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
     
    891892function wp_dropdown_roles( $default = false ) {
    892893        global $wp_roles;
    893894        $r = '';
    894         foreach( $wp_roles->role_names as $role => $name )
     895        foreach( $wp_roles->role_names as $role => $name ) {
     896                $name = translate_with_context($name);
    895897                if ( $default == $role ) // Make default first in list
    896898                        $p = "\n\t<option selected='selected' value='$role'>$name</option>";
    897899                else
    898900                        $r .= "\n\t<option value='$role'>$name</option>";
     901        }
    899902        echo $p . $r;
    900903}
    901904