diff --git a/resources/views/navbar.blade.php b/resources/views/navbar.blade.php new file mode 100644 index 0000000..f3b7f99 --- /dev/null +++ b/resources/views/navbar.blade.php @@ -0,0 +1,9 @@ +
diff --git a/src/Localization.php b/src/Localization.php index 76162ba..0381f19 100644 --- a/src/Localization.php +++ b/src/Localization.php @@ -613,4 +613,16 @@ private function useAcceptLanguageHeader() { return (bool) $this->config()->get('localization.accept-language-header', true); } + + /** + * Get locales navigation bar. + * + * @return string + */ + public function localesNavbar() + { + $supportedLocales = $this->supportedLocales->all(); + + return view('localization::navbar', compact('supportedLocales'))->render(); + } } diff --git a/src/LocalizationServiceProvider.php b/src/LocalizationServiceProvider.php index 10c6310..def2b9a 100644 --- a/src/LocalizationServiceProvider.php +++ b/src/LocalizationServiceProvider.php @@ -46,18 +46,6 @@ public function getBasePath() | Main Functions | ------------------------------------------------------------------------------------------------ */ - /** - * Boot the package. - */ - public function boot() - { - parent::boot(); - - $this->publishes([ - $this->getConfigFile() => config_path("{$this->package}.php"), - ], 'config'); - } - /** * Register the service provider. */ @@ -70,6 +58,17 @@ public function register() $this->registerLocalization(); } + /** + * Boot the package. + */ + public function boot() + { + parent::boot(); + + $this->publishConfig(); + $this->registerViews(); + } + /** * Get the services provided by the provider. * @@ -100,4 +99,31 @@ private function registerLocalization() Facades\Localization::class ); } + + /* ------------------------------------------------------------------------------------------------ + | Resources + | ------------------------------------------------------------------------------------------------ + */ + /** + * Publishes configs. + */ + private function publishConfig() + { + $this->publishes([ + $this->getConfigFile() => config_path("{$this->package}.php"), + ], 'config'); + } + + /** + * Register and published Views. + */ + private function registerViews() + { + $viewsPath = $this->getBasePath() . '/resources/views'; + + $this->loadViewsFrom($viewsPath, $this->package); + $this->publishes([ + $viewsPath => base_path('resources/views/vendor/' . $this->package), + ], 'views'); + } } diff --git a/tests/LocalizationTest.php b/tests/LocalizationTest.php index 062ee0e..6301393 100644 --- a/tests/LocalizationTest.php +++ b/tests/LocalizationTest.php @@ -444,6 +444,18 @@ public function it_can_create_url_from_uri() ); } + /** @test */ + public function it_can_render_locales_navigation_bar() + { + $navbar = localization()->localesNavbar(); + + $this->assertContains('