diff --git a/packages/cli/cli/changes/unreleased/fix-default-locale-manifest-key.yml b/packages/cli/cli/changes/unreleased/fix-default-locale-manifest-key.yml new file mode 100644 index 000000000000..183bc908d7d4 --- /dev/null +++ b/packages/cli/cli/changes/unreleased/fix-default-locale-manifest-key.yml @@ -0,0 +1,5 @@ +# yaml-language-server: $schema=../../../../../fern-changes-yml.schema.json + +- summary: | + Publish the configured default locale as the docs manifest locale key instead of always using "en". + type: fix diff --git a/packages/cli/generation/remote-generation/remote-workspace-runner/src/__test__/buildLedgerInput.test.ts b/packages/cli/generation/remote-generation/remote-workspace-runner/src/__test__/buildLedgerInput.test.ts index f552714f21aa..44609f8e9247 100644 --- a/packages/cli/generation/remote-generation/remote-workspace-runner/src/__test__/buildLedgerInput.test.ts +++ b/packages/cli/generation/remote-generation/remote-workspace-runner/src/__test__/buildLedgerInput.test.ts @@ -23,15 +23,17 @@ const MINIMAL_ROOT = { function makeDocsDefinition({ pages = {}, - root = MINIMAL_ROOT + root = MINIMAL_ROOT, + translations }: { pages?: Record; root?: unknown; + translations?: { defaultLocale: string; translations?: string[] }; } = {}) { // Minimal DocsDefinition shape — only the fields buildLedgerInput reads. return { pages, - config: { root } + config: { root, ...(translations != null ? { translations } : {}) } } as Parameters[0]["docsDefinition"]; } @@ -222,6 +224,52 @@ describe("buildLedgerInput", () => { expect(localeEntry.locale).toBe("en"); }); + it("keys the base segment by the configured default locale", () => { + const { localeEntry } = buildLedgerInput({ + docsDefinition: makeDocsDefinition({ + translations: { defaultLocale: "en-US", translations: ["en-US", "pt-BR", "ja-JP"] } + }), + apiDefinitions: new Map() + }); + + // publishInput.defaultLocale is derived from this value, so the + // manifest's defaultLocale and its base locales[] key stay in sync + // with the tag readers look up from docs.yml. + expect(localeEntry.locale).toBe("en-US"); + }); + + it("preserves a non-English default locale", () => { + const { localeEntry } = buildLedgerInput({ + docsDefinition: makeDocsDefinition({ + translations: { defaultLocale: "de-DE", translations: ["de-DE", "en"] } + }), + apiDefinitions: new Map() + }); + + expect(localeEntry.locale).toBe("de-DE"); + }); + + it("keeps an explicitly passed translation locale, including regional tags", () => { + const { localeEntry } = buildLedgerInput({ + docsDefinition: makeDocsDefinition({ + translations: { defaultLocale: "en-US", translations: ["en-US", "pt-BR"] } + }), + apiDefinitions: new Map(), + locale: "pt-BR" + }); + + expect(localeEntry.locale).toBe("pt-BR"); + }); + + it("keys the base segment by en when the site declares no translations", () => { + const { localeEntry } = buildLedgerInput({ + docsDefinition: makeDocsDefinition({ pages: { "page-1": { markdown: "# Hi" } } }), + apiDefinitions: new Map() + }); + + expect(localeEntry.locale).toBe("en"); + }); + it("uses config.root for the root field", () => { const { localeEntry } = buildLedgerInput({ docsDefinition: makeDocsDefinition({ root: MINIMAL_ROOT }), diff --git a/packages/cli/generation/remote-generation/remote-workspace-runner/src/publishDocsLedger.ts b/packages/cli/generation/remote-generation/remote-workspace-runner/src/publishDocsLedger.ts index cc645df66b59..588d8880bd82 100644 --- a/packages/cli/generation/remote-generation/remote-workspace-runner/src/publishDocsLedger.ts +++ b/packages/cli/generation/remote-generation/remote-workspace-runner/src/publishDocsLedger.ts @@ -123,7 +123,7 @@ export function buildLedgerInput({ fileManifest, fileIdToPath, editThisPage, - locale = "en" + locale }: { docsDefinition: DocsDefinition; git?: DocsPublishGitInput; @@ -139,7 +139,11 @@ export function buildLedgerInput({ fileIdToPath?: Map; /** Raw edit-this-page config from docs.yml, forwarded to LedgerConfig. */ editThisPage?: { github?: { owner: string; repo: string; branch?: string; host?: string } }; - /** Locale to stamp on segments. Defaults to "en". */ + /** + * Locale to stamp on segments. When omitted (the base segment), it falls + * back to the default locale the docs config declares, and to "en" for + * sites that declare no translations. + */ locale?: string; }): { localeEntry: LocaleEntry; blobs: Map } { const blobs = new Map(); @@ -225,7 +229,7 @@ export function buildLedgerInput({ jsFiles: jsFilesRef, fileManifest, redirects: null, - locale, + locale: locale ?? docsDefinition.config.translations?.defaultLocale ?? "en", git };