Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence i18n content collection warnings #1458

Merged
merged 5 commits into from
Feb 6, 2024
Merged

Conversation

delucis
Copy link
Member

@delucis delucis commented Feb 5, 2024

Closes #1174

Currently, there are two warnings logged related to the i18n content collection when running our basic starter kit (i.e. with no i18n files set up):

  1. A warning that an i18n collection is configured but doesn’t exist on disk (on dev/build start up):

    The i18n collection is defined but no content/i18n folder exists in the content directory. Create a new folder for the collection, or check your content configuration file for typos.

  2. A runtime error when Starlight actually calls getCollection('i18n') to again say that the collection directory doesn’t exist:

    The collection i18n does not exist or is empty. Ensure a collection directory with this name exists.

Many of us Starlight users have trained ourselves to ignore these warnings, but they remain confusing especially for newer users who assume they need to fix something.

This PR addresses both of these points:

  1. Removes the i18n collection set-up from our two starter templates, which stops Astro emitting that first warning. Means people have to add that manually if they need the custom i18n features, but we do already document that in our “Translate Starlight’s UI” docs.

  2. Hackily overrides console.warn() briefly while we make our getCollection('i18n') call, so that we swallow the runtime error. Admittedly, this is a bit gross, but I considered the options and I feel like the warning does have quite a bit of value for your average Astro users, so removing it upstream seemed kind of unfair.

    @Princesseuh also suggested adding a “noWarn” option to the query APIs to support this officially. I think that could be a nice idea, but I’m not 100% sure the use case is widespread enough to justify that yet.

Copy link

changeset-bot bot commented Feb 5, 2024

🦋 Changeset detected

Latest commit: 4c71f27

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview Feb 6, 2024 3:01pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
starlight-i18n ⬜️ Ignored (Inspect) Feb 6, 2024 3:01pm

@github-actions github-actions bot added the 🌟 core Changes to Starlight’s main package label Feb 5, 2024
@astrobot-houston
Copy link
Collaborator

astrobot-houston commented Feb 5, 2024

size-limit report 📦

Path Size
/index.html 5.22 KB (0%)
/_astro/*.js 21.54 KB (0%)
/_astro/*.css 13.13 KB (0%)

@delucis delucis added the 🌟 patch Change that triggers a patch release label Feb 6, 2024
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stop gap until we can upstream a fix!

@delucis
Copy link
Member Author

delucis commented Feb 6, 2024

Thanks for the review Nate 💖

@delucis delucis merged commit 8c88642 into main Feb 6, 2024
9 checks passed
@delucis delucis deleted the dx-973/i18n-warnings branch February 6, 2024 15:08
@astrobot-houston astrobot-houston mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package 🌟 patch Change that triggers a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants