/** * Loads the translations of this multilingual section. * * @param bool $untranslatedFirst Set to true to have untranslated strings first * * @return \Gettext\Translations */ public function getSectionInterfaceTranslations($untranslatedFirst = false) { $translations = new Translations(); $translations->setLanguage($this->getLocale()); $translations->setPluralForms($this->getNumberOfPluralForms(), $this->getPluralsRule()); $db = \Database::get(); $r = $db->query("select *\n from MultilingualTranslations\n where mtSectionID = ?\n order by " . ($untranslatedFirst ? "if(ifnull(msgstr, '') = '', 0, 1), " : "") . "mtID", [$this->getCollectionID()]); while ($row = $r->fetch()) { $t = Translation::getByRow($row); if (isset($t)) { $translations[] = $t; } } return $translations; }
public function save_translation() { $result = new EditResponse(); try { $token = $this->app->make('token'); if (!$token->validate('translate/save')) { throw new \Exception(t('Invalid token, please refresh and try again.')); } $translation = null; $mtID = @intval($this->post('id')); if ($mtID > 0) { $translation = Translation::getByRecordID($mtID); } if (!isset($translation)) { throw new \Exception(t('Invalid parameter received: %s', 'id')); } $singular = ''; $plurals = array(); if ($this->post('clear') !== '1') { $translated = $this->post('translated'); if (!is_array($translated) || count($translated) < 1) { throw new \Exception(t('Invalid parameter received: %s', 'translated')); } if ($translation->hasPlural()) { $singular = array_shift($translated); $plurals = $translated; } else { if (count($translated) !== 1) { throw new \Exception(t('Invalid parameter received: %s', 'translated')); } $singular = $translated[0]; } } $translation->updateTranslation($singular, $plurals); } catch (\Exception $x) { $result->setError($x); } $result->outputJSON(); }