i18n: kill spurious translate popup; make language pulldown actually translate
Three connected fixes:
1) Stop the unwanted "translate this page to Portuguese?" popup that
some US users were seeing. Chrome's content-language detector was
mis-firing on imported BB articles that mention Portuguese/Spanish
company/person names. Add to layout <head>:
<meta name="google" content="notranslate" />
<meta http-equiv="Content-Language" content="en" />
<meta name="robots" content="index, follow" />
Together with the existing <html lang="en"> this is the standard
"this site is English, don't offer to translate" signal.
2) Wire the LanguageSwitcher pulldown to actually do something. It used
to set a cookie + flip <html lang> with no effect on visible
content. Now picking a non-English language redirects the current
URL to Google Translate's hosted proxy (e.g.
https://broadcastbeat-com.translate.goog/<path>?_x_tr_sl=en
&_x_tr_tl=es&_x_tr_hl=en
), which renders the entire page translated server-side by Google
and preserves the user's session as they navigate. English stays
on the canonical broadcastbeat.com host.
3) SEO posture: English is the only indexable version. The Google
Translate proxy lives on a different (Google-owned) domain so US
browsers and Googlebot only ever see the English content. The
alternates.languages hreflang block stays absent — re-add only once
real translated routes exist (Phase D).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -76,6 +76,17 @@ export default function RootLayout({
|
|||||||
<head>
|
<head>
|
||||||
{/* hreflang entries removed pending real i18n routes (Phase D). */}
|
{/* hreflang entries removed pending real i18n routes (Phase D). */}
|
||||||
|
|
||||||
|
{/* Tell browsers + Google not to auto-offer translation. The site IS
|
||||||
|
English (lang="en"); the language pulldown opt-in uses Google
|
||||||
|
Translate's hosted proxy (*.translate.goog) so users who want
|
||||||
|
another language get one without polluting the canonical URL.
|
||||||
|
Without these, Chrome's content-language detector sometimes
|
||||||
|
fires on imported posts that contain Portuguese/Spanish company
|
||||||
|
or person names and offers a translate popup unprompted. */}
|
||||||
|
<meta name="google" content="notranslate" />
|
||||||
|
<meta httpEquiv="Content-Language" content="en" />
|
||||||
|
<meta name="robots" content="index, follow" />
|
||||||
|
|
||||||
<script
|
<script
|
||||||
type="application/ld+json"
|
type="application/ld+json"
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export default function LanguageSwitcher({ currentLang, onLanguageChange, compac
|
|||||||
setLangCookie(lang);
|
setLangCookie(lang);
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
|
|
||||||
// Apply RTL for Arabic
|
// Apply RTL for Arabic + update <html lang>
|
||||||
const langData = SUPPORTED_LANGUAGES.find(l => l.code === lang);
|
const langData = SUPPORTED_LANGUAGES.find(l => l.code === lang);
|
||||||
if (typeof document !== 'undefined') {
|
if (typeof document !== 'undefined') {
|
||||||
const html = document.documentElement;
|
const html = document.documentElement;
|
||||||
@@ -93,6 +93,16 @@ export default function LanguageSwitcher({ currentLang, onLanguageChange, compac
|
|||||||
}
|
}
|
||||||
|
|
||||||
onLanguageChange?.(lang);
|
onLanguageChange?.(lang);
|
||||||
|
|
||||||
|
// Non-English: route the current page through Google Translate's hosted
|
||||||
|
// proxy so the user actually sees translated content. English is the
|
||||||
|
// canonical/indexable version and just stays put.
|
||||||
|
if (lang !== 'en' && typeof window !== 'undefined') {
|
||||||
|
const host = window.location.hostname.replace(/\./g, '-');
|
||||||
|
const path = window.location.pathname + window.location.search;
|
||||||
|
const proxied = `https://${host}.translate.goog${path}?_x_tr_sl=en&_x_tr_tl=${lang}&_x_tr_hl=en`;
|
||||||
|
window.location.href = proxied;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentLangData = SUPPORTED_LANGUAGES.find(l => l.code === activeLang) || SUPPORTED_LANGUAGES[0];
|
const currentLangData = SUPPORTED_LANGUAGES.find(l => l.code === activeLang) || SUPPORTED_LANGUAGES[0];
|
||||||
|
|||||||
Reference in New Issue
Block a user