Commit cbf70b46 by Scott

Optimize language metadata parsing

Use single loop instead of two.
Also use “metadata.php” as the data file.
parent 8f13111b
......@@ -123,20 +123,18 @@
$options = array('' => 'English (US)');
$directory = @opendir(QA_LANG_DIR);
if (is_resource($directory)) {
while (($code = readdir($directory)) !== false) {
if (is_dir(QA_LANG_DIR . $code) && isset($codetolanguage[$code]))
$options[$code] = $codetolanguage[$code];
// find all language folders
foreach (glob(QA_LANG_DIR.'*', GLOB_NOSORT) as $directory) {
$code = basename($directory);
$metadatafile = QA_LANG_DIR . $code . '/metadata.php';
if (is_file($metadatafile)) {
$metadata = include $metadatafile;
if (isset($metadata['display_name']))
$options[$code] = $metadata['display_name'];
}
closedir($directory);
}
foreach (glob(QA_LANG_DIR . '*/qa-lang-metadata.php') as $filename) {
$code = basename(dirname($filename));
$metadata = include QA_LANG_DIR . $code . '/qa-lang-metadata.php';
if (isset($metadata['display_name']))
$options[$code] = $metadata['display_name'];
// otherwise use an entry from above
else if (isset($codetolanguage[$code]))
$options[$code] = $codetolanguage[$code];
}
asort($options, SORT_STRING);
......
<?php
/*
Question2Answer (c) Gideon Greenspan
......@@ -24,11 +23,6 @@
More about this license: http://www.question2answer.org/license.php
*/
return array(
'display_name' => 'English (UK)',
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
return array(
'display_name' => 'English (UK)',
);
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