Composables

useTranslation

The useTranslation() composable returns the translation function.

The useTranslation() composable returns the translation function.

The locale used by the translation function is the locale detected by the function defined in experimental.localeDetector option.

This composable is experimental and server-side only.

Type

declare function useTranslation<Schema extends Record<string, any> = {}, Event extends H3Event = H3Event>(
  event: Event
): Promise<TranslationFunction<Schema, DefineLocaleMessage>>

Usage

export default defineEventHandler(async event => {
  const t = await useTranslation(event)
  return {
    hello: t('hello')
  }
})

Copyright © 2024