From 5fae2af843430fc8b32075cc38194903fbb3e0b5 Mon Sep 17 00:00:00 2001 From: ryan 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: http://svn.automattic.com/wordpress/trunk@5258 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- 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;