Index: language_import_helper.php =================================================================== --- language_import_helper.php (revision 15158) +++ language_import_helper.php (working copy) @@ -593,6 +593,7 @@ if ($root_node->Children) { $this->_processLanguages($root_node->firstChild); + $this->_processLanguageData($root_node->firstChild); } if ($this->_debugMode) { @@ -723,8 +724,6 @@ } do { - $language_id = false; - $fields_hash = Array ( 'PackName' => $language_node->Attributes['PACKNAME'], 'LocalName' => $language_node->Attributes['PACKNAME'], @@ -748,16 +747,56 @@ do { switch ($sub_node->Name) { case 'PHRASES': + case 'EVENTS': + case 'COUNTRIES': + break; + + case 'REPLACEMENTS': + // added since v2 + $replacements = $sub_node->Data; + + if ($fields_hash['Encoding'] != 'plain') { + $replacements = base64_decode($replacements); + } + + $fields_hash['FilenameReplacements'] = $replacements; + break; + + default: + if ($version == 1) { + $fields_hash[ $field_mapping[$sub_node->Name] ] = $sub_node->Data; + } + break; + } + } while (($sub_node =& $sub_node->NextSibling())); + + $this->_processLanguage($fields_hash); + } while (($language_node =& $language_node->NextSibling())); + } + + /** + * Processes parsed XML + * + * @param kXMLNode $language_node + */ + function _processLanguageData(&$language_node) + { + do { + $encoding = $language_node->Attributes['ENCODING']; + $language_id = $this->_languages[crc32($language_node->Attributes['PACKNAME'])]; + + $sub_node =& $language_node->firstChild; + /* @var $sub_node kXMLNode */ + + do { + switch ($sub_node->Name) { + case 'PHRASES': if ($sub_node->Children) { - if (!$language_id) { - $language_id = $this->_processLanguage($fields_hash); - } - if ($this->_debugMode) { $start_time = getmicrotime(); } - $this->_processPhrases($sub_node->firstChild, $language_id, $fields_hash['Encoding']); + $this->_processPhrases($sub_node->firstChild, $language_id, $encoding); if ($this->_debugMode) { $this->Application->Debugger->appendHTML(__CLASS__ . '::' . '_processPhrases: ' . (getmicrotime() - $start_time)); @@ -767,40 +806,15 @@ case 'EVENTS': if ($sub_node->Children) { - if (!$language_id) { - $language_id = $this->_processLanguage($fields_hash); - } - - $this->_processEvents($sub_node->firstChild, $language_id, $fields_hash['Encoding']); + $this->_processEvents($sub_node->firstChild, $language_id, $encoding); } break; case 'COUNTRIES': if ($sub_node->Children) { - if (!$language_id) { - $language_id = $this->_processLanguage($fields_hash); - } - - $this->_processCountries($sub_node->firstChild, $language_id, $fields_hash['Encoding']); + $this->_processCountries($sub_node->firstChild, $language_id, $encoding); } break; - - case 'REPLACEMENTS': - // added since v2 - $replacements = $sub_node->Data; - - if ($fields_hash['Encoding'] != 'plain') { - $replacements = base64_decode($replacements); - } - - $fields_hash['FilenameReplacements'] = $replacements; - break; - - default: - if ($version == 1) { - $fields_hash[ $field_mapping[$sub_node->Name] ] = $sub_node->Data; - } - break; } } while (($sub_node =& $sub_node->NextSibling())); } while (($language_node =& $language_node->NextSibling())); @@ -844,19 +858,21 @@ $column_translation = base64_decode($column_translation); } - if (array_key_exists($phrase_key, $other_translations)) { - $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation; - $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation; - $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation; + if (!array_key_exists($phrase_key, $other_translations)) { + // ensure translation in every language to make same column count in every insert + $other_translations[$phrase_key] = Array (); + + foreach ($this->_languages as $other_language_id) { + $other_translations[$phrase_key]['l' . $other_language_id . '_Translation'] = ''; + $other_translations[$phrase_key]['l' . $other_language_id . '_HintTranslation'] = ''; + $other_translations[$phrase_key]['l' . $other_language_id . '_ColumnTranslation'] = ''; + } } - else { - $other_translations[$phrase_key] = Array ( - 'l' . $language_id . '_Translation' => $translation, - 'l' . $language_id . '_HintTranslation' => $hint_translation, - 'l' . $language_id . '_ColumnTranslation' => $column_translation, - ); - } + $other_translations[$phrase_key]['l' . $language_id . '_Translation'] = $translation; + $other_translations[$phrase_key]['l' . $language_id . '_HintTranslation'] = $hint_translation; + $other_translations[$phrase_key]['l' . $language_id . '_ColumnTranslation'] = $column_translation; + $fields_hash = array_merge($fields_hash, $other_translations[$phrase_key]); $this->Conn->doInsert($fields_hash, $this->_tables['phrases'], 'REPLACE', false); } @@ -906,17 +922,19 @@ 'MessageType' => $event_node->Attributes['MESSAGETYPE'], ); - if (array_key_exists($event_id, $other_translations)) { - $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject']; - $other_translations[$event_id]['l' . $language_id . '_Body'] = $parsed['Body']; + if (!array_key_exists($event_id, $other_translations)) { + // ensure translation in every language to make same column count in every insert + $other_translations[$event_id] = Array (); + + foreach ($this->_languages as $other_language_id) { + $other_translations[$event_id]['l' . $other_language_id . '_Subject'] = ''; + $other_translations[$event_id]['l' . $other_language_id . '_Body'] = ''; + } } - else { - $other_translations[$event_id] = Array ( - 'l' . $language_id . '_Subject' => $parsed['Subject'], - 'l' . $language_id . '_Body' => $parsed['Body'], - ); - } + $other_translations[$event_id]['l' . $language_id . '_Subject'] = $parsed['Subject']; + $other_translations[$event_id]['l' . $language_id . '_Body'] = $parsed['Body']; + if ($parsed['Headers']) { $other_translations[$event_id]['Headers'] = $parsed['Headers']; } @@ -970,15 +988,17 @@ 'CountryStateId' => $country_state_id, ); - if (array_key_exists($country_state_id, $other_translations)) { - $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation; + if (!array_key_exists($country_state_id, $other_translations)) { + // ensure translation in every language to make same column count in every insert + $other_translations[$country_state_id] = Array (); + + foreach ($this->_languages as $other_language_id) { + $other_translations[$country_state_id]['l' . $other_language_id . '_Name'] = ''; + } } - else { - $other_translations[$country_state_id] = Array ( - 'l' . $language_id . '_Name' => $translation, - ); - } + $other_translations[$country_state_id]['l' . $language_id . '_Name'] = $translation; + $fields_hash = array_merge($fields_hash, $other_translations[$country_state_id]); $this->Conn->doInsert($fields_hash, $this->_tables['country-state'], 'REPLACE', false); @@ -1032,7 +1052,7 @@ // 4. collect ID of every processed language if (!in_array($language_id, $this->_languages)) { - $this->_languages[] = $language_id; + $this->_languages[crc32($fields_hash['PackName'])] = $language_id; } return $language_id;