@@ -43,14 +43,11 @@ import type {
4343 LocaleDetector ,
4444 LocaleMessage ,
4545 LocaleParams ,
46- NamedValue ,
47- PickupPaths ,
48- RemovedIndexResources ,
4946 RemoveIndexSignature ,
50- SchemaParams ,
51- TranslateOptions
47+ SchemaParams
5248} from '@intlify/core'
5349import type { Context , MiddlewareHandler , Next } from 'hono'
50+ import type { TranslationFunction } from '../../shared/src/types.ts'
5451
5552declare module 'hono' {
5653 interface ContextVariableMap {
@@ -196,122 +193,6 @@ export function defineI18nMiddleware<
196193export const detectLocaleFromAcceptLanguageHeader = ( ctx : Context ) : Locale =>
197194 getHeaderLocale ( ctx . req . raw ) . toString ( )
198195
199- type ResolveResourceKeys <
200- Schema extends Record < string , any > = { } , // eslint-disable-line @typescript-eslint/no-explicit-any -- NOTE(kazupon): generic type
201- DefineLocaleMessageSchema extends Record < string , any > = { } , // eslint-disable-line @typescript-eslint/no-explicit-any -- NOTE(kazupon): generic type
202- DefinedLocaleMessage extends
203- RemovedIndexResources < DefineLocaleMessageSchema > = RemovedIndexResources < DefineLocaleMessageSchema > ,
204- SchemaPaths = IsEmptyObject < Schema > extends false
205- ? PickupPaths < { [ K in keyof Schema ] : Schema [ K ] } >
206- : never ,
207- DefineMessagesPaths = IsEmptyObject < DefinedLocaleMessage > extends false
208- ? PickupPaths < { [ K in keyof DefinedLocaleMessage ] : DefinedLocaleMessage [ K ] } >
209- : never
210- > = SchemaPaths | DefineMessagesPaths
211-
212- /**
213- * The translation function, which will be defined by {@link useTranslation}.
214- */
215- interface TranslationFunction <
216- Schema extends Record < string , any > = { } , // eslint-disable-line @typescript-eslint/no-explicit-any -- NOTE(kazupon): generic type
217- DefineLocaleMessageSchema extends Record < string , any > = { } , // eslint-disable-line @typescript-eslint/no-explicit-any -- NOTE(kazupon): generic type
218- ResourceKeys = ResolveResourceKeys < Schema , DefineLocaleMessageSchema >
219- > {
220- /**
221- * @param {Key | ResourceKeys } key - A translation key
222- * @returns {string } A translated message, if the key is not found, return the key
223- */
224- < Key extends string > ( key : Key | ResourceKeys ) : string
225- /**
226- * @param {Key | ResourceKeys } key - A translation key
227- * @param {number } plural - A plural choice number
228- * @returns {string } A translated message, if the key is not found, return the key
229- */
230- < Key extends string > ( key : Key | ResourceKeys , plural : number ) : string
231- /**
232- * @param {Key | ResourceKeys } key - A translation key
233- * @param {number } plural - A plural choice number
234- * @param {TranslateOptions } options - A translate options, about details see {@link TranslateOptions}
235- * @returns {string } A translated message, if the key is not found, return the key
236- */
237- < Key extends string > ( key : Key | ResourceKeys , plural : number , options : TranslateOptions ) : string
238- /**
239- * @param {Key | ResourceKeys } key - A translation key
240- * @param {string } defaultMsg - A default message, if the key is not found
241- * @returns {string } A translated message, if the key is not found, return the `defaultMsg` argument
242- */
243- < Key extends string > ( key : Key | ResourceKeys , defaultMsg : string ) : string
244- /**
245- * @param {Key | ResourceKeys } key - A translation key
246- * @param {string } defaultMsg - A default message, if the key is not found
247- * @param {TranslateOptions } options - A translate options, about details see {@link TranslateOptions}
248- * @returns {string } A translated message, if the key is not found, return the `defaultMsg` argument
249- */
250- < Key extends string > (
251- key : Key | ResourceKeys ,
252- defaultMsg : string ,
253- options : TranslateOptions
254- ) : string
255- /**
256- * @param {Key | ResourceKeys } key - A translation key
257- * @param {unknown[] } list - A list for list interpolation
258- * @returns {string } A translated message, if the key is not found, return the key
259- */
260- < Key extends string > ( key : Key | ResourceKeys , list : unknown [ ] ) : string
261- /**
262- * @param {Key | ResourceKeys } key - A translation key
263- * @param {unknown[] } list - A list for list interpolation
264- * @param {number } plural - A plural choice number
265- * @returns {string } A translated message, if the key is not found, return the key
266- */
267- < Key extends string > ( key : Key | ResourceKeys , list : unknown [ ] , plural : number ) : string
268- /**
269- * @param {Key | ResourceKeys } key - A translation key
270- * @param {unknown[] } list - A list for list interpolation
271- * @param {string } defaultMsg - A default message, if the key is not found
272- * @returns {string } A translated message, if the key is not found, return the `defaultMsg` argument
273- */
274- < Key extends string > ( key : Key | ResourceKeys , list : unknown [ ] , defaultMsg : string ) : string
275- /**
276- * @param {Key | ResourceKeys } key - A translation key
277- * @param {unknown[] } list - A list for list interpolation
278- * @param {TranslateOptions } options - A translate options, about details see {@link TranslateOptions}
279- * @returns {string } A translated message, if the key is not found, return the key
280- */
281- < Key extends string > ( key : Key | ResourceKeys , list : unknown [ ] , options : TranslateOptions ) : string
282- /**
283- * @param {Key | ResourceKeys } key - A translation key
284- * @param {NamedValue } named - A named value for named interpolation
285- * @returns {string } A translated message, if the key is not found, return the key
286- */
287- < Key extends string > ( key : Key | ResourceKeys , named : NamedValue ) : string
288- /**
289- * @param {Key | ResourceKeys } key - A translation key
290- * @param {NamedValue } named - A named value for named interpolation
291- * @param {number } plural - A plural choice number
292- * @returns {string } A translated message, if the key is not found, return the key
293- */
294- < Key extends string > ( key : Key | ResourceKeys , named : NamedValue , plural : number ) : string
295- /**
296- * @param {Key | ResourceKeys } key - A translation key
297- * @param {NamedValue } named - A named value for named interpolation
298- * @param {string } defaultMsg - A default message, if the key is not found
299- * @returns {string } A translated message, if the key is not found, return the `defaultMsg` argument
300- */
301- < Key extends string > ( key : Key | ResourceKeys , named : NamedValue , defaultMsg : string ) : string
302- /**
303- * @param {Key | ResourceKeys } key - A translation key
304- * @param {NamedValue } named - A named value for named interpolation
305- * @param {TranslateOptions } options - A translate options, about details see {@link TranslateOptions}
306- * @returns {string } A translated message, if the key is not found, return the key
307- */
308- < Key extends string > (
309- key : Key | ResourceKeys ,
310- named : NamedValue ,
311- options : TranslateOptions
312- ) : string
313- }
314-
315196/**
316197 * use translation function in event handler
317198 *
0 commit comments