/**
* Searches for language directories within a certain base dir.
*
* @param string $dir directory of files.
*
* @return array Array holding the found languages as filename => real name pairs.
*
* @since 3.7.0
*/
public static function parseLanguageFiles($dir = null)
{
$languages = array();
// Search main language directory for subdirectories
foreach (glob($dir . '/*', GLOB_NOSORT | GLOB_ONLYDIR) as $directory) {
// But only directories with lang code format
if (preg_match('#/[a-z]{2,3}-[A-Z]{2}$#', $directory)) {
$dirPathParts = pathinfo($directory);
$file = $directory . '/langmetadata.xml';
if (!is_file($file)) {
$file = $directory . '/' . $dirPathParts['filename'] . '.xml';
}
if (!is_file($file)) {
continue;
}
try {
// Get installed language metadata from xml file and merge it with lang array
if ($metadata = self::parseXMLLanguageFile($file)) {
$languages = array_replace($languages, array($dirPathParts['filename'] => $metadata));
}
} catch (\RuntimeException $e) {
// Ignore it
}
}
}
return $languages;
}