public function save() { access::verify_csrf(); if (!identity::active_user()->admin) { access::forbidden(); } $locale = I18n::instance()->locale(); $input = Input::instance(); $key = $input->post("l10n-message-key"); $root_message = ORM::factory("incoming_translation")->where(array("key" => $key, "locale" => "root"))->find(); if (!$root_message->loaded) { throw new Exception("@todo bad request data / illegal state"); } $is_plural = I18n::is_plural_message(unserialize($root_message->message)); if ($is_plural) { $plural_forms = l10n_client::plural_forms($locale); $translation = array(); foreach ($plural_forms as $plural_form) { $value = $input->post("l10n-edit-plural-translation-{$plural_form}"); if (null === $value || !is_string($value)) { throw new Exception("@todo bad request data"); } $translation[$plural_form] = $value; } } else { $translation = $input->post("l10n-edit-translation"); if (null === $translation || !is_string($translation)) { throw new Exception("@todo bad request data"); } } $entry = ORM::factory("outgoing_translation")->where(array("key" => $key, "locale" => $locale))->find(); if (!$entry->loaded) { $entry->key = $key; $entry->locale = $locale; $entry->message = $root_message->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()); }