summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/admin_maintenance.php12
-rw-r--r--core/helpers/graphics.php24
-rw-r--r--core/libraries/I18n.php26
-rw-r--r--modules/comment/controllers/admin_comments.php24
-rw-r--r--modules/comment/views/admin_comments.html.php12
5 files changed, 60 insertions, 38 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;
diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php
index f8dfa8ee..d1666d41 100644
--- a/modules/comment/controllers/admin_comments.php
+++ b/modules/comment/controllers/admin_comments.php
@@ -29,27 +29,27 @@ class Admin_Comments_Controller extends Admin_Controller {
$view->content->menu = Menu::factory("root")
->append(Menu::factory("link")
->id("unpublished")
- ->label(t(array("one" => "Awaiting Moderation ({{count}})",
- "other" => "Awaiting Moderation ({{count}})"),
- array("count" => $view->content->unpublished->count())))
+ ->label(t2("Awaiting Moderation ({{count}})",
+ "Awaiting Moderation ({{count}})",
+ $view->content->unpublished->count()))
->url(url::site("admin/comments/queue/unpublished")))
->append(Menu::factory("link")
->id("published")
- ->label(t(array("one" => "Approved ({{count}})",
- "other" => "Approved ({{count}})"),
- array("count" => $view->content->published->count())))
+ ->label(t2("Approved ({{count}})",
+ "Approved ({{count}})",
+ $view->content->published->count()))
->url(url::site("admin/comments/queue/published")))
->append(Menu::factory("link")
->id("spam")
- ->label(t(array("one" => "Spam ({{count}})",
- "other" => "Spam ({{count}})"),
- array("count" => $view->content->spam->count())))
+ ->label(t2("Spam ({{count}})",
+ "Spam ({{count}})",
+ $view->content->spam->count()))
->url(url::site("admin/comments/queue/spam")))
->append(Menu::factory("link")
->id("deleted")
- ->label(t(array("one" => "Recently Deleted ({{count}})",
- "other" => "Recently Deleted ({{count}})"),
- array("count" => $view->content->deleted->count())))
+ ->label(t2("Recently Deleted ({{count}})",
+ "Recently Deleted ({{count}})",
+ $view->content->deleted->count()))
->url(url::site("admin/comments/queue/deleted")));
return $view;
}
diff --git a/modules/comment/views/admin_comments.html.php b/modules/comment/views/admin_comments.html.php
index 9ef52720..83672bc1 100644
--- a/modules/comment/views/admin_comments.html.php
+++ b/modules/comment/views/admin_comments.html.php
@@ -51,16 +51,16 @@
<div>
<? if ($spam_caught > 0): ?>
<p>
- <?= t(array("one" => "Gallery has caught {{count}} spam for you since you installed spam filtering.",
- "other" => "Gallery has caught {{count}} spam for you since you installed spam filtering."),
- array("count" => $spam_caught)) ?>
+ <?= t2("Gallery has caught {{count}} spam for you since you installed spam filtering.",
+ "Gallery has caught {{count}} spam for you since you installed spam filtering.",
+ $spam_caught) ?>
</p>
<? endif ?>
<p>
<? if ($spam->count()): ?>
- <?= t(array("one" => "There is currently one comment in your spam queue. You can delete it with a single click, but there is no undo operation so you may want to check the message first to make sure that it really is spam.",
- "other" => "There are currently {{count}} comments in your spam queue. You can delete them all with a single click, but there is no undo operation so you may want to check the messages first to make sure that they really are spam. All spam messages will be deleted after 7 days automatically."),
- array("count" => $spam->count())) ?>
+ <?= t2("There is currently one comment in your spam queue. You can delete it with a single click, but there is no undo operation so you may want to check the message first to make sure that it really is spam.",
+ "There are currently {{count}} comments in your spam queue. You can delete them all with a single click, but there is no undo operation so you may want to check the messages first to make sure that they really are spam. All spam messages will be deleted after 7 days automatically.",
+ $spam->count()) ?>
</p>
<p>
<a href="<?= url::site("admin/comments/delete_all_spam?csrf=" . access::csrf_token()) ?>">