Impedisce l'auto-traduzione del browser e fissa il locale TH/EN esplicito.

Chrome traduceva il tailandese in inglese allo scroll; html translate=no e prop locale sulle route.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Javaxman
2026-07-30 11:39:27 +02:00
parent 04a1892c0d
commit ef343a31b5
5 changed files with 20 additions and 7 deletions

View File

@ -20,11 +20,12 @@ const canonicalUrl = Astro.url.toString();
---
<!doctype html>
<html lang={htmlLang} class="bg-nx-bg">
<html lang={htmlLang} class="bg-nx-bg" translate="no">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content={description} />
<meta name="google" content="notranslate" />
<link rel="canonical" href={canonicalUrl} />
<meta name="theme-color" content="#030712" />
<meta property="og:type" content="website" />
@ -46,7 +47,7 @@ const canonicalUrl = Astro.url.toString();
rel="stylesheet"
/>
</head>
<body class="min-h-screen">
<body class="notranslate min-h-screen">
<slot />
<CookieConsent />
<ChatGateModal />

View File

@ -2,4 +2,4 @@
import Page from '../index.astro';
---
<Page />
<Page locale="en" />

View File

@ -16,10 +16,19 @@ import {
getFaq,
getCta,
} from '../data/home';
import type { SupportedLocale } from '../data/home/navigation';
interface Props {
/** Locale esplicito dalle route /en e /th (evita ambiguità se la page è importata come componente). */
locale?: SupportedLocale;
}
const { locale: localeProp } = Astro.props;
const path = Astro.url.pathname;
const localeMatch = path.match(/^\/(en|th)(\/|$)/);
const currentLocale = (localeMatch?.[1] ?? 'it') as 'it' | 'en' | 'th';
const currentLocale = (localeProp ??
(localeMatch?.[1] as SupportedLocale | undefined) ??
'it') as SupportedLocale;
const navigation = getNavigation(currentLocale);
const siteMeta = getSiteMeta(currentLocale);
const hero = getHero(currentLocale);

View File

@ -2,4 +2,4 @@
import Page from '../index.astro';
---
<Page />
<Page locale="th" />

View File

@ -75,8 +75,11 @@ function measureHeaderAndSync(): void {
}
function bind(): void {
const path = window.location.pathname;
if (path !== '/' && path !== '/index.html') return;
const path = window.location.pathname.replace(/\/$/, '') || '/';
// Home IT (`/`) e home localizzate (`/en`, `/th`).
if (path !== '/' && path !== '/index.html' && path !== '/en' && path !== '/th') {
return;
}
const header = document.querySelector('header');
measureHeaderAndSync();