aerni / statamic-advanced-seo

Comprehensive SEO addon for Statamic with flexibility in mind
https://statamic.com/addons/aerni/advanced-seo
11 stars 6 forks source link

Not possible to translate SEO title for custom routes #111

Closed Web10-Joris closed 10 months ago

Web10-Joris commented 10 months ago

I've tried to translate the seo title and description for a custom route but without success. This is the route.php:

Route::statamic('/custom', 'custom.index', [
            'seo_enabled' => true,
            'seo_title' => __('seo.cart_title'),
            'seo_description' => __('seo.cart_description')]);

And the HTML for this route is outputting: <title> seo.cart_title | SiteName </title>

The correct lang folder and file are set up with translations for the current user locale.

Is this something that I can fix myself or does it need to be inside the addon?

aerni commented 10 months ago

I tried reproducing this issue, but the translation works as expected. Can you create a sample repo that reproduces the issue?

Web10-Joris commented 10 months ago

I've invited you to the private dev repo. Can you try it in here? I've removed the localizable strings for now in the routes.php, but feel free to add and test locally on the /cart page.

aerni commented 10 months ago

I fiddled around with your site a little. The issue is related to the setup of your routes. You have to figure that one out. The issue isn't related to Advanced SEO.

Web10-Joris commented 9 months ago

Hi @aerni, thanks for letting me know and for taking the time to check it. After much debugging I still haven't figured out where the problem lies. Seems that all custom routes do not take Statamic Site locale but keep the default app locale while the content from the view is translated. Any tips are welcome :)

aerni commented 9 months ago

Yeah, so this is probably a Statamic bug. Most likely related to the Localize Middleware. Best to open an issue there.

You can work around it by using a regular Laravel route, that returns a Statamic view and setting the app locale to the locale of the current site.

Site::all()->each(function ($site) {
    Route::get("{$site->url()}/test", function () use ($site) {
        App::setLocale($site->shortLocale());

        return View::make('layout', [
            'seo_enabled' => true,
            'seo_title' => __('seo.title'),
        ]);
    });
});