Skip to content

Commit

Permalink
Merge pull request #194 from Laravel-Lang/11.x
Browse files Browse the repository at this point in the history
Fixed `lang:add` always implicitly includes `en`
  • Loading branch information
Andrey Helldar authored Dec 14, 2021
2 parents f3e0ca7 + 49bbd43 commit 5af8c8e
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Processors/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ protected function collectSource(Provider $provider, string $source, string $tar
}

$this->setResourceKeys($target, $this->getKeysOnly($content));
$this->setResource(Locales::ENGLISH, $target, $content);

if ($this->hasEnglish()) {
$this->setResource(Locales::ENGLISH, $target, $content);
}
}

protected function collectLocales(Provider $provider, string $source, string $target): void
Expand Down Expand Up @@ -92,4 +95,9 @@ protected function resolveKeys(array $array): array
return is_numeric($key) && is_string($value) ? $value : $key;
})->get();
}

protected function hasEnglish(): bool
{
return in_array(Locales::ENGLISH, $this->locales);
}
}
41 changes: 41 additions & 0 deletions tests/InlineOff/Console/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,45 @@ public function testInstall()
$this->assertSame('This is Baz', __('All rights reserved.'));
$this->assertSame('Confirm Password', __('Confirm Password'));
}

public function testOverwrite()
{
$this->copyFixtures();

$this->assertSame('Foo Failed', __('auth.failed'));
$this->assertSame('Foo Throttle', __('auth.throttle'));
$this->assertSame('Das eingegebene Passwort ist nicht korrekt.', __('auth.password'));

$this->assertSame('Foo Auth', __('auth.foo'));
$this->assertSame('Bar Auth', __('auth.bar'));
$this->assertSame('Baz Auth', __('auth.baz'));

$this->assertSame('This is Foo', __('Foo'));
$this->assertSame('This is Bar', __('Bar'));
$this->assertSame('This is Baz', __('Baz'));

$this->assertSame('This is Baz', __('All rights reserved.'));
$this->assertSame('This is Baq', __('Confirm Password'));

$this->artisan('lang:add', [
'locales' => $this->locale,
])->run();

$this->refreshLocales();

$this->assertSame('Foo Failed', __('auth.failed'));
$this->assertSame('Foo Throttle', __('auth.throttle'));
$this->assertSame('Das eingegebene Passwort ist nicht korrekt.', __('auth.password'));

$this->assertSame('Foo Auth', __('auth.foo'));
$this->assertSame('Bar Auth', __('auth.bar'));
$this->assertSame('Baz Auth', __('auth.baz'));

$this->assertSame('This is Foo', __('Foo'));
$this->assertSame('This is Bar', __('Bar'));
$this->assertSame('This is Baz', __('Baz'));

$this->assertSame('This is Baz', __('All rights reserved.'));
$this->assertSame('This is Baq', __('Confirm Password'));
}
}
41 changes: 41 additions & 0 deletions tests/InlineOn/Console/AddTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,45 @@ public function testInstall()
$this->assertSame('This is Baz', __('All rights reserved.'));
$this->assertSame('Confirm Password', __('Confirm Password'));
}

public function testOverwrite()
{
$this->copyFixtures();

$this->assertSame('Foo Failed', __('auth.failed'));
$this->assertSame('Foo Throttle', __('auth.throttle'));
$this->assertSame('Das eingegebene Passwort ist nicht korrekt.', __('auth.password'));

$this->assertSame('Foo Auth', __('auth.foo'));
$this->assertSame('Bar Auth', __('auth.bar'));
$this->assertSame('Baz Auth', __('auth.baz'));

$this->assertSame('This is Foo', __('Foo'));
$this->assertSame('This is Bar', __('Bar'));
$this->assertSame('This is Baz', __('Baz'));

$this->assertSame('This is Baz', __('All rights reserved.'));
$this->assertSame('This is Baq', __('Confirm Password'));

$this->artisan('lang:add', [
'locales' => $this->locale,
])->run();

$this->refreshLocales();

$this->assertSame('Foo Failed', __('auth.failed'));
$this->assertSame('Foo Throttle', __('auth.throttle'));
$this->assertSame('Das eingegebene Passwort ist nicht korrekt.', __('auth.password'));

$this->assertSame('Foo Auth', __('auth.foo'));
$this->assertSame('Bar Auth', __('auth.bar'));
$this->assertSame('Baz Auth', __('auth.baz'));

$this->assertSame('This is Foo', __('Foo'));
$this->assertSame('This is Bar', __('Bar'));
$this->assertSame('This is Baz', __('Baz'));

$this->assertSame('This is Baz', __('All rights reserved.'));
$this->assertSame('This is Baq', __('Confirm Password'));
}
}
4 changes: 4 additions & 0 deletions tests/fixtures/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
return [
'failed' => 'Foo Failed',
'throttle' => 'Foo Throttle',

'foo' => 'Foo Auth',
'bar' => 'Bar Auth',
'baz' => 'Baz Auth',
];

0 comments on commit 5af8c8e

Please sign in to comment.