summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gallery/controllers/admin_maintenance.php5
-rw-r--r--modules/gallery/controllers/l10n_client.php2
-rw-r--r--modules/gallery/helpers/gallery_task.php2
-rw-r--r--modules/gallery/libraries/Gallery_I18n.php45
-rw-r--r--modules/gallery/libraries/drivers/Cache/Database.php12
5 files changed, 46 insertions, 20 deletions
diff --git a/modules/gallery/controllers/admin_maintenance.php b/modules/gallery/controllers/admin_maintenance.php
index d90fe0ea..c16c5c41 100644
--- a/modules/gallery/controllers/admin_maintenance.php
+++ b/modules/gallery/controllers/admin_maintenance.php
@@ -209,9 +209,10 @@ class Admin_Maintenance_Controller extends Admin_Controller {
message::success(t("Task failed"));
break;
}
+ // Using sprintf("%F") to avoid comma as decimal separator.
print json_encode(array("result" => "success",
"task" => array(
- "percent_complete" => $task->percent_complete,
+ "percent_complete" => sprintf("%F", $task->percent_complete),
"status" => (string) $task->status,
"done" => (bool) $task->done),
"location" => url::site("admin/maintenance")));
@@ -219,7 +220,7 @@ class Admin_Maintenance_Controller extends Admin_Controller {
} else {
print json_encode(array("result" => "in_progress",
"task" => array(
- "percent_complete" => $task->percent_complete,
+ "percent_complete" => sprintf("%F", $task->percent_complete),
"status" => (string) $task->status,
"done" => (bool) $task->done)));
}
diff --git a/modules/gallery/controllers/l10n_client.php b/modules/gallery/controllers/l10n_client.php
index e20bab50..be0aaa11 100644
--- a/modules/gallery/controllers/l10n_client.php
+++ b/modules/gallery/controllers/l10n_client.php
@@ -80,6 +80,8 @@ class L10n_Client_Controller extends Controller {
$entry->save();
+ Gallery_I18n::clear_cache($locale);
+
print json_encode(new stdClass());
}
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index 3e6278e5..617f7f48 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -201,6 +201,8 @@ class gallery_task_Core {
$total = $num_fetched + $num_remaining;
$task->percent_complete = 70 + 30 * ((float) $num_fetched / $total);
} else {
+ Gallery_I18n::clear_cache();
+
$task->done = true;
$task->state = "success";
$task->status = t("Translations installed/updated");
diff --git a/modules/gallery/libraries/Gallery_I18n.php b/modules/gallery/libraries/Gallery_I18n.php
index ac0588e3..0e9c0bdc 100644
--- a/modules/gallery/libraries/Gallery_I18n.php
+++ b/modules/gallery/libraries/Gallery_I18n.php
@@ -150,33 +150,43 @@ class Gallery_I18n_Core {
private function lookup($locale, $message) {
if (!isset($this->_cache[$locale])) {
- $this->_cache[$locale] = array();
- // TODO: Load data from locale file instead of the DB.
+ $this->_cache[$locale] = self::load_translations($locale);
+ }
+
+ $key = self::get_message_key($message);
+
+ if (isset($this->_cache[$locale][$key])) {
+ return $this->_cache[$locale][$key];
+ } else {
+ return null;
+ }
+ }
+
+ private static function load_translations($locale) {
+ $cache_key = "translation|" . $locale;
+ $cache = Cache::instance();
+ $translations = $cache->get($cache_key);
+ if (empty($translations)) {
foreach (db::build()
->select("key", "translation")
->from("incoming_translations")
->where("locale", "=", $locale)
->execute() as $row) {
- $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ $translations[$row->key] = unserialize($row->translation);
}
-
+
// Override incoming with outgoing...
foreach (db::build()
->select("key", "translation")
->from("outgoing_translations")
->where("locale", "=", $locale)
->execute() as $row) {
- $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ $translations[$row->key] = unserialize($row->translation);
}
+
+ $cache->set($cache_key, $translations, array("translation"), 0);
}
-
- $key = self::get_message_key($message);
-
- if (isset($this->_cache[$locale][$key])) {
- return $this->_cache[$locale][$key];
- } else {
- return null;
- }
+ return $translations;
}
public function has_translation($message, $options=null) {
@@ -256,6 +266,15 @@ class Gallery_I18n_Core {
return $this->_call_log;
}
+ public static function clear_cache($locale=null) {
+ $cache = Cache::instance();
+ if ($locale) {
+ $cache->delete("translation|" . $locale);
+ } else {
+ $cache->delete_tag("translation");
+ }
+ }
+
private static function get_plural_key($locale, $count) {
$parts = explode('_', $locale);
$language = $parts[0];
diff --git a/modules/gallery/libraries/drivers/Cache/Database.php b/modules/gallery/libraries/drivers/Cache/Database.php
index 82a09ab9..085c5c35 100644
--- a/modules/gallery/libraries/drivers/Cache/Database.php
+++ b/modules/gallery/libraries/drivers/Cache/Database.php
@@ -153,15 +153,17 @@ class Cache_Database_Driver extends Cache_Driver {
* @param bool delete a tag
* @return bool
*/
- public function delete($id, $tag=false) {
+ public function delete($keys, $is_tag=false) {
$db = db::build()
->delete("caches");
- if ($id === true) {
+ if ($keys === true) {
// Delete all caches
- } else if ($tag === true) {
- $db->where("tags", "LIKE", "%<$id>%");
+ } else if ($is_tag === true) {
+ foreach ($keys as $tag) {
+ $db->where("tags", "LIKE", "%<$tag>%");
+ }
} else {
- $db->where("key", "=", $id);
+ $db->where("key", "IN", $keys);
}
$status = $db->execute();