vsch / laravel-translation-manager

Enhanced Management of Laravel 4 & 5 Translations, with Yandex Translation API assisted translations.
MIT License
181 stars 84 forks source link

Undefined variable: package #19

Open jvanremoortere opened 8 years ago

jvanremoortere commented 8 years ago

When following all the instalation steps, without changing the route prefix in the laravel-translation-manager config file, I get an error "NotFoundHttpException in RouteCollection.php in line XXX".

Therefor I tried adding the route manually to my routes.php file

Route::get('translations', ['as' => 'translations', function(){
    return view('vendor.laravel-translation-manager.index');
}]);

But now I get the following error "Undefined variable: package"... Line 7

vsch commented 8 years ago

@goeroe, you cannot set the route that way. The route is set in ManagerServiceProvider::boot method https://github.com/vsch/laravel-translation-manager/blob/master/src/ManagerServiceProvider.php#L106-L113

I can see only two reasons for this:

  1. config is not published, I am assuming that you do have config/laravel-translation-manager.php in your project which is created with defaults when you publish the config.
  2. The service is not added in config\app.php. Are you sure that the Service has been added to the config\app.php?

The other option is to set a break point on line 106 above and see what values you get and if that part of the code is executed.

jvanremoortere commented 8 years ago

Thanks for the quick reply.

Everything is done properly but it seems the problem lies in the handle function of another package ( Marwelln/laravel-multiple-locales ) that handles the multiple locales.

vsch commented 8 years ago

Is there a way to enable/disable it for certain routes? At least to leave the route for translation manager web interface alone. You can modify the handle function of the middleware to check if the route starts with the translation manager web interface route and then skip to the next handler without any changes.

jvanremoortere commented 8 years ago

That's what I did right now...

// Check if the first url segment is the route for translation
if($request->segment(1) != $this->app->config->get('laravel-translation-manager.route.prefix')) {
     // Do the stuff from the Language middleware
} else {
     // Just set the standard locale
}

Now it works but for some strange reason "translations" gets seen as a locale/language... schermafdruk 2015-11-08 20 13 56

vsch commented 8 years ago

The language middleware uses the first part of the path to select the current locale for the application. make sure that it does not happen, or in the translation manager define 'show_locales' array to include only the locales you want to show and leave out 'translations' locale.

The middleware seems to be a very minimal implementation. There should be more control on what routes are affected.