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

git-svn-id: http://svn.automattic.com/wordpress/trunk@5258 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-04-12 21:15:44 +00:00
parent d5bd979f87
commit 5fae2af843
1 changed files with 15 additions and 21 deletions

View File

@ -17,8 +17,7 @@ function get_locale() {
return $locale;
}
// Return a translated string.
function __($text, $domain = 'default') {
function translate($text, $domain) {
global $l10n;
if (isset($l10n[$domain]))
@ -27,29 +26,24 @@ function __($text, $domain = 'default') {
return $text;
}
// Return a translated string.
function __($text, $domain = 'default') {
return translate($text, $domain);
}
// Echo a translated string.
function _e($text, $domain = 'default') {
global $l10n;
if (isset($l10n[$domain]))
echo apply_filters('gettext', $l10n[$domain]->translate($text), $text);
else
echo $text;
echo translate($text, $domain);
}
function _c($text, $domain = 'default') {
global $l10n;
if ( isset($l10n[$domain]) )
$whole = apply_filters('gettext', $l10n[$domain]->translate($text), $text);
else
$whole = $text;
$trans = explode('|', $whole, 2);
if ( isset( $trans[1] ) )
return $trans[1];
else
return $trans[0];
$whole = translate($text, $domain);
$last_bar = strrpos($whole, '|');
if ( false == $last_bar ) {
return $whole;
} else {
return substr($whole, 0, $last_bar);
}
}
// Return the plural form.
@ -57,7 +51,7 @@ function __ngettext($single, $plural, $number, $domain = 'default') {
global $l10n;
if (isset($l10n[$domain])) {
return $l10n[$domain]->ngettext($single, $plural, $number);
return apply_filters('ngettext', $l10n[$domain]->ngettext($single, $plural, $number), $single, $plural, $number);
} else {
if ($number != 1)
return $plural;