Skip to content

Commit

Permalink
Stop silencing i18n content collection related errors (#2546)
Browse files Browse the repository at this point in the history
  • Loading branch information
HiDeoo authored Nov 1, 2024
1 parent 91e1dd7 commit bf42300
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/big-ducks-rhyme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes an issue where i18n content collection related errors, e.g. malformed JSON or YAML, would not be reported.
12 changes: 4 additions & 8 deletions packages/starlight/utils/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@ export type UserI18nKeys = keyof RemoveIndexSignature<UserI18nSchema>;

/** Get all translation data from the i18n collection, keyed by `id`, which matches locale. */
async function loadTranslations() {
let userTranslations: Record<string, UserI18nSchema> = {};
// Briefly override `console.warn()` to silence logging when a project has no i18n collection.
const warn = console.warn;
console.warn = () => {};
try {
// Load the user’s i18n collection and ignore the error if it doesn’t exist.
userTranslations = Object.fromEntries(
// @ts-ignore — may be an error in projects without an i18n collection
(await getCollection('i18n')).map(({ id, data }) => [id, data] as const)
);
} catch {}
const userTranslations: Record<string, UserI18nSchema> = Object.fromEntries(
// @ts-ignore — may be a type error in projects without an i18n collection
(await getCollection('i18n')).map(({ id, data }) => [id, data] as const)
);
// Restore the original warn implementation.
console.warn = warn;
return userTranslations;
Expand Down

0 comments on commit bf42300

Please sign in to comment.