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,21 +123,19 @@ ...@@ -123,21 +123,19 @@
$options = array('' => 'English (US)'); $options = array('' => 'English (US)');
$directory = @opendir(QA_LANG_DIR); // find all language folders
if (is_resource($directory)) { foreach (glob(QA_LANG_DIR.'*', GLOB_NOSORT) as $directory) {
while (($code = readdir($directory)) !== false) { $code = basename($directory);
if (is_dir(QA_LANG_DIR . $code) && isset($codetolanguage[$code])) $metadatafile = QA_LANG_DIR . $code . '/metadata.php';
$options[$code] = $codetolanguage[$code]; if (is_file($metadatafile)) {
} $metadata = include $metadatafile;
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'])) if (isset($metadata['display_name']))
$options[$code] = $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); asort($options, SORT_STRING);
......
<?php <?php
/* /*
Question2Answer (c) Gideon Greenspan Question2Answer (c) Gideon Greenspan
...@@ -24,11 +23,6 @@ ...@@ -24,11 +23,6 @@
More about this license: http://www.question2answer.org/license.php More about this license: http://www.question2answer.org/license.php
*/ */
return array( return array(
'display_name' => 'English (UK)', 'display_name' => 'English (UK)',
); );
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
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