From e53916dd0622e3db61d6a05ad0fe69e8d7c7f11a Mon Sep 17 00:00:00 2001 From: Andy Staudacher Date: Thu, 15 Jan 2009 09:30:15 +0000 Subject: Simplifying the way t() is called. Refactoring localization function t($message, $options=array()) into 2 separate functions: - the new t($message, $options=array()) is for simple strings, optionally with placeholder interpolation. - t2($singular, $plural, $count, $options=array()) is for plurals. --- core/libraries/I18n.php | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'core/libraries') diff --git a/core/libraries/I18n.php b/core/libraries/I18n.php index 2007bb07..0aa6652b 100644 --- a/core/libraries/I18n.php +++ b/core/libraries/I18n.php @@ -19,12 +19,34 @@ */ /** - * @see I18n_Core::translate($message, $options) + * Translates a localizable message. + * @param $message String The message to be translated. E.g. "Hello world" + * @param $options array (optional) Options array for key value pairs which are used + * for pluralization and interpolation. Special key: "locale" to override the + * currently configured locale. + * @return String The translated message string. */ function t($message, $options=array()) { return I18n::instance()->translate($message, $options); } +/** + * Translates a localizable message with plural forms. + * @param $singular String The message to be translated. E.g. "There is one album." + * @param $plural String The plural message to be translated. E.g. + * "There are %count albums." + * @param $count Number The number which is inserted for the %count placeholder and + * which is used to select the proper plural form ($singular or $plural). + * @param $options array (optional) Options array for key value pairs which are used + * for pluralization and interpolation. Special key: "locale" to override the + * currently configured locale. + * @return String The translated message string. + */ +function t2($singular, $plural, $count, $options=array()) { + return I18n::instance()->translate(array("one" => $singular, "other" => $plural), + array_merge($options, array("count" => $count))); +} + class I18n_Core { private $_config = array(); @@ -52,7 +74,7 @@ class I18n_Core { * the latter to override the currently configured locale. * @return String The translated message string. */ - public function translate($message, $options=array() /** @todo , $hint=null */) { + public function translate($message, $options=array()) { $locale = empty($options['locale']) ? $this->_config['default_locale'] : $options['locale']; $count = empty($options['count']) ? null : $options['count']; $values = $options; -- cgit v1.2.3