Skip to content

Commit

Permalink
fallback fix (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleswita authored Oct 22, 2020
1 parent 6fa9df4 commit 943b546
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DI/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getConfigSchema(): Nette\Schema\Schema
return true;
}),
'default' => Expect::string('en'),
'fallback' => Expect::array()->default(['en_US']),
'fallback' => Expect::array()->default(null),
])->assert(function (stdClass $locales): bool {
if ($locales->whitelist !== null && !in_array($locales->default, $locales->whitelist, true)) {
throw new Contributte\Translation\Exceptions\InvalidArgument('If you set whitelist, default locale must be on him.');
Expand All @@ -63,6 +63,10 @@ public function loadConfiguration(): void
{
$builder = $this->getContainerBuilder();

if ($this->config->locales->fallback === null) {
$this->config->locales->fallback = ['en_US'];
}

if ($this->config->localeResolvers === null) {
$this->config->localeResolvers = [
Contributte\Translation\LocalesResolvers\Session::class,
Expand Down
16 changes: 16 additions & 0 deletions tests/Tests/DI/TranslationExtension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ class TranslationExtension extends Tests\TestAbstract
Tester\Assert::count(1, $container->findByType(Tests\PsrLoggerMock::class));
}

public function test05(): void
{
$container = Tests\Helpers::createContainerFromConfigurator($this->container->getParameters()['tempDir'], [
'translation' => [
'locales' => [
'fallback' => ['cs_CZ'],
],
],
]);

/** @var Contributte\Translation\Translator $translator */
$translator = $container->getByType(Nette\Localization\ITranslator::class);

Tester\Assert::same($translator->getFallbackLocales(), ['cs_CZ']);
}

}

(new TranslationExtension($container))->run();

0 comments on commit 943b546

Please sign in to comment.