WordPress.org

Make WordPress Core

Changeset 5258


Ignore:
Timestamp:
04/12/2007 09:15:44 PM (15 years ago)
Author:
ryan
Message:

Refactor l10n code to reduce duplication. Change placement of context. Props nbachiyski. fixes #3687

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/l10n.php

    r5081 r5258  
    1818}
    1919
    20 // Return a translated string.
    21 function __($text, $domain = 'default') {
     20function translate($text, $domain) {
    2221    global $l10n;
    2322
     
    2827}
    2928
     29// Return a translated string.
     30function __($text, $domain = 'default') {
     31    return translate($text, $domain);
     32}
     33
    3034// Echo a translated string.
    3135function _e($text, $domain = 'default') {
    32     global $l10n;
    33 
    34     if (isset($l10n[$domain]))
    35         echo apply_filters('gettext', $l10n[$domain]->translate($text), $text);
    36     else
    37         echo $text;
     36    echo translate($text, $domain);
    3837}
    3938
    4039function _c($text, $domain = 'default') {
    41     global $l10n;
    42 
    43     if ( isset($l10n[$domain]) )
    44         $whole = apply_filters('gettext', $l10n[$domain]->translate($text), $text);
    45     else
    46         $whole = $text;
    47 
    48     $trans = explode('|', $whole, 2);
    49     if ( isset( $trans[1] ) )
    50         return $trans[1];
    51     else
    52         return $trans[0];   
     40    $whole = translate($text, $domain);
     41    $last_bar = strrpos($whole, '|');
     42    if ( false == $last_bar ) {
     43        return $whole;
     44    } else {
     45        return substr($whole, 0, $last_bar);
     46    }
    5347}
    5448
     
    5852
    5953    if (isset($l10n[$domain])) {
    60         return $l10n[$domain]->ngettext($single, $plural, $number);
     54        return apply_filters('ngettext', $l10n[$domain]->ngettext($single, $plural, $number), $single, $plural, $number);
    6155    } else {
    6256        if ($number != 1)
Note: See TracChangeset for help on using the changeset viewer.