Index: branches/5.1.x/core/kernel/languages/phrases_cache.php =================================================================== diff -u -r12657 -r13086 --- branches/5.1.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 12657) +++ branches/5.1.x/core/kernel/languages/phrases_cache.php (.../phrases_cache.php) (revision 13086) @@ -1,6 +1,6 @@ Conn =& $this->Application->GetADODBConnection(); - if (defined('DEBUG_MODE') && DEBUG_MODE && $this->Application->IsAdmin()) { + if (defined('DEBUG_MODE') && DEBUG_MODE && $this->Application->isAdmin) { // only has effect in admin, because on front-end phrases are translated in "Content Mode" $this->_editMissing = defined('DBG_PHRASES') && DBG_PHRASES; } @@ -94,7 +101,7 @@ */ function setPhraseEditing() { - if (!$this->Application->IsAdmin() && (EDITING_MODE == EDITING_MODE_CONTENT)) { + if (!$this->Application->isAdmin && (EDITING_MODE == EDITING_MODE_CONTENT)) { $this->_editExisting = true; $this->_editMissing = true; $this->_simpleEditingMode = true; @@ -108,16 +115,18 @@ $this->LanguageId = 1; } else { - if ($this->Application->IsAdmin()) { - $id_field = $this->Application->getUnitOption('lang', 'IDField'); - $table_name = $this->Application->getUnitOption('lang', 'TableName'); - $sql = 'SELECT '.$id_field.' - FROM '.$table_name.' - WHERE AdminInterfaceLang = 1'; - $this->LanguageId = $this->Conn->GetOne($sql); + if ($this->Application->isAdmin) { + $this->LanguageId = $this->Application->Session->GetField('Language'); } else { $this->LanguageId = $this->Application->GetVar('m_lang'); + + if ($this->Application->GetVar('admin')) { + $admin_session =& $this->Application->recallObject('Session.admin'); + /* @var $admin_session Session */ + + $this->AdminLanguageId = $admin_session->GetField('Language'); + } } } @@ -149,10 +158,10 @@ return; } - $sql = 'SELECT Translation, UPPER(Phrase) AS Phrase + $sql = 'SELECT Translation, PhraseKey FROM ' . TABLE_PREFIX . 'Phrase WHERE (LanguageId = ' . $this->LanguageId . ') AND PhraseId IN (' . implode(',', $ids) . ')'; - $this->Phrases = $this->Conn->GetCol($sql, 'Phrase'); + $this->Phrases = $this->Conn->GetCol($sql, 'PhraseKey'); /*foreach($phrases as $phrase => $tanslation) { @@ -199,7 +208,7 @@ } } - function GetPhrase($label, $allow_editing = true) + function GetPhrase($label, $allow_editing = true, $use_admin = false) { if (!isset($this->LanguageId)) { //actually possible when custom field contains references to language labels and its being rebuilt in OnAfterConfigRead @@ -235,17 +244,25 @@ return $translated_label; } - $this->LoadPhraseByLabel($label, $original_label, $allow_editing); + $this->LoadPhraseByLabel($label, $original_label, $allow_editing, $use_admin); return $this->GetPhrase($label, $allow_editing); } - function LoadPhraseByLabel($label, $original_label, $allow_editing = true) + function LoadPhraseByLabel($label, $original_label, $allow_editing = true, $use_admin = false) { - // bug: MySQL don't use index on Phrase column, when function is used on it's value (e.g. UPPER, like in this case) + if (!$allow_editing && !$use_admin && !array_key_exists($label, $this->_missingPhrases) && array_key_exists($label, $this->Phrases)) { + // label is aready translated, but it's version without on the fly translation code is requested + $this->Phrases['NE:' . $label] = $this->Phrases[$label]; + + return true; + } + + $language_id = $use_admin ? $this->AdminLanguageId : $this->LanguageId; + $sql = 'SELECT PhraseId, Translation FROM ' . TABLE_PREFIX . 'Phrase - WHERE (LanguageId = ' . $this->LanguageId . ') AND (PhraseKey = ' . $this->Conn->qstr($label) . ')'; + WHERE (LanguageId = ' . $language_id . ') AND (PhraseKey = ' . $this->Conn->qstr($label) . ')'; $res = $this->Conn->GetRow($sql); if ($res === false || count($res) == 0) {