Index: branches/5.2.x/core/kernel/languages/phrases_cache.php =================================================================== diff -u -N -r14244 -r14585 --- branches/5.2.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 14244) +++ branches/5.2.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 14585) @@ -1,6 +1,6 @@ _editExisting = true; $this->_editMissing = true; - $this->_simpleEditingMode = true; + $this->_simpleEditingMode = !$this->Application->isDebugMode(); $this->_translateHtmlTag = 'span'; } @@ -113,6 +113,7 @@ 'm_opener' => 'd', 'phrases_label' => '#LABEL#', 'phrases_event' => 'OnPreparePhrase', + 'next_template' => urlencode('external:' . $_SERVER['REQUEST_URI']), 'pass' => 'm,phrases' ); @@ -167,10 +168,10 @@ return ; } - $sql = 'SELECT l' . $this->LanguageId . '_Translation, PhraseKey + $sql = 'SELECT l' . $this->LanguageId . '_Translation AS Translation, l' . $this->LanguageId . '_HintTranslation AS HintTranslation, l' . $this->LanguageId . '_ColumnTranslation AS ColumnTranslation, PhraseKey FROM ' . TABLE_PREFIX . 'Phrase WHERE PhraseId IN (' . implode(',', $ids) . ') AND l' . $this->LanguageId . '_Translation IS NOT NULL'; - $this->Phrases = $this->Conn->GetCol($sql, 'PhraseKey'); + $this->Phrases = $this->Conn->Query($sql, 'PhraseKey'); $this->Ids = $this->OriginalIds = $ids; } @@ -180,7 +181,7 @@ // uppercase phrase name for cases, when this method is called outside this class $cache_key = ($allow_editing ? '' : 'NE:') . mb_strtoupper($label); - $this->Phrases[$cache_key] = $value; + $this->Phrases[$cache_key] = Array ('Translation' => $value, 'HintTranslation' => $value, 'ColumnTranslation' => $value); } function NeedsCacheUpdate() @@ -190,7 +191,7 @@ function GetPhrase($label, $allow_editing = true, $use_admin = false) { - if (!isset($this->LanguageId)) { + if ( !isset($this->LanguageId) ) { //actually possible when custom field contains references to language labels and its being rebuilt in OnAfterConfigRead //which is triggered by Sections rebuild, which in turn read all the configs and all of that happens BEFORE seeting the language... return 'impossible case'; @@ -199,21 +200,31 @@ // cut exclamation marks - depricated form of passing phrase name from templates $label = preg_replace('/^!(.*)!$/', '\\1', $label); - if (strlen($label) == 0) { + if ( strlen($label) == 0 ) { return ''; } $original_label = $this->_escapePhraseName ? addslashes($label) : $label; $label = mb_strtoupper($label); + if ( substr($label, 0, 5) == 'HINT:' || substr($label, 0, 7) == 'COLUMN:' ) { + // don't just check for ":" since phrases could have ":" in their names (e.g. advanced permission labels) + list ($field_prefix, $label) = explode(':', $label, 2); + $translation_field = mb_convert_case($field_prefix, MB_CASE_TITLE) . 'Translation'; + } + else { + $translation_field = 'Translation'; + } + $cache_key = ($allow_editing ? '' : 'NE:') . $label; - if (array_key_exists($cache_key, $this->Phrases)) { - $translated_label = $this->Phrases[$cache_key]; + if ( isset($this->Phrases[$cache_key]) ) { + $translated_label = $this->Phrases[$cache_key][$translation_field]; if ($this->_editExisting && $allow_editing && !array_key_exists($label, $this->_missingPhrases)) { // option to change translation for Labels - $edit_url = 'javascript:translate_phrase(\'' . $original_label . '\', \'' . $this->_phraseEditTemplate . '\', {event: \'OnPreparePhrase\', simple_mode: ' . ($this->_simpleEditingMode ? 'true' : 'false') . '});'; + $original_label = explode(':', $original_label, 2); + $edit_url = 'javascript:translate_phrase(\'' . end($original_label) . '\', \'' . $this->_phraseEditTemplate . '\', {event: \'OnPreparePhrase\', simple_mode: ' . ($this->_simpleEditingMode ? 'true' : 'false') . '});'; $translated_label = '<' . $this->_translateHtmlTag . ' href="' . $edit_url . '" name="cms-translate-phrase" title="Edit translation">' . $translated_label . '_translateHtmlTag . '>'; if ($this->fromTag) { @@ -226,12 +237,12 @@ $this->LoadPhraseByLabel($label, $original_label, $allow_editing, $use_admin); - return $this->GetPhrase($label, $allow_editing); + return $this->GetPhrase($original_label, $allow_editing); } function LoadPhraseByLabel($label, $original_label, $allow_editing = true, $use_admin = false) { - if (!$allow_editing && !$use_admin && !array_key_exists($label, $this->_missingPhrases) && array_key_exists($label, $this->Phrases)) { + if ( !$allow_editing && !$use_admin && !isset($this->_missingPhrases[$label]) && isset($this->Phrases[$label]) ) { // label is aready translated, but it's version without on the fly translation code is requested $this->Phrases['NE:' . $label] = $this->Phrases[$label]; @@ -240,7 +251,7 @@ $language_id = $use_admin ? $this->AdminLanguageId : $this->LanguageId; - $sql = 'SELECT PhraseId, l' . $language_id . '_Translation + $sql = 'SELECT PhraseId, l' . $language_id . '_Translation AS Translation, l' . $language_id . '_HintTranslation AS HintTranslation, l' . $language_id . '_ColumnTranslation AS ColumnTranslation FROM ' . TABLE_PREFIX . 'Phrase WHERE (PhraseKey = ' . $this->Conn->qstr($label) . ') AND (l' . $language_id . '_Translation IS NOT NULL)'; $res = $this->Conn->GetRow($sql); @@ -249,7 +260,8 @@ $translation = '!' . $label . '!'; if ($this->_editMissing && $allow_editing) { - $edit_url = str_replace('#LABEL#', $original_label, $this->_editLinkMask); + $original_label = explode(':', $original_label, 2); + $edit_url = str_replace('#LABEL#', end($original_label), $this->_editLinkMask); $translation = '<' . $this->_translateHtmlTag . ' href="' . $edit_url . '" name="cms-translate-phrase" title="Translate">!' . $label . '!_translateHtmlTag . '>'; if ($this->fromTag) { @@ -266,7 +278,7 @@ } $cache_key = ($allow_editing ? '' : 'NE:') . $label; - $this->Phrases[$cache_key] = $res['l' . $language_id . '_Translation']; + $this->Phrases[$cache_key] = $res; array_push($this->Ids, $res['PhraseId']); $this->Ids = array_unique($this->Ids); // just to make sure