Skip to report

Language detection shares Hono’s Accept parser

Follow Hono’s language detector middleware into a shared Accept-header parser that the accepts helper now also uses, detecting from query, cookie, header or path.

honojs/hono #3787 · PR by lord007tn · Merged

honojs/hono 1e629125..ecdbd5eb

base and head as given

  • Language detection is a new middleware capability.
  • Accept-header parsing moved from request helpers into shared utilities.
  • Language detection now depends on shared accept-header parsing.
files changed
9
in a component
4
lines in components
413
components
3
public routes changed
0
schema statements
0
new dependencies
0
excluded by role
5
Based on 4 of 4 eligible changed files

Language detection

Added
Before
Language detection did not exist
After
Requests gain a language value

Applications can add middleware that selects a supported language from query parameters, cookies, headers, or URL paths and stores it on the request context. Detected languages can be cached in a cookie.

In favour

  • In favour: Configurable detection order supports application-specific precedence
  • In favour: Only configured supported languages reach request context

The model found nothing to weigh against this.

Inspect 2 source files behind this explanation

Shared accept-header parsing

Modified
Before
Parsing lived in request helpers
After
Utilities provide shared parsing

Accept-based helpers and language detection now share one parser that orders header values by quality score and preserves their original order when scores tie.

In favour

  • In favour: Preserves header order when quality scores tie

The model found nothing to weigh against this.

Inspect 2 source files behind this explanation
Files changed in 3 components. Dependencies shown: 2 new, 2 unchanged
unchanged · 2new · 21 component added

2 new dependencies between components — Language Middleware → Helper · Language Middleware → Utils

What else could behave differently

2 components · 4 files

These components import changed code, directly or through other files. A traced dependency is a place to review, not a confirmed runtime failure.

Reached 2

ComponentSymbolCited atFilesReached by
Helpersrc/helper/Added src/utils/accept.ts:12-2421 direct · 1 at two steps
Trace path

Shortest component path from the changed symbol:

  1. Utils
  2. Helper

Later steps follow file imports; they do not prove this symbol is called.

Language Middlewaresrc/middleware/language/Added 1 of 10 changed symbols reaching itsrc/middleware/language/language.ts:1022 direct
Trace path

Shortest component path from the changed symbol:

  1. Language Middleware

Later steps follow file imports; they do not prove this symbol is called.

Statements 2

The added parseAccept export reached 2 Helper files; all 7 names in its origin file changed. 11
src/utils/accept.ts:12-24
The added DetectorType export reached 2 Language Middleware files; all 18 names in its origin file changed. 2
src/middleware/language/language.ts:10

3 reached files belong to no component — tests, docs and config.

Routes, schema, dependencies

No public URL, no migration and no new package.

Inspect components, files and symbols

Component

HelperModified
src/helper/

1 file · 26 lines

exports, 13 dependents

Helper's static export surface no longer included parseAccept.

Shared accept-header parsing, modified

UtilsModified
src/utils/

1 file · 86 lines

20 dependents

Utils added the Accept and parseAccept exports.

Shared accept-header parsing, modified

Language MiddlewareAdded
src/middleware/language/

2 files · 301 lines

Language Middleware added 16 exported names, including languageDetector and parseAcceptLanguage.

Language detection, added

File

Language Middlewaresrc/middleware/language/
src/middleware/language/language.ts

+289 −0

Language detection, added

Language Middlewaresrc/middleware/language/
src/middleware/language/index.ts

+12 −0

Language detection, added

Helpersrc/helper/
src/helper/accepts/accepts.ts

+1 −25

Shared accept-header parsing, modified

Utilssrc/utils/
src/utils/accept.ts

+86 −0

Shared accept-header parsing, modified

Diff

Language Middlewaresrc/middleware/language/
src/middleware/language/language.ts

1–289

Language detection, added

Language Middlewaresrc/middleware/language/
src/middleware/language/index.ts

1–12

Language detection, added

Helpersrc/helper/
src/helper/accepts/accepts.ts

2–2, 20–44

Shared accept-header parsing, modified

Utilssrc/utils/
src/utils/accept.ts

1–86

Shared accept-header parsing, modified

Analysis scope

453 → 3
  1. 453
    files at head
  2. 56
    components
  3. 3
    changed by this change

Where the new files landed

3 new files
New fileBelongs toUsed byCallsServes
src/utils/accept.ts
Utilsbase frame
HelperLanguage Middleware
nothing outside its own component
src/middleware/language/2 new files
Language Middlewarenew territory
src/HelperUtils
./language

2 added files carry no component — 2 test.

3components changed
0reached, not changed
1components added/removed
3dependencies added between components
0dependencies removed between components
0files moved to another path

9 files changed, 8 claims stated. 2 components reached in total.

naming: “model

narrative: “model

analyzer 0.2.0, config v1.9.0-phase8

Every line above is derived from 1e629125..ecdbd5eb and nothing else.