diff --git a/scripts/docs-i18n/localized_links.go b/scripts/docs-i18n/localized_links.go index 76037009dcd..d7845c4451a 100644 --- a/scripts/docs-i18n/localized_links.go +++ b/scripts/docs-i18n/localized_links.go @@ -136,6 +136,9 @@ func discoverLocalePrefixes(docsRoot string) (map[string]struct{}, error) { if !localeDirRe.MatchString(name) { continue } + if _, err := os.Stat(filepath.Join(docsRoot, name, ".i18n", "README.md")); err != nil { + continue + } locales[name] = struct{}{} } return locales, nil diff --git a/scripts/docs-i18n/relocalize_test.go b/scripts/docs-i18n/relocalize_test.go index 7c0fd821120..be78e49ce53 100644 --- a/scripts/docs-i18n/relocalize_test.go +++ b/scripts/docs-i18n/relocalize_test.go @@ -112,6 +112,47 @@ func TestPostprocessLocalizedDocsRewritesPublishedPageLinksForEachLocale(t *test } } +func TestPostprocessLocalizedDocsDoesNotTreatThreeLetterSourceDirsAsLocales(t *testing.T) { + t.Parallel() + + docsRoot := t.TempDir() + writeFile(t, filepath.Join(docsRoot, "docs.json"), `{"redirects":[]}`) + writeFile(t, filepath.Join(docsRoot, "cli", "index.md"), "# CLI\n") + writeFile(t, filepath.Join(docsRoot, "cli", "AGENTS.md"), "# CLI docs guide\n") + writeFile(t, filepath.Join(docsRoot, "web", "index.md"), "# Web\n") + writeFile(t, filepath.Join(docsRoot, "zh-CN", "AGENTS.md"), "# zh-CN\n") + writeFile(t, filepath.Join(docsRoot, "zh-CN", ".i18n", "README.md"), "# zh-CN i18n\n") + writeFile(t, filepath.Join(docsRoot, "zh-CN", "cli", "index.md"), "# CLI 本地化\n") + writeFile(t, filepath.Join(docsRoot, "zh-CN", "web", "index.md"), "# Web 本地化\n") + + pagePath := filepath.Join(docsRoot, "zh-CN", "gateway", "index.md") + writeFile(t, pagePath, stringsJoin( + "---", + "title: 网关", + "x-i18n:", + " source_hash: test", + "---", + "", + "See [CLI](/cli).", + "", + "See [Web](/web).", + )) + + if err := postprocessLocalizedDocs(docsRoot, "zh-CN", []string{pagePath}); err != nil { + t.Fatalf("postprocessLocalizedDocs failed: %v", err) + } + + got := mustReadFile(t, pagePath) + for _, want := range []string{ + "See [CLI](/zh-CN/cli).", + "See [Web](/zh-CN/web).", + } { + if !containsLine(got, want) { + t.Fatalf("expected rewritten link %q in output:\n%s", want, got) + } + } +} + func TestPostprocessLocalizedDocsOnlyTouchesScopedFiles(t *testing.T) { t.Parallel()