Skip to content

Commit

Permalink
Merge branch '4.4' into 5.3
Browse files Browse the repository at this point in the history
* 4.4:
  Fix composer.json versions
  Fix composer.json versions
  Remove redundant license info
  [HttpFoundation] Fix isNotModified determination logic
  Fix Url Validator false positives
  [Translation] Reverse fallback locales
  [FrameworkBundle] Fall back to default configuration in debug:config and consistently resolve parameter values
  allow null for framework.translator.default_path
  improve failure messages of the CrawlerSelectorTextContains constraint
  • Loading branch information
nicolas-grekas committed Aug 26, 2021
2 parents fd6bece + db0ba1e commit 6e69f35
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
10 changes: 8 additions & 2 deletions Tests/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,17 @@ public function testTransWithIcuVariantFallbackLocale()
$translator->addResource('array', ['foo' => 'foofoo'], 'en_GB_scouse');
$translator->addResource('array', ['bar' => 'foobar'], 'en_GB');
$translator->addResource('array', ['baz' => 'foobaz'], 'en_001');
$translator->addResource('array', ['qux' => 'fooqux'], 'en');
$translator->addResource('array', ['bar' => 'en', 'qux' => 'fooqux'], 'en');
$translator->addResource('array', ['bar' => 'nl_NL', 'fallback' => 'nl_NL'], 'nl_NL');
$translator->addResource('array', ['bar' => 'nl', 'fallback' => 'nl'], 'nl');

$translator->setFallbackLocales(['nl_NL', 'nl']);

$this->assertSame('foofoo', $translator->trans('foo'));
$this->assertSame('foobar', $translator->trans('bar'));
$this->assertSame('foobaz', $translator->trans('baz'));
$this->assertSame('fooqux', $translator->trans('qux'));
$this->assertSame('nl_NL', $translator->trans('fallback'));
}

public function testTransWithIcuRootFallbackLocale()
Expand Down Expand Up @@ -316,7 +322,7 @@ public function testTransWithFallbackLocaleTer()
$translator = new Translator('fr_FR');
$translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', ['foo' => 'foo (en_US)'], 'en_US');
$translator->addResource('array', ['bar' => 'bar (en)'], 'en');
$translator->addResource('array', ['foo' => 'foo (en)', 'bar' => 'bar (en)'], 'en');

$translator->setFallbackLocales(['en_US', 'en']);

Expand Down
18 changes: 10 additions & 8 deletions Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,8 @@ protected function computeFallbackLocales(string $locale)
$this->parentLocales = json_decode(file_get_contents(__DIR__.'/Resources/data/parents.json'), true);
}

$originLocale = $locale;
$locales = [];
foreach ($this->fallbackLocales as $fallback) {
if ($fallback === $locale) {
continue;
}

$locales[] = $fallback;
}

while ($locale) {
$parent = $this->parentLocales[$locale] ?? null;
Expand All @@ -439,10 +433,18 @@ protected function computeFallbackLocales(string $locale)
}

if (null !== $locale) {
array_unshift($locales, $locale);
$locales[] = $locale;
}
}

foreach ($this->fallbackLocales as $fallback) {
if ($fallback === $originLocale) {
continue;
}

$locales[] = $fallback;
}

return array_unique($locales);
}

Expand Down

0 comments on commit 6e69f35

Please sign in to comment.