diff --git a/framework/core/js/src/common/Application.tsx b/framework/core/js/src/common/Application.tsx index 3dc7b8259..09a13034d 100644 --- a/framework/core/js/src/common/Application.tsx +++ b/framework/core/js/src/common/Application.tsx @@ -9,6 +9,7 @@ import Translator from './Translator'; import Store, { ApiPayload, ApiResponse, ApiResponsePlural, ApiResponseSingle, payloadIsPlural } from './Store'; import Session from './Session'; import extract from './utils/extract'; +import extractText from './utils/extractText'; import Drawer from './utils/Drawer'; import mapRoutes from './utils/mapRoutes'; import RequestError, { InternalFlarumRequestOptions } from './utils/RequestError'; @@ -365,9 +366,21 @@ export default class Application { updateTitle(): void { const count = this.titleCount ? `(${this.titleCount}) ` : ''; - const pageTitleWithSeparator = this.title && m.route.get() !== this.forum.attribute('basePath') + '/' ? this.title + ' - ' : ''; - const title = this.forum.attribute('title'); - document.title = count + pageTitleWithSeparator + title; + const onHomepage = m.route.get() === this.forum.attribute('basePath') + '/'; + + const params = { + pageTitle: this.title, + forumName: this.forum.attribute('title'), + // Until we add page numbers to the frontend, this is constant at 1 + // so that the page number portion doesn't show up in the URL. + pageNumber: 1, + }; + + const title = + onHomepage || !this.title + ? extractText(app.translator.trans('core.lib.meta_titles.without_page_title', params)) + : extractText(app.translator.trans('core.lib.meta_titles.with_page_title', params)); + document.title = count + title; } protected transformRequestOptions(flarumOptions: FlarumRequestOptions): InternalFlarumRequestOptions { diff --git a/framework/core/locale/core.yml b/framework/core/locale/core.yml index 7c4812140..b0e0b055e 100644 --- a/framework/core/locale/core.yml +++ b/framework/core/locale/core.yml @@ -542,6 +542,11 @@ core: loading_indicator: accessible_label: => core.ref.loading + # Translations in this namespace are used to format page meta titles. + meta_titles: + with_page_title: "{pageNumber, plural, =1 {{pageTitle} - {forumName}} other {{pageTitle}: Page # - {forumName}}}" + without_page_title: "{pageNumber, plural, =1 {{forumName}} other {Page # - {forumName}}}" + # These translations are used in modals. modal: close: Close @@ -628,11 +633,6 @@ core: submit_button: => core.ref.save_changes title: => core.ref.reset_your_password - # Translations in this namespace are used to format page meta titles. - meta_titles: - with_page_title: "{pageNumber, plural, =1 {{pageTitle} - {forumName}} other {{pageTitle}: Page # - {forumName}}}" - without_page_title: "{pageNumber, plural, =1 {{forumName}} other {Page # - {forumName}}}" - # Translations in this namespace are used in messages output by the API. api: invalid_username_message: "The username may only contain letters, numbers, and dashes." diff --git a/framework/core/src/Frontend/Driver/BasicTitleDriver.php b/framework/core/src/Frontend/Driver/BasicTitleDriver.php index b87272149..36929602e 100644 --- a/framework/core/src/Frontend/Driver/BasicTitleDriver.php +++ b/framework/core/src/Frontend/Driver/BasicTitleDriver.php @@ -37,7 +37,7 @@ class BasicTitleDriver implements TitleDriverInterface ]; return $onHomePage || ! $document->title - ? $this->translator->trans('core.views.meta_titles.without_page_title', $params) - : $this->translator->trans('core.views.meta_titles.with_page_title', $params); + ? $this->translator->trans('core.lib.meta_titles.without_page_title', $params) + : $this->translator->trans('core.lib.meta_titles.with_page_title', $params); } }