Fix runtime default locale resolution
CI / quality (push) Waiting to run

This commit is contained in:
MOH
2026-03-15 06:02:27 +01:00
parent 9b8409a7d3
commit c18128c965
29 changed files with 330 additions and 108 deletions
+6 -6
View File
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import { routing } from "../i18n/routing";
import { appLocales } from "../i18n/routing";
import {
PAGE_TITLE_TOKEN,
SITE_NAME_TOKEN,
@@ -22,9 +22,9 @@ function toAbsoluteUrl(pathname: string): string {
return new URL(pathname, getSiteUrl()).toString();
}
export function buildLocaleAlternates(pathname: string, defaultLocale = routing.defaultLocale) {
export function buildLocaleAlternates(pathname: string, defaultLocale: AppLocale) {
const languages = Object.fromEntries(
routing.locales.map((locale) => [locale, toAbsoluteUrl(getLocalizedPathWithDefault(locale, pathname, defaultLocale))]),
appLocales.map((locale) => [locale, toAbsoluteUrl(getLocalizedPathWithDefault(locale, pathname, defaultLocale))]),
) as Record<AppLocale, string>;
return {
@@ -120,8 +120,8 @@ export async function buildLocalizedMetadata({
description,
applyTitleTemplate,
}: LocalizedMetadataInput): Promise<Metadata> {
const localeKey = resolveLocale(locale);
const [settings, bindings] = await Promise.all([getSiteSettings(), getSiteSettingsMediaBindings()]);
const localeKey = resolveLocale(locale, settings.defaultLocale);
return buildLocalizedMetadataFromConfig({
settings,
@@ -152,7 +152,7 @@ export function buildLocalizedMetadataFromConfig(input: {
description,
applyTitleTemplate = true,
} = input;
const localeKey = resolveLocale(locale);
const localeKey = resolveLocale(locale, settings.defaultLocale);
const localeSettings = settings.locales[localeKey];
const resolvedDescription = description?.trim() || localeSettings.siteDescription;
const resolvedTitle = applyTitleTemplate
@@ -167,7 +167,7 @@ export function buildLocalizedMetadataFromConfig(input: {
openGraph: {
title: resolvedTitle,
description: resolvedDescription,
url: toAbsoluteUrl(getLocalizedPath(localeKey, pathname)),
url: toAbsoluteUrl(getLocalizedPath(localeKey, pathname, settings.defaultLocale)),
siteName: localeSettings.siteName,
locale: localeKey,
type: "website",