summaryrefslogtreecommitdiff
path: root/core/libraries
diff options
context:
space:
mode:
authorAndy Staudacher <andy.st@gmail.com>2009-01-15 09:30:15 +0000
committerAndy Staudacher <andy.st@gmail.com>2009-01-15 09:30:15 +0000
commite53916dd0622e3db61d6a05ad0fe69e8d7c7f11a (patch)
treedd7b6c0bbb6884341691189e98451f90870b6c35 /core/libraries
parent0bbde9e059c51fe61c92d23f9f6a4518b2fb1a8c (diff)
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.
Diffstat (limited to 'core/libraries')
-rw-r--r--core/libraries/I18n.php26
1 files changed, 24 insertions, 2 deletions
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;