czim / laravel-localization-route-cache Goto Github PK
View Code? Open in Web Editor NEWTranslated Route Caching Solution for Laravel Localization
License: MIT License
Translated Route Caching Solution for Laravel Localization
License: MIT License
Hi, thank you for your great package!
When I use your package, mcamara language-selector not working. Because, $this->translatedRoutes property in McamaraLaravelLocalization is never init and the functions for language selector does not work anymore. With cache, the app don't use routes.php and don't use LaravelLocalization::transRoute('routes.XXXX'). But it's this function that modifies $this->translatedRoutes property.
I propose a solution for set $this->translatedRoutes after routes are loaded in app. But, that works only when the routes have an alias. The app's routes in the router uses these alias.
//The alias of the route must be equal as the translation key in resources/lang/{locale}/routes.php
Route::get(LaravelLocalization::transRoute('routes.auth/login'), [
'uses' => 'Auth\AuthController@login',
'as' => 'auth/login'
]);
==> auth/login
Moreover, with cache, the app don't use the middleware LaravelLocalizationRoutes. So, routeName property is no longer set. This property is used in getLocalizedURL() for redirect the user on the same page with the correct language.
That is why, LoadsTranslatedCachedRoutes must do that too (set routeName property).
Composer says that this package is abbandoned, can you please clarify this?
You should collaborate with @mcamara and merge this package into mcamara/laravel-localization!
P.S. Really thanks for this package!
Hi,
Not a blocking incompatibility, just to note that the command artisan route:trans:cache
does not accept route implemented as Closure.
$ ./artisan route:trans:cache
Route caches for locales cleared!
In Route.php line 817:
Unable to prepare route [api/user] for serialization. Uses Closure.
Cheers & many thanks for this nice work :-)
Hello!
Non-static method Mcamara\LaravelLocalization\LaravelLocalization::getCurrentLocale() should not be called statically
is thrown when using the library. I think it is a clash with the Facade accessor
I have installed and configured this package, and in general it works great.
But in my app I want to use some dynamic routes, so I can get localized menu items for each locale from the menu table of the database.
When I run the following command:
php artisan route:trans:list nl
... and I try to get the (forced) currentlocale inside the group ...
Route::group(['prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localeSessionRedirect', 'localizationRedirect', 'localeViewPath']], function () {
$locale = LaravelLocalization::getCurrentLocale();
dd($locale);
// get menu items from DB ...
});
I get an unexpected result:
"en"
Is there any way I can get the ForcedLocale inside my Route group?
I have tried to get it from env(ROUTING_LOCALE), but that does not seem to work.
Any advice would be greatly appreciated.
This does not work with Laravel 5.1 due to: "mcamara/laravel-localization": "^1.1"
mcamara/laravel-localization states: 5.0.x/5.1.x 1.0.x
Could you simply change it to:
-"mcamara/laravel-localization": "^1.1"
+"mcamara/laravel-localization": "^1.0"
or does it rely on something in >1.0 ?
As for https://laravel.com/docs/5.5/upgrade, we need to rename fire()
method with handle()
.
Hello!
From version 0.9.6 there is a problem with the route:trans:cache command.
In RouteTranslationsCacheCommand.php line 139:
Call to undefined method Mcamara\LaravelLocalization\LaravelLocalization::getSerializedTranslatedRoutes()
I use
mcamara/laravel-localization v1.3.10
Laravel v5.5.40
So I had to revert back to v0.9.5
Hello,
unfortunatly, i tried the 0.8.1 on a Laravel 5.1 application.
Localized URL (eg ndd.com/en) are now 404.
Hi.
LaravelLocalization redirects to the default locale. Ex: http://localize.local redirects to http://localize.local/en
Steps to reproduce
1 - Created a fresh L5.3 project
2 - Added Mcamara/LaravelLocalization and enabled "en", "es", and "fr" locales in the config file.
3 - Added "LaravelLocalization middlewares to app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'localization' => [
\Mcamara\LaravelLocalization\Middleware\LaravelLocalizationRedirectFilter::class,
\Mcamara\LaravelLocalization\Middleware\LocaleSessionRedirect::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
4 - Created a controller and updated routes/web.php file
Route::group(['middleware' => ['localization'], 'prefix' => LaravelLocalization::setLocale()], function () {
Route::get('/', 'IndexController@index')->name('index');
});
5 - Redirection is working as expected.
http://localize.local redirects to http://localize.local/en
6 - Created translation files
http://localize.local/en outputs Hello
http://localize.local/es outputs Hola
http://localize.local/fr outputs Bonjour
7 - Installed your package
composer require czim/laravel-localization-route-cache
Added the service provider in config/app.php
Mcamara\LaravelLocalization\LaravelLocalizationServiceProvider::class,
Czim\LaravelLocalizationRouteCache\LaravelLocalizationServiceProvider::class,
Added the trait to RouteServiceProvider
class RouteServiceProvider extends ServiceProvider
{
use \Czim\LaravelLocalizationRouteCache\Traits\LoadsTranslatedCachedRoutes;
...
}
Redirection still works
8 - Create the route cache files
php artisan route:trans:cache
Content of bootstrap/cache
-rw-rw-r-- 1 dev dev 596965 Nov 16 15:49 compiled.php
-rwxrwxrwx 1 dev dev 14 Nov 16 15:15 .gitignore*
-rw-rw-r-- 1 dev dev 1587 Nov 16 15:50 routes_en.php
-rw-rw-r-- 1 dev dev 1587 Nov 16 15:50 routes_es.php
-rw-rw-r-- 1 dev dev 1587 Nov 16 15:50 routes_fr.php
-rw-rw-r-- 1 dev dev 1587 Nov 16 15:50 routes.php
-rw-rw-r-- 1 dev dev 9141 Nov 16 15:48 services.php
9 - Redirect stops working
http://localize.local no longer redirects to http://localize.local/en but http://localize.local/en works as expected - ouputs "Hello"
http://localize.local/es and http://localize.local/fr gives an error message
laravel.log:
[2016-11-16 16:02:19] production.WARNING: Routes cached, but no cached routes found for locale 'es'!
[2016-11-16 16:02:19] production.WARNING: Routes cached, but no cached routes found for locale 'fr'!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.