-
-
Notifications
You must be signed in to change notification settings - Fork 1
breaking(hono): change defineI18nMiddleware to defineIntlifyMiddleware
#45
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
Conversation
WalkthroughThis PR renames the Hono integration surface from i18n → intlify (public API, context keys, examples, docs, tests) and standardizes context parameter names from Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant HonoMiddleware as defineIntlifyMiddleware
participant Detector as LocaleDetector
participant Handler
Note over App,HonoMiddleware `#DDDDFF`: Request flow with renamed middleware/key
App->>HonoMiddleware: request -> middleware(c)
HonoMiddleware->>Detector: call detector(c)
Detector-->>HonoMiddleware: locale
HonoMiddleware->>App: set context 'intlify' & 'intlifyLocaleDetector'
App->>Handler: handler(c) uses useTranslation(c)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
defineI18nMiddleware to `defineIntlifyMiddle…defineI18nMiddleware to defineIntlifyMiddleware
commit: |
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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/hono/spec/integration.spec.ts (1)
93-93: Inconsistent parameter naming: usecinstead ofctx.Line 93 uses
ctxas the parameter name, while line 140 usesc. The PR standardizes oncthroughout the codebase to align with Hono conventions.Apply this diff to fix the inconsistency:
- const localeDetector = async (ctx: Context, i18n: CoreContext<string, DefineLocaleMessage>) => { - const locale = getQueryLocale(ctx.req.raw).toString() + const localeDetector = async (c: Context, i18n: CoreContext<string, DefineLocaleMessage>) => { + const locale = getQueryLocale(c.req.raw).toString() await sleep(100) const loader = messages[locale] if (loader && !i18n.messages[locale]) {
🧹 Nitpick comments (1)
packages/hono/README.md (1)
124-149: Consider adding a "Migration Guide" section (optional enhancement).While the examples clearly show the new API, a dedicated migration section (or a note in the PR description) explicitly mapping old API → new API would help users upgrading from the previous version. For example:
defineI18nMiddleware→defineIntlifyMiddlewarei18n(middleware variable) →intlifyctx(context parameter) →ci18n.messages→intlify.messagesThis is not a blocker, as the changes are evident from the examples, but would improve user experience for migration.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
packages/hono/README.md(5 hunks)packages/hono/docs/functions/defineIntlifyMiddleware.md(4 hunks)packages/hono/docs/functions/detectLocaleFromAcceptLanguageHeader.md(4 hunks)packages/hono/docs/functions/getDetectorLocale.md(2 hunks)packages/hono/docs/functions/useTranslation.md(4 hunks)packages/hono/docs/index.md(1 hunks)packages/hono/playground/basic/index.ts(2 hunks)packages/hono/playground/global-schema/index.ts(3 hunks)packages/hono/playground/local-schema/index.ts(2 hunks)packages/hono/playground/typesafe-schema/index.ts(3 hunks)packages/hono/spec/integration.spec.ts(10 hunks)packages/hono/src/index.test-d.ts(1 hunks)packages/hono/src/index.test.ts(6 hunks)packages/hono/src/index.ts(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (8)
packages/hono/src/index.test.ts (2)
packages/h3/src/index.ts (1)
intlify(122-126)packages/hono/src/index.ts (1)
defineIntlifyMiddleware(123-164)
packages/hono/playground/basic/index.ts (1)
packages/hono/src/index.ts (1)
defineIntlifyMiddleware(123-164)
packages/hono/playground/global-schema/index.ts (1)
packages/hono/src/index.ts (1)
defineIntlifyMiddleware(123-164)
packages/hono/src/index.test-d.ts (1)
packages/hono/src/index.ts (1)
defineIntlifyMiddleware(123-164)
packages/hono/playground/local-schema/index.ts (1)
packages/hono/src/index.ts (1)
defineIntlifyMiddleware(123-164)
packages/hono/playground/typesafe-schema/index.ts (1)
packages/hono/src/index.ts (1)
defineIntlifyMiddleware(123-164)
packages/hono/spec/integration.spec.ts (2)
packages/h3/src/index.ts (2)
intlify(122-126)CoreContext(39-39)packages/hono/src/index.ts (2)
defineIntlifyMiddleware(123-164)CoreContext(36-36)
packages/hono/src/index.ts (2)
packages/h3/src/index.ts (6)
intlify(122-126)detectLocaleFromAcceptLanguageHeader(241-242)getHeaderLocale(27-27)useTranslation(297-323)DefineLocaleMessage(262-262)getDetectorLocale(344-347)packages/shared/src/types.ts (1)
TranslationFunction(25-39)
🔇 Additional comments (22)
packages/hono/README.md (2)
75-115: Documentation consistently reflects the breaking API changes.The README correctly documents the transition from
defineI18nMiddlewaretodefineIntlifyMiddlewareacross all translation examples. The migration fromctxtoc(Hono's standard context parameter) andi18ntointlifyis consistently applied. The example progression from basic locale detection → middleware-based translation → custom detectors is clear and accurate.
116-199: Custom locale detector examples correctly document the new middleware API.The custom detector examples (lines 122–151 and 162–199) properly show:
- Correct function signature for sync detectors:
(c: Context): string- Correct async signature:
(c: Context, intlify: CoreContext<...>): Promise<string>- Proper access to middleware context via
intlify.messages[locale]for lazy loadingAll imports and middleware usage align with the new naming convention.
packages/hono/docs/functions/detectLocaleFromAcceptLanguageHeader.md (1)
10-10: LGTM! Documentation consistently updated.The documentation correctly reflects the breaking API changes: parameter rename
ctx→cand middleware renamedefineI18nMiddleware→defineIntlifyMiddleware.Also applies to: 19-19, 31-31, 33-33, 46-46
packages/hono/playground/global-schema/index.ts (1)
3-3: LGTM! Playground example properly updated.The example correctly demonstrates the new
defineIntlifyMiddlewareAPI and follows the updated naming conventions.Also applies to: 20-20, 29-29
packages/hono/spec/integration.spec.ts (1)
22-22: LGTM! Test file properly updated.The test suite correctly uses the new
defineIntlifyMiddlewareAPI and updated naming conventions.Also applies to: 34-34, 61-61, 73-73, 104-104, 117-117, 151-151, 161-161
packages/hono/docs/functions/defineIntlifyMiddleware.md (1)
5-5: LGTM! API documentation correctly updated.The documentation comprehensively reflects the breaking change from
defineI18nMiddlewaretodefineIntlifyMiddleware, including all descriptions, signatures, and examples.Also applies to: 7-7, 10-10, 13-13, 28-28, 34-34, 44-44, 46-46, 62-62
packages/hono/playground/local-schema/index.ts (1)
3-3: LGTM! Playground example properly updated.The local schema example correctly demonstrates the new
defineIntlifyMiddlewareAPI with updated naming conventions.Also applies to: 11-11, 20-20
packages/hono/playground/typesafe-schema/index.ts (1)
3-3: LGTM! Typesafe schema example properly updated.The example correctly demonstrates the new
defineIntlifyMiddlewareAPI with proper type safety and updated naming conventions.Also applies to: 13-13, 24-24
packages/hono/src/index.test-d.ts (1)
2-2: LGTM! Type test properly updated.The type test correctly validates the new
defineIntlifyMiddlewareAPI and ensures it conforms to theMiddlewareHandlerinterface.Also applies to: 6-6, 12-12, 19-19
packages/hono/docs/index.md (1)
13-13: LGTM! Documentation index properly updated.The function reference correctly links to the renamed
defineIntlifyMiddlewaredocumentation with an updated description.packages/hono/playground/basic/index.ts (1)
4-4: LGTM! API rename applied consistently.The import, variable naming, and middleware registration have been updated correctly to use the new
defineIntlifyMiddlewareAPI andintlifyterminology.Also applies to: 9-9, 22-22
packages/hono/docs/functions/getDetectorLocale.md (1)
19-19: LGTM! Documentation updates are consistent.The parameter name and middleware reference updates align correctly with the API changes.
Also applies to: 29-29, 36-38
packages/hono/src/index.test.ts (3)
8-8: LGTM! Test import and basic validation updated correctly.The import and test for
defineIntlifyMiddlewarehave been updated consistently with the API changes.Also applies to: 28-41
43-80: LGTM! Context key updates in test are correct.The mock context setup correctly uses the new
intlifyandintlifyLocaleDetectorkeys, matching the implementation changes.
98-126: LGTM! Locale detector test updated correctly.The
getDetectorLocaletest has been updated with the correct context keys and references the updated middleware name.packages/hono/docs/functions/useTranslation.md (1)
10-10: LGTM! Documentation fully aligned with API changes.All parameter names, middleware references, and example code have been updated correctly to reflect the new
defineIntlifyMiddlewareAPI andintlifyterminology.Also applies to: 41-41, 62-62, 68-68, 70-70, 82-82, 85-87
packages/hono/src/index.ts (6)
52-57: LGTM! Module declaration updated correctly.The
ContextVariableMapdeclaration properly reflects the new context keys (intlifyandintlifyLocaleDetector), which are used consistently throughout the implementation.
88-164: LGTM! Middleware function implementation is correct.The
defineIntlifyMiddlewarefunction has been properly renamed and updated:
- JSDoc and examples reflect the new API
- Internal variable naming is consistent (
intlify)- Context keys (
intlify,intlifyLocaleDetector) are set and cleaned up correctly- Warning message references the correct function name
166-194: LGTM! Locale detection function updated consistently.The
detectLocaleFromAcceptLanguageHeaderfunction has been correctly updated:
- Parameter renamed from
ctxtocthroughout- JSDoc examples reference the new middleware name
- Implementation uses the new parameter correctly
196-216: LGTM! Internal helper function updated correctly.The
getLocaleAndIntlifyContexthelper function properly uses the new context keys (intlify,intlifyLocaleDetector) and provides clear error messages referencing the updated middleware name.
218-276: LGTM! Translation function updated correctly.The
useTranslationfunction has been properly updated:
- Parameter renamed from
ctxtocconsistently- JSDoc examples demonstrate the new API correctly
- Implementation uses the updated
getLocaleAndIntlifyContexthelper- Translation logic remains intact
278-301: LGTM! Detector locale function updated correctly.The
getDetectorLocalefunction has been properly updated:
- Parameter renamed from
ctxtoc- JSDoc references the correct middleware name
- Implementation uses the updated helper function
Description
Linked Issues
Additional context
Summary by CodeRabbit
Documentation
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.