diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/l10n_client.php | 45 | ||||
-rw-r--r-- | core/helpers/core_installer.php | 13 | ||||
-rw-r--r-- | core/js/l10n_client.js | 2 | ||||
-rw-r--r-- | core/libraries/I18n.php | 14 | ||||
-rw-r--r-- | core/models/outgoing_translation.php | 21 | ||||
-rw-r--r-- | core/tests/I18n_Test.php | 1 |
6 files changed, 88 insertions, 8 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); |