Giter Site home page Giter Site logo

laravel-localization-route-cache's People

Contributors

czim avatar kkomelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-localization-route-cache's Issues

Feature: Add language selector support

Hi, thank you for your great package!

Description

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.

Solution

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).

not compatible with route as Closure

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 :-)

Error while implementing

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

Use ForcedLocale in routes file

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.

Support for Laravel 5.1

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 ?

Problem with route:trans:cache command

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

Laravel 5.1 not working

Hello,
unfortunatly, i tried the 0.8.1 on a Laravel 5.1 application.
Localized URL (eg ndd.com/en) are now 404.

LaravelLocalization stops redirecting after route cache files creation

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'!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.