summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/controllers/l10n_client.php45
-rw-r--r--core/helpers/core_installer.php13
-rw-r--r--core/js/l10n_client.js2
-rw-r--r--core/libraries/I18n.php14
-rw-r--r--core/models/outgoing_translation.php21
-rw-r--r--core/tests/I18n_Test.php1
-rw-r--r--installer/init_var.php6
-rw-r--r--installer/install.sql25
8 files changed, 112 insertions, 15 deletions
diff --git a/core/controllers/l10n_client.php b/core/controllers/l10n_client.php
index fb008ce0..29648ba4 100644
--- a/core/controllers/l10n_client.php
+++ b/core/controllers/l10n_client.php
@@ -21,12 +21,44 @@ class L10n_Client_Controller extends Controller {
public function save($string) {
access::verify_csrf();
+ $input = Input::instance();
+ $message = $input->post("l10n-message-source");
+ $translation = $input->post("l10n-edit-target");
+ $key = I18n::getMessageKey($message);
+ $locale = I18n::instance()->getLocale();
+
+ $entry = ORM::factory("outgoing_translation")
+ ->where(array("key" => $key,
+ "locale" => $locale))
+ ->find();
+
+ if (!$entry->loaded) {
+ $entry->key = $key;
+ $entry->locale = $locale;
+ $entry->message = serialize($message);
+ $entry->base_revision = null;
+ }
+
+ $entry->translation = serialize($translation);
+
+ $entry_from_incoming = ORM::factory("incoming_translation")
+ ->where(array("key" => $key,
+ "locale" => $locale))
+ ->find();
+
+ if (!$entry_from_incoming->loaded) {
+ $entry->base_revision = $entry_from_incoming->revision;
+ }
+
+ $entry->save();
+
print json_encode(new stdClass());
}
private static function _l10n_client_form() {
$form = new Forge("/l10n_client/save", "", "post", array("id" => "gL10nClientSaveForm"));
$group = $form->group("l10n_message");
+ $group->hidden("l10n-message-source")->value("");
$group->textarea("l10n-edit-target");
$group->submit("l10n-edit-save")->value(t("Save translation"));
// TODO(andy_st): Avoiding multiple submit buttons for now (hassle with jQuery form plugin).
@@ -53,16 +85,15 @@ class L10n_Client_Controller extends Controller {
foreach ($calls as $call) {
list ($message, $options) = $call;
if (is_array($message)) {
- // TODO: Translate each message. If it has a plural form, get
- // the current locale's plural rules and all plural translations.
- $options['count'] = 1;
- $source = $message['one'];
- } else {
- $source = $message;
+ // TODO: Handle plural forms.
+ // Translate each message. If it has a plural form, get
+ // the current locale's plural rules and all plural translations.
+ continue;
}
+ $source = $message;
$translation = '';
if (I18n::instance()->hasTranslation($message, $options)) {
- $translation = I18n::instance()->hasTtranslation($message, $options);
+ $translation = I18n::instance()->translate($message, $options);
}
$string_list[] = array('source' => $source,
'translation' => $translation);
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index 24b9e993..7a83ec8f 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -140,6 +140,18 @@ class core_installer {
KEY `locale_key` (`locale`, `key`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ $db->query("CREATE TABLE `outgoing_translations` (
+ `id` int(9) NOT NULL auto_increment,
+ `key` binary(16) NOT NULL,
+ `locale` char(10) NOT NULL,
+ `message` text NOT NULL,
+ `translation` text,
+ `base_revision` int(9) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`key`, `locale`),
+ KEY `locale_key` (`locale`, `key`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+
$db->query("CREATE TABLE `sessions` (
`session_id` varchar(127) NOT NULL,
`last_activity` int(10) UNSIGNED NOT NULL,
@@ -258,6 +270,7 @@ class core_installer {
$db->query("DROP TABLE IF EXISTS `modules`;");
$db->query("DROP TABLE IF EXISTS `themes`;");
$db->query("DROP TABLE IF EXISTS `incoming_translations`;");
+ $db->query("DROP TABLE IF EXISTS `outgoing_translations`;");
$db->query("DROP TABLE IF EXISTS `permissions`;");
$db->query("DROP TABLE IF EXISTS `sessions`;");
$db->query("DROP TABLE IF EXISTS `tasks`;");
diff --git a/core/js/l10n_client.js b/core/js/l10n_client.js
index 7d2ca5e3..f43671f1 100644
--- a/core/js/l10n_client.js
+++ b/core/js/l10n_client.js
@@ -128,6 +128,7 @@ Gallery.behaviors.l10nClient = function(context) {
var index = $('#l10n-client-string-select li').index(this);
$('#l10n-client-string-editor .source-text').text(Gallery.l10nClient.getString(index, 'source'));
+ $("#gL10nClientSaveForm input[name='l10n-message-source']").val(Gallery.l10nClient.getString(index, 'source'));
$('#gL10nClientSaveForm #l10n-edit-target').val(Gallery.l10nClient.getString(index, 'translation'));
Gallery.l10nClient.selected = index;
@@ -173,6 +174,7 @@ Gallery.behaviors.l10nClient = function(context) {
// Empty input fields.
$('#l10n-client-string-editor .source-text').html('');
$('#gL10nClientSaveForm #l10n-edit-target').val('');
+ $("#gL10nClientSaveForm input[name='l10n-message-source']").val('');
},
error: function(xmlhttp) {
// TODO: Localize this message
diff --git a/core/libraries/I18n.php b/core/libraries/I18n.php
index 51bc2a51..19215325 100644
--- a/core/libraries/I18n.php
+++ b/core/libraries/I18n.php
@@ -101,6 +101,10 @@ class I18n_Core {
return $entry;
}
+ public function getLocale() {
+ return $this->_config['default_locale'];
+ }
+
private function lookup($locale, $message) {
if (!isset($this->_cache[$locale])) {
$this->_cache[$locale] = array();
@@ -113,6 +117,16 @@ class I18n_Core {
->as_array() as $row) {
$this->_cache[$locale][$row->key] = unserialize($row->translation);
}
+
+ // Override incoming with outgoing...
+ foreach (Database::instance()
+ ->select("key", "translation")
+ ->from("outgoing_translations")
+ ->where(array("locale" => $locale))
+ ->get()
+ ->as_array() as $row) {
+ $this->_cache[$locale][$row->key] = unserialize($row->translation);
+ }
}
$key = self::getMessageKey($message);
diff --git a/core/models/outgoing_translation.php b/core/models/outgoing_translation.php
new file mode 100644
index 00000000..cd5d3267
--- /dev/null
+++ b/core/models/outgoing_translation.php
@@ -0,0 +1,21 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2008 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Outgoing_Translation_Model extends ORM {
+}
diff --git a/core/tests/I18n_Test.php b/core/tests/I18n_Test.php
index df139f04..65b5e79a 100644
--- a/core/tests/I18n_Test.php
+++ b/core/tests/I18n_Test.php
@@ -42,7 +42,6 @@ class I18n_Test extends Unit_Test_Case {
foreach ($messages_te_ST as $data) {
list ($message, $translation) = $data;
- $key = $message;
$entry = ORM::factory("incoming_translation");
$entry->key = I18n::getMessageKey($message);
$entry->message = serialize($message);
diff --git a/installer/init_var.php b/installer/init_var.php
index 94dd5c67..b0f0d5db 100644
--- a/installer/init_var.php
+++ b/installer/init_var.php
@@ -1,8 +1,8 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<?php
!file_exists(VARPATH . "albums") && mkdir(VARPATH . "albums");
-!file_exists(VARPATH . "resizes") && mkdir(VARPATH . "resizes");
-!file_exists(VARPATH . "thumbs") && mkdir(VARPATH . "thumbs");
-!file_exists(VARPATH . "logs") && mkdir(VARPATH . "logs");
!file_exists(VARPATH . "uploads") && mkdir(VARPATH . "uploads");
!file_exists(VARPATH . "modules") && mkdir(VARPATH . "modules");
+!file_exists(VARPATH . "resizes") && mkdir(VARPATH . "resizes");
+!file_exists(VARPATH . "logs") && mkdir(VARPATH . "logs");
+!file_exists(VARPATH . "thumbs") && mkdir(VARPATH . "thumbs");
diff --git a/installer/install.sql b/installer/install.sql
index 1cbcbb56..ba3773e7 100644
--- a/installer/install.sql
+++ b/installer/install.sql
@@ -143,7 +143,7 @@ CREATE TABLE `items` (
KEY `type` (`type`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO `items` VALUES (NULL,1232411356,'Welcome to your Gallery3',NULL,1,1,1,NULL,NULL,2,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1232411356,0,NULL,1,1);
+INSERT INTO `items` VALUES (NULL,1234166308,'Welcome to your Gallery3',NULL,1,1,1,NULL,NULL,2,0,NULL,NULL,1,2,NULL,NULL,1,'Gallery','album',1234166308,0,NULL,1,1);
DROP TABLE IF EXISTS `items_tags`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
@@ -196,6 +196,21 @@ CREATE TABLE `modules` (
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO `modules` VALUES (1,'core',1),(2,'user',1),(3,'comment',1),(4,'info',1),(5,'media_rss',1),(6,'search',1),(7,'slideshow',1),(8,'tag',1);
+DROP TABLE IF EXISTS `outgoing_translations`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `outgoing_translations` (
+ `id` int(9) NOT NULL auto_increment,
+ `key` binary(16) NOT NULL,
+ `locale` char(10) NOT NULL,
+ `message` text NOT NULL,
+ `translation` text,
+ `base_revision` int(9) default NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `key` (`key`,`locale`),
+ KEY `locale_key` (`locale`,`key`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SET character_set_client = @saved_cs_client;
DROP TABLE IF EXISTS `permissions`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
@@ -283,12 +298,14 @@ CREATE TABLE `users` (
`email` varchar(64) default NULL,
`admin` tinyint(1) default '0',
`guest` tinyint(1) default '0',
+ `hash` char(32) default NULL,
`url` varchar(255) default NULL,
PRIMARY KEY (`id`),
- UNIQUE KEY `name` (`name`)
+ UNIQUE KEY `name` (`name`),
+ UNIQUE KEY `hash` (`hash`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO `users` VALUES (1,'guest','Guest User','QYV8187262d4349b69c82675f8378185a61c',0,0,NULL,0,1,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL);
+INSERT INTO `users` VALUES (1,'guest','Guest User','MGLY6511e6a900d20a0d74e270e059120353',0,0,NULL,0,1,NULL,NULL),(2,'admin','Gallery Administrator','',0,0,NULL,1,0,NULL,NULL);
DROP TABLE IF EXISTS `vars`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
@@ -301,4 +318,4 @@ CREATE TABLE `vars` (
UNIQUE KEY `module_name` (`module_name`,`name`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
-INSERT INTO `vars` VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','graphics_toolkit','imagemagick'),(7,'core','graphics_toolkit_path','/usr/bin'),(8,'core','blocks_dashboard_sidebar','a:4:{i:1876961917;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:924956900;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:8006564;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1576448242;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(9,'core','blocks_dashboard_center','a:4:{i:1489461869;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:2076717831;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:706100302;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1064064430;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(10,'core','version','3.0'),(11,'comment','spam_caught','0');
+INSERT INTO `vars` VALUES (1,'core','active_site_theme','default'),(2,'core','active_admin_theme','admin_default'),(3,'core','page_size','9'),(4,'core','thumb_size','200'),(5,'core','resize_size','640'),(6,'core','graphics_toolkit','imagemagick'),(7,'core','graphics_toolkit_path','/usr/bin'),(8,'core','blocks_dashboard_sidebar','a:4:{i:1010288539;a:2:{i:0;s:4:\"core\";i:1;s:11:\"block_adder\";}i:1869509477;a:2:{i:0;s:4:\"core\";i:1;s:5:\"stats\";}i:695550396;a:2:{i:0;s:4:\"core\";i:1;s:13:\"platform_info\";}i:1828086635;a:2:{i:0;s:4:\"core\";i:1;s:12:\"project_news\";}}'),(9,'core','blocks_dashboard_center','a:4:{i:184470340;a:2:{i:0;s:4:\"core\";i:1;s:7:\"welcome\";}i:111465099;a:2:{i:0;s:4:\"core\";i:1;s:12:\"photo_stream\";}i:1801799843;a:2:{i:0;s:4:\"core\";i:1;s:11:\"log_entries\";}i:1081490389;a:2:{i:0;s:7:\"comment\";i:1;s:15:\"recent_comments\";}}'),(10,'core','version','3.0'),(11,'comment','spam_caught','0');