From 21fa942e24223958ef2bea96537335589d71aa5f Mon Sep 17 00:00:00 2001 From: Gege <dngege@gmail.com> Date: Fri, 5 Jul 2019 11:25:24 +0200 Subject: [PATCH] Fixes #12 - fix multiple package translations bug --- CHANGELOG.md | 12 ++++++++---- src/I18nServiceProvider.php | 10 ++++++++-- tests/I18nTest.php | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bab5762..c0bd750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v0.6.7 (2018-07-05) +### Fixed +- Only one package added to the list of translations [#12](https://github.com/thepinecode/i18n/issues/12) + ## v0.6.6 (2018-06-22) ### Fixed - JS string conversions @@ -10,15 +14,15 @@ ## v0.6.4 (2018-06-13) ### Fixed -- add fallback for invalid translations +- add fallback for invalid translations [#11](https://github.com/thepinecode/i18n/issues/11) ## v0.6.3 (2018-06-07) ### Fixed -- trim whitespaces +- trim whitespaces [#10](https://github.com/thepinecode/i18n/issues/10) ## v0.6.2 (2018-06-03) ### Changed -- revert JS regexp to have better browser support +- revert JS regexp to have better browser support [#8](https://github.com/thepinecode/i18n/issues/8) ## v0.6.1 (2018-06-03) ### Fixed @@ -27,7 +31,7 @@ ## v0.6.0 (2018-06-02) ### Added -- support multilang applications and packages +- support multilang applications and packages [#7](https://github.com/thepinecode/i18n/issues/7) - tests for multilang feature ## v0.5.1 (2018-05-29) diff --git a/src/I18nServiceProvider.php b/src/I18nServiceProvider.php index 84c7ec9..f27e6ad 100644 --- a/src/I18nServiceProvider.php +++ b/src/I18nServiceProvider.php @@ -78,7 +78,9 @@ protected function translations() */ protected function packageTranslations() { - return collect($this->app['translator']->getLoader()->namespaces())->flatMap(function ($dir, $namespace) { + $namespaces = $this->app['translator']->getLoader()->namespaces(); + + return collect($namespaces)->map(function ($dir, $namespace) { return collect(File::directories($dir))->flatMap(function ($dir) use ($namespace) { return [ basename($dir) => collect([ @@ -89,7 +91,11 @@ protected function packageTranslations() })->toArray(), ]), ]; - }); + })->toArray(); + })->reduce(function ($collection, $item) { + return collect(array_merge_recursive($collection->toArray(), $item)); + }, collect())->map(function ($item) { + return collect($item); }); } diff --git a/tests/I18nTest.php b/tests/I18nTest.php index 1996397..3e20269 100644 --- a/tests/I18nTest.php +++ b/tests/I18nTest.php @@ -15,7 +15,7 @@ public function translations_can_be_printed_via_blade_directive() /** @test */ public function translations_can_have_custom_key() { - $this->get('/i18n/custom-key')->assertSee('window.custom = '); + $this->get('/i18n/custom-key')->assertSee("window['custom'] = "); } /** @test */