@@ -10,6 +10,7 @@ import { getLocaleDetectionOptions } from '../shared/utils.js';
1010
1111export interface I18nPluginOptions {
1212 localeDetection : LocaleDetectionOptions ;
13+ staticRoutePrefixes : string [ ] ;
1314}
1415
1516/**
@@ -77,6 +78,18 @@ const convertToHonoLanguageDetectorOptions = (
7778 } ;
7879} ;
7980
81+ /**
82+ * Check if the given pathname is a static resource request
83+ */
84+ const isStaticResourceRequest = (
85+ pathname : string ,
86+ staticRoutePrefixes : string [ ] ,
87+ ) : boolean => {
88+ return staticRoutePrefixes . some (
89+ prefix => pathname . startsWith ( `${ prefix } /` ) || pathname === prefix ,
90+ ) ;
91+ } ;
92+
8093const getLanguageFromPath = (
8194 req : any ,
8295 urlPath : string ,
@@ -156,6 +169,7 @@ export const i18nServerPlugin = (options: I18nPluginOptions): ServerPlugin => ({
156169 fallbackLanguage = 'en' ,
157170 detection,
158171 } = getLocaleDetectionOptions ( entryName , options . localeDetection ) ;
172+ const staticRoutePrefixes = options . staticRoutePrefixes ;
159173 const originUrlPath = route . urlPath ;
160174 const urlPath = originUrlPath . endsWith ( '/' )
161175 ? `${ originUrlPath } *`
@@ -168,17 +182,36 @@ export const i18nServerPlugin = (options: I18nPluginOptions): ServerPlugin => ({
168182 fallbackLanguage ,
169183 detection ,
170184 ) ;
185+ const detectorHandler = languageDetector ( detectorOptions ) ;
171186 middlewares . push ( {
172187 name : 'i18n-language-detector' ,
173188 path : urlPath ,
174- handler : languageDetector ( detectorOptions ) ,
189+ handler : async ( c : Context , next : Next ) => {
190+ const url = new URL ( c . req . url ) ;
191+ const pathname = url . pathname ;
192+
193+ // For static resource requests, skip language detection
194+ if ( isStaticResourceRequest ( pathname , staticRoutePrefixes ) ) {
195+ return await next ( ) ;
196+ }
197+
198+ return detectorHandler ( c , next ) ;
199+ } ,
175200 } ) ;
176201 }
177202
178203 middlewares . push ( {
179204 name : 'i18n-server-middleware' ,
180205 path : urlPath ,
181206 handler : async ( c : Context , next : Next ) => {
207+ const url = new URL ( c . req . url ) ;
208+ const pathname = url . pathname ;
209+
210+ // For static resource requests, skip i18n processing
211+ if ( isStaticResourceRequest ( pathname , staticRoutePrefixes ) ) {
212+ return await next ( ) ;
213+ }
214+
182215 const language = getLanguageFromPath ( c . req , urlPath , languages ) ;
183216 if ( ! language ) {
184217 // Get detected language from languageDetector middleware
0 commit comments