/** * Create element from row. * * @param array $row * * @return TranslateModel */ public function populateElementModel($row) { return TranslateModel::populateModel($row); }
/** * Open file and parse translate tags. * * @param string $path * @param string $file * @param ElementCriteriaModel $criteria * * @return array */ protected function _parseFile($path, $file, ElementCriteriaModel $criteria) { // Collect matches in file $occurences = array(); // Get file contents $contents = IOHelper::getFileContents($file); // Get extension $extension = IOHelper::getExtension($file); // Get matches per extension foreach ($this->_expressions[$extension] as $regex) { // Match translation functions if (preg_match_all($regex, $contents, $matches)) { // Collect foreach ($matches[2] as $original) { // Translate $translation = Craft::t($original, array(), null, $criteria->locale); // Show translation in textfield $field = craft()->templates->render('_includes/forms/text', array('id' => ElementHelper::createSlug($original), 'name' => 'translation[' . $original . ']', 'value' => $translation, 'placeholder' => $translation)); // Fill element with translation data $element = TranslateModel::populateModel(array('id' => ElementHelper::createSlug($original), 'original' => $original, 'translation' => $translation, 'source' => $path, 'file' => $file, 'locale' => $criteria->locale, 'field' => $field)); // If searching, only return matches if ($criteria->search && !stristr($element->original, $criteria->search) && !stristr($element->translation, $criteria->search)) { continue; } // If wanting one status, ditch the rest if ($criteria->status && $criteria->status != $element->getStatus()) { continue; } // Collect in array $occurences[$original] = $element; } } } // Return occurences return $occurences; }