diff --git a/README.md b/README.md index e18da61..0bf76ae 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,8 @@ class Kernel extends HttpKernel { /**** OTHER MIDDLEWARE ****/ 'localize' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRoutes::class, 'localizationRedirect' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class, - 'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class + 'localeSessionRedirect' => \Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class, + 'localeViewPath' => \Mcamara\LaravelLocalization\Middleware\LaravelLocalizationViewPath::class // REDIRECTION MIDDLEWARE ]; } @@ -131,7 +132,7 @@ class Kernel extends HttpKernel { Route::group( [ 'prefix' => LaravelLocalization::setLocale(), - 'middleware' => [ 'localeSessionRedirect', 'localizationRedirect' ] + 'middleware' => [ 'localeSessionRedirect', 'localizationRedirect', 'localeViewPath' ] ], function() { @@ -156,6 +157,15 @@ If you want to hide the default locale but always show other locales in the url, **IMPORTANT** - When `hideDefaultLocaleInURL` is set to true, the unlocalized root is treated as the applications default locale `app.locale`. Because of this language negotiation using the Accept-Language header will **NEVER** occur when `hideDefaultLocaleInURL` is true. +### Set current locale as view-base-path + +To set the current locale as view-base-path, simply register the localeViewPath-middlware in your Kernel.php, like it is descriped above. + +Now you can wrap your views in language-based folders like the translation files. + +`resources/views/en/`, `resources/vies/fr`, ... + + ## Helpers This package comes with some useful functions, like: diff --git a/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationViewPath.php b/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationViewPath.php new file mode 100644 index 0000000..f51a035 --- /dev/null +++ b/src/Mcamara/LaravelLocalization/Middleware/LaravelLocalizationViewPath.php @@ -0,0 +1,37 @@ +shouldIgnore($request)) { + return $next($request); + } + + $app = app(); + + $currentLocale = app('laravellocalization')->getCurrentLocale(); + $viewPath = resource_path('views/' . $currentLocale); + + // Add current locale-code to view-paths + View::addLocation($viewPath); + + return $next($request); + } + +}