-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
refactor: unsplit astro:i18n
module
#9790
Conversation
🦋 Changeset detectedLatest commit: 70d5a85 The changes in this PR will be included in the next version bump. 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 |
if (i18n === undefined) throw new Error("The `astro:i18n` module can not be used without enabling i18n in your Astro config."); | ||
return this.resolve("astro/virtual-modules/i18n.js"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error here is new. Previously, it would throw with a generic "cant resolve" message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw an AstroError
instead? Or use this.error
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if one of them is better. I can say this will properly display the message in the browser error overlay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be an AstroError, yes! I didn't fully understand the this.error thing though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be an AstroError, yes! I didn't fully understand the this.error thing though
In a rollup plugin you can use this.error
to throw an error without breaking too much stuff :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd go with a AstroError so that we can have docs and stuff on it then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packages/astro/src/i18n/index.ts
Outdated
return code; | ||
} | ||
} else if (locale === path) { | ||
return locale; | ||
} | ||
} | ||
return undefined; | ||
throw new Error("Unreachable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added errors in a couple of places where implementation did not match the public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest inserting a better message here. Even though it's for us, it's good practice to leave a message explaining why this happened, or a possible fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 4abc42e
import type { I18nInternalConfig } from "../i18n/vite-plugin-i18n.js"; | ||
export { normalizeTheLocale, toCodes, toPaths } from "../i18n/index.js"; | ||
// @ts-expect-error | ||
import config from "astro-internal:i18n-config" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something that I didn't know about virtual modules an vite. Nice!
const { defaultLocale, locales, routing, fallback } = i18n!; | ||
const config: I18nInternalConfig = { base, format, site, trailingSlash, defaultLocale, locales, routing, fallback }; | ||
return `export default ${JSON.stringify(config)};`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely more maintainable!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, and this will be the key to removing i18n from the manifest
if (i18n === undefined) throw new Error("The `astro:i18n` module can not be used without enabling i18n in your Astro config."); | ||
return this.resolve("astro/virtual-modules/i18n.js"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we throw an AstroError
instead? Or use this.error
?
packages/astro/src/i18n/index.ts
Outdated
return code; | ||
} | ||
} else if (locale === path) { | ||
return locale; | ||
} | ||
} | ||
return undefined; | ||
throw new Error("Unreachable"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest inserting a better message here. Even though it's for us, it's good practice to leave a message explaining why this happened, or a possible fix.
Changes
astro:i18n
module lived inastro/client
.vite-plugin-i18n.ts
.astro/virtual-modules/i18n.ts
Testing
Does not affect behavior. Existing tests should pass.
Docs
Does not affect usage.