Index: branches/5.3.x/core/units/phrases/phrases_event_handler.php =================================================================== diff -u -N -r15483 -r15584 --- branches/5.3.x/core/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 15483) +++ branches/5.3.x/core/units/phrases/phrases_event_handler.php (.../phrases_event_handler.php) (revision 15584) @@ -1,6 +1,6 @@ getTranslationFields(); $changed_fields = array_keys( $object->GetChangedFields() ); - $translation_fields = Array ('Translation', 'HintTranslation', 'ColumnTranslation'); foreach ($changed_fields as $changed_field) { $changed_field = preg_replace('/^l[\d]+_/', '', $changed_field); @@ -396,6 +396,42 @@ } /** + * Returns fields, that can be translated + * + * @return Array + * @access protected + */ + protected function getTranslationFields() + { + return Array ('Translation', 'HintTranslation', 'ColumnTranslation'); + } + + /** + * Put correct translation to source language fields + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnAfterItemLoad(kEvent $event) + { + parent::OnAfterItemLoad($event); + + $object = $event->getObject(); + /* @var $object kDBItem */ + + $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + $translation_fields = $this->getTranslationFields(); + $source_language = $ml_helper->getSourceLanguage($object->GetDBField('TranslateFromLanguage')); + + foreach ($translation_fields as $translation_field) { + $object->SetDBField('Source' . $translation_field, $object->GetDBField('l' . $source_language . '_' . $translation_field)); + } + } + + /** * Changes default module to custom (when available) * * @param kEvent $event @@ -406,32 +442,18 @@ { parent::OnAfterConfigRead($event); - if ($this->Application->findModule('Name', 'Custom')) { + if ( $this->Application->findModule('Name', 'Custom') ) { $fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); $fields['Module']['default'] = 'Custom'; $this->Application->setUnitOption($event->Prefix, 'Fields', $fields); } - // make sure, that PrimaryTranslation column always refrers to primary language column - $language_id = $this->Application->GetVar('lang_id'); + $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ - if (!$language_id) { - $language_id = $this->Application->GetVar('m_lang'); - } + $ml_helper->replaceMLCalculatedFields($event); - $primary_language_id = $this->Application->GetDefaultLanguageId(); - $calculated_fields = $this->Application->getUnitOption($event->Prefix, 'CalculatedFields'); - - foreach ($calculated_fields[''] as $field_name => $field_expression) { - $field_expression = str_replace('%5$s', $language_id, $field_expression); - $field_expression = str_replace('%4$s', $primary_language_id, $field_expression); - - $calculated_fields[''][$field_name] = $field_expression; - } - - $this->Application->setUnitOption($event->Prefix, 'CalculatedFields', $calculated_fields); - - if ($this->Application->GetVar('regional')) { + if ( $this->Application->GetVar('regional') ) { $this->Application->setUnitOption($event->Prefix, 'PopulateMlFields', true); } } @@ -517,4 +539,21 @@ ) ); } + + /** + * Updates translation state for all saved phrases + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnBeforeCopyToLive(kEvent $event) + { + parent::OnBeforeCopyToLive($event); + + $ml_helper = $this->Application->recallObject('kMultiLanguageHelper'); + /* @var $ml_helper kMultiLanguageHelper */ + + $ml_helper->updateTranslationState($event); + } } \ No newline at end of file