zerospam / laravel-gettext

Adds localization support to laravel applications using PoEdit and GNU-Gettext.
99 stars 56 forks source link

Translation doesn't work on error page #5

Closed saschametz95 closed 6 years ago

saschametz95 commented 6 years ago

Hi there, I just tested the plugin and it works great. But there seems to be a problem with error pages. The text is translated on every page except the 404 page.

Belphemur commented 6 years ago

Hello,

Can you check if the middleware is loaded also for your Error Page ?

On 2017-11-05 05:53, Sascha wrote:

Hi there, I just tested the plugin and it works great. But there seems to be a problem with error pages. The text is translated on every page except the 404 page.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Belphemur/laravel-gettext/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMEshe6vcWrWSpzxXRQuLrh9iyQ18Stks5szZOngaJpZM4QSVZS.

saschametz95 commented 6 years ago

Hi Belphemur, thanks for the hint. The problem was that the the middleware is only loaded when a route is matched. If a NotFoundException is thrown the middlewares won't run. I got it running by adding a fallback route so the middleware loads on the error page.

Route::fallback(function () {
    return view('errors.404');
});

I don't think it's the best solution because i only want this for a 404 error. Maybe i will find something better or someone else has a better solution.

Belphemur commented 6 years ago

One of the way (a little dirty to be honest) would be to run the code of the middleware directly in your view before rendering your strings.

It's only one method that is called to gather from the session the required language.

On 2017-11-07 17:59, Sascha wrote:

Hi Belphemur, thanks for the hint. The problem was that the the middleware is only loaded when a route is matched. If a NotFoundException is thrown the middlewares won't run. I got it running by adding a fallback route so the middleware loads on the error page.

|Route::fallback(function () { return view('errors.404'); }); |

I don't think if it's the best solution because i only want this for the 404 error page. Maybe i will find something better or someone else has a better solution.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Belphemur/laravel-gettext/issues/5#issuecomment-342652462, or mute the thread https://github.com/notifications/unsubscribe-auth/AAMEslHMym7MajAS522MjN2qHpwUeh8Bks5s0ODMgaJpZM4QSVZS.