From 3b2de5b5df20cf5285294f5d844c45e656f6ecad Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 12 Apr 2007 21:15:44 +0000 Subject: [PATCH] Refactor l10n code to reduce duplication. Change placement of context. Props nbachiyski. fixes #3687 git-svn-id: https://develop.svn.wordpress.org/trunk@5258 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/l10n.php | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 0847ea3775..4dba679896 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -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;