Util\Translator: fix language list

Reverted former redundant patch, got confused by legacy web modules
been translated with earlier versions. They had a different directory
structure and registered erraneous domain directories.

This patch fixes the list, does an additional safety check (dirname must
end with .UTF-8) and strips .UTF-8 from the locale name. Former regex
matched always and therefore blacklisted every translation.
This commit is contained in:
Thomas Gelf 2014-06-25 11:43:15 +02:00
parent 20cdb6e0b8
commit fac3c9f3a6

View File

@ -131,16 +131,17 @@ class Translator
public static function getAvailableLocaleCodes() public static function getAvailableLocaleCodes()
{ {
$codes = array(); $codes = array();
$postfix = '.UTF-8';
foreach (array_values(self::$knownDomains) as $directory) { foreach (array_values(self::$knownDomains) as $directory) {
$dh = opendir($directory); $dh = opendir($directory);
while (false !== ($name = readdir($dh))) { while (false !== ($name = readdir($dh))) {
if (!preg_match('@\.|\.\.@', $name) && is_dir($directory . DIRECTORY_SEPARATOR . $name)) { if (substr($name, 0, 1) === '.') continue;
$codes[] = $name; if (substr($name, -6) !== $postfix) continue;
if (is_dir($directory . DIRECTORY_SEPARATOR . $name)) {
$codes[] = substr($name, 0, -6);
} }
} }
} }
return $codes; return $codes;
} }
} }