Make WordPress Core

Changeset 6916


Ignore:
Timestamp:
02/19/2008 08:28:54 PM (18 years ago)
Author:
ryan
Message:

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/schema.php

    r6896 r6916  
    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'));
     270
     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');
    275283
    276284    // Add caps for Administrator role
  • trunk/wp-admin/includes/template.php

    r6910 r6916  
    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>
     
    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 ) {
     
    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}
  • trunk/wp-admin/users.php

    r6888 r6916  
    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>';
  • trunk/wp-includes/l10n.php

    r6726 r6916  
    6565 * @return string Translated text
    6666 */
    67 function translate($text, $domain) {
     67function translate($text, $domain = 'default') {
    6868    global $l10n;
    6969
     
    7575
    7676/**
    77  * __() - Retrieve a translated string
    78  *
    79  * __() is a convenience function which retrieves the translated
    80  * string from the translate().
    81  *
    82  * @see translate() An alias of translate()
    83  * @since 2.1.0
    84  *
    85  * @param string $text Text to translate
    86  * @param string $domain Optional. Domain to retrieve the translated text
     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
    8791 * @return string Translated text
    8892 */
    89 function __($text, $domain = 'default') {
    90     return translate($text, $domain);
    91 }
    92 
    93 // .
    94 /**
    95  * _e() - Display a translated string
    96  *
    97  * _e() is a convenience function which displays the returned
    98  * translated text from translate().
    99  *
    100  * @see translate() Echos returned translate() string
    101  * @since 1.2.0
    102  *
    103  * @param string $text Text to translate
    104  * @param string $domain Optional. Domain to retrieve the translated text
    105  */
    106 function _e($text, $domain = 'default') {
    107     echo translate($text, $domain);
    108 }
    109 
    110 /**
    111  * _c() - Retrieve context translated string
    112  *
    113  * Quite a few times, there will be collisions with similar
    114  * translatable text found in more than two places but with
    115  * different translated context.
    116  *
    117  * In order to use the separate contexts, the _c() function
    118  * is used and the translatable string uses a pipe ('|')
    119  * which has the context the string is in.
    120  *
    121  * When the translated string is returned, it is everything
    122  * before the pipe, not including the pipe character. If
    123  * there is no pipe in the translated text then everything
    124  * is returned.
    125  *
    126  * @since 2.2.0
    127  *
    128  * @param string $text Text to translate
    129  * @param string $domain Optional. Domain to retrieve the translated text
    130  * @return string Translated context string without pipe
    131  */
    132 function _c($text, $domain = 'default') {
     93function translate_with_context($text, $domain = 'default') {
    13394    $whole = translate($text, $domain);
    13495    $last_bar = strrpos($whole, '|');
     
    13899        return substr($whole, 0, $last_bar);
    139100    }
     101}
     102
     103/**
     104 * __() - Retrieve a translated string
     105 *
     106 * __() is a convenience function which retrieves the translated
     107 * string from the translate().
     108 *
     109 * @see translate() An alias of translate()
     110 * @since 2.1.0
     111 *
     112 * @param string $text Text to translate
     113 * @param string $domain Optional. Domain to retrieve the translated text
     114 * @return string Translated text
     115 */
     116function __($text, $domain = 'default') {
     117    return translate($text, $domain);
     118}
     119
     120// .
     121/**
     122 * _e() - Display a translated string
     123 *
     124 * _e() is a convenience function which displays the returned
     125 * translated text from translate().
     126 *
     127 * @see translate() Echos returned translate() string
     128 * @since 1.2.0
     129 *
     130 * @param string $text Text to translate
     131 * @param string $domain Optional. Domain to retrieve the translated text
     132 */
     133function _e($text, $domain = 'default') {
     134    echo translate($text, $domain);
     135}
     136
     137/**
     138 * _c() - Retrieve context translated string
     139 *
     140 * Quite a few times, there will be collisions with similar
     141 * translatable text found in more than two places but with
     142 * different translated context.
     143 *
     144 * In order to use the separate contexts, the _c() function
     145 * is used and the translatable string uses a pipe ('|')
     146 * which has the context the string is in.
     147 *
     148 * When the translated string is returned, it is everything
     149 * before the pipe, not including the pipe character. If
     150 * there is no pipe in the translated text then everything
     151 * is returned.
     152 *
     153 * @since 2.2.0
     154 *
     155 * @param string $text Text to translate
     156 * @param string $domain Optional. Domain to retrieve the translated text
     157 * @return string Translated context string without pipe
     158 */
     159function _c($text, $domain = 'default') {
     160    return translate_with_context($text, $domain);
    140161}
    141162
Note: See TracChangeset for help on using the changeset viewer.