-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: custom translator not receiving updated locale (#919)
- Loading branch information
1 parent
fea226d
commit a19ddcc
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Mcamara\LaravelLocalization\Tests; | ||
|
||
use Illuminate\Translation\ArrayLoader; | ||
use Illuminate\Translation\Translator; | ||
use Mcamara\LaravelLocalization\LaravelLocalization; | ||
|
||
class CustomTranslatorTest extends TestCase | ||
{ | ||
// The LaravelLocalization class supports the use of a custom translator instance. | ||
// When the setLocale() method is invoked, it delegates the operation to the application instance, | ||
// which, in turn, updates the locale on the translator instance bound in the service container. | ||
// If a custom translator is provided, LaravelLocalization ensures that the locale is also set correctly | ||
// on the custom translator to maintain consistent behavior across the application. | ||
public function testCanSetLocaleForCustomTranslator(): void | ||
{ | ||
$loader = new ArrayLoader(); | ||
$translator = new Translator($loader , 'en'); | ||
$localization = new LaravelLocalization( | ||
$this->app, | ||
$this->app['config'], | ||
$translator, | ||
$this->app['router'], | ||
$this->app['request'], | ||
$this->app['url'] | ||
); | ||
|
||
$localization->setLocale('es'); | ||
|
||
$this->assertEquals('es', $translator->getLocale()); | ||
} | ||
} |