composer update
This commit is contained in:
+25
-27
@@ -190,9 +190,10 @@ class Translator extends Translation\Translator
|
||||
}
|
||||
|
||||
foreach ($this->getDirectories() as $directory) {
|
||||
$directory = rtrim($directory, '\\/');
|
||||
if (file_exists($filename = "$directory/$locale.php")) {
|
||||
$this->messages[$locale] = require $filename;
|
||||
$data = @include sprintf('%s/%s.php', rtrim($directory, '\\/'), $locale);
|
||||
|
||||
if ($data !== false) {
|
||||
$this->messages[$locale] = $data;
|
||||
$this->addResource('array', $this->messages[$locale], $locale);
|
||||
|
||||
return true;
|
||||
@@ -339,33 +340,11 @@ class Translator extends Translation\Translator
|
||||
$completeLocaleChunks = preg_split('/[_.-]+/', $completeLocale);
|
||||
|
||||
$getScore = function ($language) use ($completeLocaleChunks) {
|
||||
$chunks = preg_split('/[_.-]+/', $language);
|
||||
$score = 0;
|
||||
|
||||
foreach ($completeLocaleChunks as $index => $chunk) {
|
||||
if (!isset($chunks[$index])) {
|
||||
$score++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strtolower($chunks[$index]) === strtolower($chunk)) {
|
||||
$score += 10;
|
||||
}
|
||||
}
|
||||
|
||||
return $score;
|
||||
return static::compareChunkLists($completeLocaleChunks, preg_split('/[_.-]+/', $language));
|
||||
};
|
||||
|
||||
usort($locales, function ($first, $second) use ($getScore) {
|
||||
$first = $getScore($first);
|
||||
$second = $getScore($second);
|
||||
|
||||
if ($first === $second) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $first < $second ? 1 : -1;
|
||||
return $getScore($second) <=> $getScore($first);
|
||||
});
|
||||
|
||||
$locale = $locales[0];
|
||||
@@ -402,4 +381,23 @@ class Translator extends Translation\Translator
|
||||
'locale' => $this->getLocale(),
|
||||
];
|
||||
}
|
||||
|
||||
private static function compareChunkLists($referenceChunks, $chunks)
|
||||
{
|
||||
$score = 0;
|
||||
|
||||
foreach ($referenceChunks as $index => $chunk) {
|
||||
if (!isset($chunks[$index])) {
|
||||
$score++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strtolower($chunks[$index]) === strtolower($chunk)) {
|
||||
$score += 10;
|
||||
}
|
||||
}
|
||||
|
||||
return $score;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user