Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ const MINIMAL_ROOT = {

function makeDocsDefinition({
pages = {},
root = MINIMAL_ROOT
root = MINIMAL_ROOT,
translations
}: {
pages?: Record<string, { markdown: string }>;
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<typeof buildLedgerInput>[0]["docsDefinition"];
}

Expand Down Expand Up @@ -222,6 +224,66 @@ 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("does not collide the base segment with a real en translation", () => {
const docsDefinition = makeDocsDefinition({
pages: { "welcome-page": { markdown: "# Welcome to the Plant Atlas" } },
translations: { defaultLocale: "nl", translations: ["en", "de"] }
});

const base = buildLedgerInput({ docsDefinition, apiDefinitions: new Map() }).localeEntry;
const translation = buildLedgerInput({ docsDefinition, apiDefinitions: new Map(), locale: "en" }).localeEntry;

// The manifest keys locales as a record, so a base segment stamped "en"
// would overwrite the site's real "en" translation.
expect([base.locale, translation.locale]).toEqual(["nl", "en"]);
});

it("uses config.root for the root field", () => {
const { localeEntry } = buildLedgerInput({
docsDefinition: makeDocsDefinition({ root: MINIMAL_ROOT }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function buildLedgerInput({
fileManifest,
fileIdToPath,
editThisPage,
locale = "en"
locale
}: {
docsDefinition: DocsDefinition;
git?: DocsPublishGitInput;
Expand All @@ -139,7 +139,11 @@ export function buildLedgerInput({
fileIdToPath?: Map<string, string>;
/** 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<string, Buffer> } {
const blobs = new Map<string, Buffer>();
Expand Down Expand Up @@ -225,7 +229,7 @@ export function buildLedgerInput({
jsFiles: jsFilesRef,
fileManifest,
redirects: null,
locale,
locale: locale ?? docsDefinition.config.translations?.defaultLocale ?? "en",
git
};

Expand Down
Loading