Repository navigation
fix(plugin-i18n): change to builtinResources option
#296
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -83,8 +83,8 @@ export default function i18n( | |||||||||||||||||||||||||||||||||||||
| const locale = toLocale(options.locale) | ||||||||||||||||||||||||||||||||||||||
| const localeStr = toLocaleString(locale) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| const resources = | ||||||||||||||||||||||||||||||||||||||
| options.resources || | ||||||||||||||||||||||||||||||||||||||
| const builtinResources = | ||||||||||||||||||||||||||||||||||||||
| options.builtinResources || | ||||||||||||||||||||||||||||||||||||||
| (Object.create(null) as Record<string, Record<BuiltinResourceKeys, string>>) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+86
to
88
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Provide a backward-compatible fallback with a deprecation warning To avoid breaking existing users immediately, fall back to the deprecated Apply this diff: - const builtinResources =
- options.builtinResources ||
- (Object.create(null) as Record<string, Record<BuiltinResourceKeys, string>>)
+ const builtinResources =
+ options.builtinResources ??
+ // Deprecated alias (to be removed in the next major)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ (options as any).resources ??
+ (Object.create(null) as Record<string, Record<BuiltinResourceKeys, string>>)
+
+ // Soft deprecation notice (printed once)
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ if ((options as any).resources && !options.builtinResources) {
+ // Keep this lightweight to avoid noisy logs; consider gating by env if needed
+ console.warn(
+ '[@gunshi/plugin-i18n] `resources` option is deprecated. Use `builtinResources` instead.'
+ )
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // create translation adapter | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -150,7 +150,7 @@ export default function i18n( | |||||||||||||||||||||||||||||||||||||
| setResource(DEFAULT_LOCALE, DefaultResource as Record<BuiltinResourceKeys, string>) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // install built-in locale resources | ||||||||||||||||||||||||||||||||||||||
| for (const [locale, resource] of Object.entries(resources)) { | ||||||||||||||||||||||||||||||||||||||
| for (const [locale, resource] of Object.entries(builtinResources)) { | ||||||||||||||||||||||||||||||||||||||
| setResource(locale, resource) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -90,7 +90,7 @@ export interface I18nPluginOptions { | |||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Built-in localizable resources | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| resources?: Record<string, Record<BuiltinResourceKeys, string>> | ||||||||||||||||||||||||||||||||||||||||||
| builtinResources?: Record<string, Record<BuiltinResourceKeys, string>> | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+93
to
94
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Public option rename looks good; add a deprecated alias to avoid a breaking change Renaming a public option is a breaking change for downstream consumers. Consider keeping a deprecated Apply this diff to introduce a deprecated alias: export interface I18nPluginOptions {
/**
* Locale to use for translations
*/
locale?: string | Intl.Locale
/**
* Translation adapter factory
*/
translationAdapterFactory?: TranslationAdapterFactory
/**
* Built-in localizable resources
*/
- builtinResources?: Record<string, Record<BuiltinResourceKeys, string>>
+ /**
+ * @deprecated Use `builtinResources` instead. This alias will be removed in the next major release.
+ */
+ resources?: Record<string, Record<BuiltinResourceKeys, string>>
+ builtinResources?: Record<string, Record<BuiltinResourceKeys, string>>
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
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.
💡 Verification agent
🧩 Analysis chain
LGTM: test config aligns with the new public option
Switching to
builtinResourcesmatches the plugin API rename and keeps tests up to date.Run this repo-wide check to ensure there are no lingering usages of the old
resourcesoption in code, tests, or docs:🏁 Script executed:
Length of output: 685
🏁 Script executed:
Length of output: 2426
Documentation update required: replace deprecated
resourcesoption in plugin-renderer READMEThe test changes correctly switch to the new
builtinResourcesAPI, but the docs still reference the oldresourcesoption. Please update:• packages/plugin-renderer/README.md (around line 243):
No changes are needed for the private
#resourcesfield inplugin-i18n/src/translation.tsor the lockfile entry.📝 Committable suggestion
🤖 Prompt for AI Agents