Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMS pages do not show localeTitle unless the locale prefix is present in the URL #676

Closed
guus-frenken opened this issue May 17, 2022 · 1 comment

Comments

@guus-frenken
Copy link
Contributor

CMS pages do not provide the localized version of the page title when accessing {{ this.page.title }} or $this->page->title unless I have the /[locale]/ prefix in my URL.

My page configs look like this:

....stuff
title = "Title in default locale"
....more stuff

[viewBag]
localeTitle[en] = "Title in alternative locale"

When relying on the locale stored in the session, it always displays the page title in the default locale.

A possible workaround is to override the page title by putting the following code in a component and placing it in your page/layout:

public function onRun()
{
    if ( ! $this->page->page instanceof \Cms\Classes\Page) {
        return;
    }

    $locale = app('translator')->getLocale();

    if ($this->page->localeTitle && array_key_exists($locale, (array)$this->page->localeTitle)) {
        $this->page->title = $this->page->localeTitle[$locale];
    }
}
@guus-frenken guus-frenken changed the title CMS pages do not show localizedTitle unless the locale prefix is present in the URL CMS pages do not show localeTitle unless the locale prefix is present in the URL May 17, 2022
@daftspunk
Copy link
Member

Hey @guus-frenken

I have confirmed this is no longer an issue using the latest codebase versions (OCMS v3 and Translate v2). It was likely fixed as part of the rewrite, along with a bunch of other issues.

The title is rendered with the following and is translated based on the selected site:

<title>October CMS - {{ this.page.title }}</title>

Just ping me here if it is still an issue for you. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants