Commit 02833d53 by Scott

Optimize qa_lang

Store phrases in one variable, return as soon as possible. This results in extra includes in some circumstances but overall it's still faster.
parent 448ddb4a
......@@ -1191,53 +1191,43 @@
{
if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); }
global $qa_lang_file_pattern, $qa_phrases_custom, $qa_phrases_lang, $qa_phrases_default;
global $qa_lang_file_pattern, $qa_phrases_full;
list($group, $label)=explode('/', $identifier, 2);
list($group, $label) = explode('/', $identifier, 2);
// First look for a custom phrase in qa-lang/custom/
if (isset($qa_phrases_full[$group][$label]))
return $qa_phrases_full[$group][$label];
if (!isset($qa_phrases_custom[$group])) { // only load each language file once
$phrases=@include QA_LANG_DIR.'custom/qa-lang-'.$group.'.php'; // can tolerate missing file or directory
$qa_phrases_custom[$group]=is_array($phrases) ? $phrases : array();
}
if (isset($qa_phrases_custom[$group][$label]))
return $qa_phrases_custom[$group][$label];
// Second look for a localized file in qa-lang/<lang>/
if (!isset($qa_phrases_full[$group])) {
// load the default language files
if (isset($qa_lang_file_pattern[$group]))
$include = str_replace('*', 'default', $qa_lang_file_pattern[$group]);
else
$include = QA_INCLUDE_DIR.'lang/qa-lang-'.$group.'.php';
$languagecode=qa_opt('site_language');
$qa_phrases_full[$group] = is_file($include) ? (array)(include_once $include) : array();
if (strlen($languagecode)) {
if (!isset($qa_phrases_lang[$group])) {
// look for a localized file in qa-lang/<lang>/
$languagecode = qa_opt('site_language');
if (strlen($languagecode)) {
if (isset($qa_lang_file_pattern[$group]))
$include=str_replace('*', $languagecode, $qa_lang_file_pattern[$group]);
$include = str_replace('*', $languagecode, $qa_lang_file_pattern[$group]);
else
$include=QA_LANG_DIR.$languagecode.'/qa-lang-'.$group.'.php';
$include = QA_LANG_DIR.$languagecode.'/qa-lang-'.$group.'.php';
$phrases=@include $include;
$qa_phrases_lang[$group]=is_array($phrases) ? $phrases : array();
$phrases = is_file($include) ? (array)(include $include) : array();
$qa_phrases_full[$group] = array_merge($qa_phrases_full[$group], $phrases);
}
if (isset($qa_phrases_lang[$group][$label]))
return $qa_phrases_lang[$group][$label];
}
// add any custom phrases from qa-lang/custom/
$include = QA_LANG_DIR.'custom/qa-lang-'.$group.'.php';
$phrases = is_file($include) ? (array)(include $include) : array();
$qa_phrases_full[$group] = array_merge($qa_phrases_full[$group], $phrases);
// Finally load the default language files
if (!isset($qa_phrases_default[$group])) { // only load each default language file once
if (isset($qa_lang_file_pattern[$group]))
$include=str_replace('*', 'default', $qa_lang_file_pattern[$group]);
else
$include=QA_INCLUDE_DIR.'lang/qa-lang-'.$group.'.php';
$qa_phrases_default[$group]=@include_once $include;
if (isset($qa_phrases_full[$group][$label]))
return $qa_phrases_full[$group][$label];
}
if (isset($qa_phrases_default[$group][$label]))
return $qa_phrases_default[$group][$label];
return '['.$identifier.']'; // as a last resort, return the identifier to help in development
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment