Skip to content

Commit 5bd8254

Browse files
committed
fix(docs): keep source dirs in i18n route index
1 parent 3ccaa1b commit 5bd8254

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

scripts/docs-i18n/localized_links.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ func discoverLocalePrefixes(docsRoot string) (map[string]struct{}, error) {
136136
if !localeDirRe.MatchString(name) {
137137
continue
138138
}
139+
if _, err := os.Stat(filepath.Join(docsRoot, name, ".i18n", "README.md")); err != nil {
140+
continue
141+
}
139142
locales[name] = struct{}{}
140143
}
141144
return locales, nil

scripts/docs-i18n/relocalize_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,47 @@ func TestPostprocessLocalizedDocsRewritesPublishedPageLinksForEachLocale(t *test
112112
}
113113
}
114114

115+
func TestPostprocessLocalizedDocsDoesNotTreatThreeLetterSourceDirsAsLocales(t *testing.T) {
116+
t.Parallel()
117+
118+
docsRoot := t.TempDir()
119+
writeFile(t, filepath.Join(docsRoot, "docs.json"), `{"redirects":[]}`)
120+
writeFile(t, filepath.Join(docsRoot, "cli", "index.md"), "# CLI\n")
121+
writeFile(t, filepath.Join(docsRoot, "cli", "AGENTS.md"), "# CLI docs guide\n")
122+
writeFile(t, filepath.Join(docsRoot, "web", "index.md"), "# Web\n")
123+
writeFile(t, filepath.Join(docsRoot, "zh-CN", "AGENTS.md"), "# zh-CN\n")
124+
writeFile(t, filepath.Join(docsRoot, "zh-CN", ".i18n", "README.md"), "# zh-CN i18n\n")
125+
writeFile(t, filepath.Join(docsRoot, "zh-CN", "cli", "index.md"), "# CLI 本地化\n")
126+
writeFile(t, filepath.Join(docsRoot, "zh-CN", "web", "index.md"), "# Web 本地化\n")
127+
128+
pagePath := filepath.Join(docsRoot, "zh-CN", "gateway", "index.md")
129+
writeFile(t, pagePath, stringsJoin(
130+
"---",
131+
"title: 网关",
132+
"x-i18n:",
133+
" source_hash: test",
134+
"---",
135+
"",
136+
"See [CLI](/cli).",
137+
"",
138+
"See [Web](/web).",
139+
))
140+
141+
if err := postprocessLocalizedDocs(docsRoot, "zh-CN", []string{pagePath}); err != nil {
142+
t.Fatalf("postprocessLocalizedDocs failed: %v", err)
143+
}
144+
145+
got := mustReadFile(t, pagePath)
146+
for _, want := range []string{
147+
"See [CLI](/zh-CN/cli).",
148+
"See [Web](/zh-CN/web).",
149+
} {
150+
if !containsLine(got, want) {
151+
t.Fatalf("expected rewritten link %q in output:\n%s", want, got)
152+
}
153+
}
154+
}
155+
115156
func TestPostprocessLocalizedDocsOnlyTouchesScopedFiles(t *testing.T) {
116157
t.Parallel()
117158

0 commit comments

Comments
 (0)