From 1d3c7d7441db707dd40ebc7b9a3418f5df6b1da4 Mon Sep 17 00:00:00 2001 From: dttgc Date: Wed, 2 Dec 2026 14:27:18 +0900 Subject: [PATCH] fix(download): fall back to English for outdated snippets --- apps/site/components/DownloadSection.tsx | 30 ++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/apps/site/components/DownloadSection.tsx b/apps/site/components/DownloadSection.tsx index b6fe875fecb30..eb27a4a5d83d4 100644 --- a/apps/site/components/DownloadSection.tsx +++ b/apps/site/components/DownloadSection.tsx @@ -16,6 +16,20 @@ type DownloadSectionProps = PropsWithChildren<{ releases: Array; }>; +// Ignore translatable comments and blank lines when comparing snippet commands. +const normalizeSnippetCommands = (content: string) => + content + .split(/\r?\n/) + .filter(line => line.trim() && !line.trimStart().startsWith('#')) + .map(line => + line + // Keep the opening backtick when removing a template's first comment. + .replace(/^([ \t]*`)#[^`\\]*$/, '$1') + // Ignore inline comments after Node.js and npm version checks. + .replace(/^([ \t]*(?:node|npm) -v)[ \t]+#.*$/, '$1') + ) + .join('\n'); + const DownloadSection: FC = async ({ releases, children, @@ -32,11 +46,23 @@ const DownloadSection: FC = async ({ const { pathname } = getClientContext(); + // Exclude outdated translations so the merge can use their English snippets. + const currentLocaleSnippets = localeSnippets.filter(snippet => { + const fallback = fallbackSnippets.find(s => s.name === snippet.name); + return ( + !fallback || + normalizeSnippetCommands(snippet.content) === + normalizeSnippetCommands(fallback.content) + ); + }); + // Some available translations do not have download snippets translated or have them partially translated // This aims to merge the available translated snippets with the fallback snippets const memoizedSnippets = fallbackSnippets - .filter(snippet => !localeSnippets.some(s => s.name === snippet.name)) - .concat(localeSnippets); + .filter( + snippet => !currentLocaleSnippets.some(s => s.name === snippet.name) + ) + .concat(currentLocaleSnippets); // Decides which initial release to use based on the current pathname const initialRelease: Array = pathname.endsWith('/alpha')