/** * Load the strings from the language file * * @return bool True on success, false otherwise */ public function loadStringsFromFile() { $filePath = $this->getFilePath(); // Check if the file exists. if (file_exists($filePath)) { $strings = NenoHelper::readLanguageFile($this->getFilePath()); if ($strings !== false) { // Init the string array $this->strings = array(); // Loop through all the strings and index them creating the key foreach ($strings as $key => $string) { $this->strings[$this->extension . '.ini:' . $key] = $string; } return true; } } return false; }
/** * Move the translation to its place in the shadow table * * @return bool */ public function moveTranslationToTarget() { /* @var $db NenoDatabaseDriverMysqlx */ $db = JFactory::getDbo(); $query = $db->getQuery(true); // If the translation comes from database content, let's load it if ($this->contentType == self::DB_STRING) { $query->clear()->select(array('f.field_name', 't.table_name'))->from('`#__neno_content_element_fields` AS f')->innerJoin('`#__neno_content_element_tables` AS t ON f.table_id = t.id')->where('f.id = ' . $this->element->id); $db->setQuery($query); $row = $db->loadRow(); list($fieldName, $tableName) = $row; // Ensure data integrity $this->string = NenoHelperData::ensureDataIntegrity($this->element->id, $this->string, $this->language); $query->clear()->select(array('f.field_name', 'ft.value'))->from('`#__neno_content_element_fields_x_translations` AS ft')->innerJoin('`#__neno_content_element_fields` AS f ON f.id = ft.field_id')->where('ft.translation_id = ' . $this->id); $db->setQuery($query); $whereValues = $db->loadAssocList('field_name'); $shadowTableName = $db->generateShadowTableName($tableName, $this->language); $query->clear()->update($shadowTableName)->set($db->quoteName($fieldName) . ' = ' . $db->quote($this->string)); foreach ($whereValues as $whereField => $where) { $query->where($db->quoteName($whereField) . ' = ' . $db->quote($where['value'])); } $db->setQuery($query); $db->execute(); return true; } else { $query->select(array('REPLACE(lf.filename, lf.language, ' . $db->quote($this->language) . ') AS filename', 'lf.filename as originalFilename', 'ls.constant'))->from('#__neno_content_element_translations AS tr')->innerJoin('#__neno_content_element_language_strings AS ls ON ls.id = tr.content_id')->innerJoin('#__neno_content_element_language_files AS lf ON ls.languagefile_id = lf.id')->where('tr.id = ' . (int) $this->id); $db->setQuery($query); $translationData = $db->loadAssoc(); $existingStrings = array(); if (!empty($translationData)) { $filePath = JPATH_ROOT . "/language/" . $this->language . '/' . $translationData['filename']; if (file_exists($filePath)) { $existingStrings = NenoHelper::readLanguageFile($filePath); } else { $defaultLanguage = NenoSettings::get('source_language'); if (file_exists(JPATH_ROOT . "/language/{$defaultLanguage}/" . $translationData['originalFilename'])) { $existingStrings = NenoHelper::readLanguageFile(JPATH_ROOT . "/language/{$defaultLanguage}/" . $translationData['originalFilename']); } } $existingStrings[$translationData['constant']] = $this->string; NenoHelper::saveIniFile($filePath, $existingStrings); } } return false; }
/** * Load strings from the template overwrite * * @return array */ public function loadStringsFromTemplateOverwrite() { $strings = array(); $template = NenoHelper::getFrontendTemplate(); if (!empty($template)) { $filePath = JPATH_ROOT . '/templates/' . $template . '/language/' . $this->language . '/' . $this->getFileName(); if (file_exists($filePath)) { $strings = NenoHelper::readLanguageFile($filePath); } } return $strings; }