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