/** * Translates a list of items * @param array $rows * @param JFLanguage $language * @param array $tableArray */ public static function translateListArray(&$rows, $language, $fields, $onlytransFields = true) { if (!isset($rows) || !is_array($rows) || count($rows) == 0) { return $rows; } $jfManager = JoomFishManager::getInstance(); $registry = JFactory::getConfig(); $defaultLang = $registry->getValue("config.defaultlang"); $db = JFactory::getDBO(); $querySQL = (string) $db->getQuery(); // do not try to translate if I have no fields!!! if (!isset($fields) || count($fields) == 0) { return; } $fielddata = JoomFish::getTablesIdsAndFields($fields); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('joomfish'); $dispatcher->trigger('onBeforeTranslationProcess', array(&$rows, $language, &$fielddata, $querySQL, $onlytransFields)); // If I write content in non-default language then this skips the translation! //if($language == $defaultLang) return $rows; $rowsLanguage = $language; if (count($rows) > 0) { foreach ($fielddata as $reftable => $value) { if ($reftable == "allfields") { continue; } $table = $value["orgtable"]; if (!$table || count($value['fields']) == 0) { continue; } // If there is no translated content for this table then skip it! if (!$db->translatedContentAvailable($table)) { continue; } // get the fieldnames to see if we have any translateable fields $fieldnames = array(); foreach ($value['fields'] as $fieldinfo) { if (isset($fieldinfo->orgname) && $fieldinfo->orgname != "") { $fieldnames[] = $fieldinfo->orgname; } } if (!$db->testTranslateableFields($table, $fieldnames)) { continue; } // get primary key for tablename $idkey = $jfManager->getPrimaryKey(trim($reftable)); // find the primary id column number if (!isset($value["idindex"])) { continue; } $keycol = $value["idindex"]; $idlist = array(); // temp variable to make sure all ids in idstring are unique (for neatness more than performance) foreach ($rows as $row) { if (!empty($row[$keycol])) { $idlist[] = $row[$keycol]; } } if (count($idlist) == 0) { continue; } $idstring = implode(",", array_unique($idlist)); if (!$jfManager->getContentElement($table) || $jfManager->getContentElement($table)->getTarget() == "joomfish") { JoomFish::translateListArrayWithIDs($rows, $idstring, $table, $reftable, $language, $keycol, $idkey, $fielddata, $querySQL); } else { JoomFish::nativeTranslateListArrayWithIDs($rows, $idstring, $table, $reftable, $language, $keycol, $idkey, $fielddata, $querySQL, true, $onlytransFields); } } } }