diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/admin_maintenance.php | 12 | ||||
-rw-r--r-- | core/helpers/graphics.php | 24 | ||||
-rw-r--r-- | core/libraries/I18n.php | 26 |
3 files changed, 42 insertions, 20 deletions
diff --git a/core/controllers/admin_maintenance.php b/core/controllers/admin_maintenance.php index 3eec16fc..1c9b4164 100644 --- a/core/controllers/admin_maintenance.php +++ b/core/controllers/admin_maintenance.php @@ -30,9 +30,9 @@ class Admin_Maintenance_Controller extends Admin_Controller { "callback" => "graphics::rebuild_dirty_images", "description" => ( $dirty_count ? - t(array("one" => "You have one image which is out of date", - "other" => "You have {{count}} out-of-date images"), - array("count" => $dirty_count)) + t2("You have one image which is out of date", + "You have {{count}} out-of-date images", + $dirty_count) : t("All your images are up to date")), "severity" => $dirty_count ? log::WARNING : log::SUCCESS), ArrayObject::ARRAY_AS_PROPS)); @@ -50,9 +50,9 @@ class Admin_Maintenance_Controller extends Admin_Controller { $stalled_count = $query->count(); if ($stalled_count) { log::warning("tasks", - t(array("one" => "One task is stalled", - "other" => "{{count}} tasks are stalled"), - array("count" => $stalled_count)), + t2("One task is stalled", + "{{count}} tasks are stalled", + $stalled_count), t("{{link_start}}view{{link_end}}", array("link_start" => "<a href=\"" . url::site("admin/maintenance") . "\">", "link_start" => "</a>"))); diff --git a/core/helpers/graphics.php b/core/helpers/graphics.php index 738c7d45..7b13c55d 100644 --- a/core/helpers/graphics.php +++ b/core/helpers/graphics.php @@ -217,14 +217,14 @@ class graphics_Core { $count = self::find_dirty_images_query()->count(); if ($count) { site_status::warning( - t(array("one" => "One of your photos is out of date. {{link_start}}Click here to fix it{{link_end}}", - "other" => "{{count}} of your photos are out of date. {{link_start}}Click here to fix them{{link_end}}"), - array("count" => $count, - "link_start" => "<a href=\"" . - url::site("admin/maintenance/start/graphics::rebuild_dirty_images?csrf=__CSRF__") . - "\" class=\"gDialogLink\">", - "link_end" => "</a>")), - "graphics_dirty"); + t2("One of your photos is out of date. {{link_start}}Click here to fix it{{link_end}}", + "{{count}} of your photos are out of date. {{link_start}}Click here to fix them{{link_end}}", + $count, + array("link_start" => "<a href=\"" . + url::site("admin/maintenance/start/graphics::rebuild_dirty_images?csrf=__CSRF__") . + "\" class=\"gDialogLink\">", + "link_end" => "</a>")), + "graphics_dirty"); } } @@ -254,10 +254,10 @@ class graphics_Core { } } - $task->status = t(array("one" => "Updated: 1 image. Total: {{total_count}}.", - "other" => "Updated: {{count}} images. Total: {{total_count}}."), - array("count" => $completed, - "total_count" => ($remaining + $completed))); + $task->status = t2("Updated: 1 image. Total: {{total_count}}.", + "Updated: {{count}} images. Total: {{total_count}}.", + $completed, + array("total_count" => ($remaining + $completed))); if ($completed + $remaining > 0) { $task->percent_complete = (int)(100 * $completed / ($completed + $remaining)); 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; |