Skip to content
Permalink
Browse files

set default locale from null to 'en'

  • Loading branch information
Aleš
Aleš committed Sep 4, 2019
1 parent 3b2c4dd commit 58bdee33dec75ffda37a8368710f72531f86a294
Showing with 9 additions and 17 deletions.
  1. +1 −5 src/DI/TranslationExtension.php
  2. +8 −11 tests/Tests/DI/TranslationExtension.phpt
  3. +0 −1 tests/Tests/Translator.phpt
@@ -32,7 +32,7 @@ public function getConfigSchema(): Nette\Schema\Schema
'logger' => Expect::mixed()->default(null),
'locales' => Expect::structure([
'whitelist' => Expect::array()->default(null), // @todo unique check?
'default' => Expect::string(null),
'default' => Expect::string('en'),
'fallback' => Expect::array()->default(null),
]),
'localeResolvers' => Expect::array()->default(null),
@@ -102,10 +102,6 @@ public function loadConfiguration(): void
->setFactory($this->config->cache->factory, [$this->config->debug]);
// Translator
if ($this->config->locales->default === null) {
throw new Contributte\Translation\Exceptions\InvalidArgument('Default locale must be set.');
}
if ($this->config->debug && $this->config->debugger) {
$factory = Contributte\Translation\DebuggerTranslator::class;
@@ -26,22 +26,19 @@ class TranslationExtension extends Tests\TestAbstract
$this->createContainer(['cache' => ['factory' => '\\stdClass']]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Cache factory must implement interface "Symfony\\Component\\Config\\ConfigCacheFactoryInterface".');
Tester\Assert::exception(function (): void {
$this->createContainer([]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Default locale must be set.');
Tester\Assert::exception(function (): void {
$this->createContainer(['locales' => ['default' => 'en'], 'loaders' => ['\\stdClass']]);
$this->createContainer(['loaders' => ['\\stdClass']]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Loader must implement interface "Symfony\\Component\\Translation\\Loader\\LoaderInterface".');
Tester\Assert::exception(function (): void {
$this->createContainer(['locales' => ['default' => 'en'], 'dirs' => [__DIR__ . '/__no_exists__']]);
$this->createContainer(['dirs' => [__DIR__ . '/__no_exists__']]);
}, UnexpectedValueException::class);
Tester\Assert::exception(function (): void {
$this->createContainer(['logger' => true, 'locales' => ['default' => 'en'], 'localeResolvers' => []]);
$this->createContainer(['logger' => true, 'localeResolvers' => []]);
}, Nette\DI\MissingServiceException::class, 'Service of type \'Psr\\Log\\LoggerInterface\' not found.');
Tester\Assert::exception(function (): void {
$this->createContainer(['logger' => '\\stdClass', 'locales' => ['default' => 'en'], 'localeResolvers' => []]);
$this->createContainer(['logger' => '\\stdClass', 'localeResolvers' => []]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Logger must implement interface "Psr\\Log\\LoggerInterface".');
Tester\Assert::exception(function (): void {
$this->createContainer(['logger' => 1, 'locales' => ['default' => 'en'], 'localeResolvers' => []]);
$this->createContainer(['logger' => 1, 'localeResolvers' => []]);
}, Contributte\Translation\Exceptions\InvalidArgument::class, 'Option "logger" must be bool for autowired or class name as string.');
}
@@ -63,7 +60,7 @@ class TranslationExtension extends Tests\TestAbstract
}
});
$compiler->addConfig(['parameters' => $this->container->getParameters(), 'translation' => ['locales' => ['default' => 'en'], 'dirs' => [__DIR__ . '__config_dir__']]]);
$compiler->addConfig(['parameters' => $this->container->getParameters(), 'translation' => ['dirs' => [__DIR__ . '__config_dir__']]]);
});
} catch (UnexpectedValueException $e) {
@@ -73,7 +70,7 @@ class TranslationExtension extends Tests\TestAbstract
public function test03(): void
{
$container = $this->createContainer(['debug' => true, 'debugger' => true, 'locales' => ['default' => 'en', 'whitelist' => ['en']], 'localeResolvers' => [], 'dirs' => [__DIR__ . '/../../lang']]);
$container = $this->createContainer(['debug' => true, 'debugger' => true, 'locales' => ['whitelist' => ['en']], 'localeResolvers' => [], 'dirs' => [__DIR__ . '/../../lang']]);
/** @var Contributte\Translation\Tracy\Panel $panel */
$panel = $container->getByType(Contributte\Translation\Tracy\Panel::class);
@@ -99,7 +96,7 @@ class TranslationExtension extends Tests\TestAbstract
public function test04(): void
{
$container = $this->createContainer(['logger' => '\\Tests\\PsrLoggerMock', 'locales' => ['default' => 'en'], 'localeResolvers' => []], Tests\PsrLoggerMock::class);
$container = $this->createContainer(['logger' => '\\Tests\\PsrLoggerMock', 'localeResolvers' => []], Tests\PsrLoggerMock::class);
Tester\Assert::count(1, $container->findByType(Tests\PsrLoggerMock::class));
}
@@ -262,7 +262,6 @@ class Translator extends Tests\TestAbstract
'translation' => [
'debug' => true,
'locales' => [
'default' => 'en',
'whitelist' => ['en'],
],
'localeResolvers' => [

0 comments on commit 58bdee3

Please sign in to comment.
You can’t perform that action at this time.