import { TransformContext, DirectiveTransform } from '@vue/compiler-dom'; import { I18n, I18nMode } from 'vue-i18n'; /** * Translation signature resolver * * @remarks * This resolver is used at {@link TransformVTDirectiveOptions | 'translationSignatures' option} * * @public * * @example * ```js * import { compile } from '@vue/compiler-dom' * import { transformVTDirective } from '@intlify/vue-i18n-extensions' * * // the below is just an example, you can use your own signature resolver * const signatureMap = new Map() * * const transformVT = transformVTDirective({ * translationSignatures: (context) => { * const { prefixIdentifiers, bindingMetadata, inline, filename } = context * let signature = '' * * // something logic to resolve signature like using `signatureMap` * // signature = signatureMap.get(filename) * // ... * * return signature * } * }) * * const { code } = compile(`

`, { * // ... * directiveTransforms: { t: transformVT } * }) * ``` */ type TranslationSignatureResolver = (context: TransformContext, baseResolver: (context: TransformContext, signature: string) => string | undefined) => string | undefined; /** * Transform options for `v-t` custom directive * * @public */ interface TransformVTDirectiveOptions = {}, // eslint-disable-line @typescript-eslint/no-empty-object-type -- TODO: fix this DateTimeFormats extends Record = {}, // eslint-disable-line @typescript-eslint/no-empty-object-type -- TODO: fix this NumberFormats extends Record = {}, // eslint-disable-line @typescript-eslint/no-empty-object-type -- TODO: fix this Legacy extends boolean = true> { /** * I18n instance * * @remarks * If this option is specified, `v-t` custom directive transform uses an I18n instance to pre-translate. * The translation will use the global resources registered in the I18n instance, * that is, `v-t` directive transform is also a limitation that the resources of each component cannot be used. */ i18n?: I18n; /** * I18n Mode * * @remarks * Specify the API style of vue-i18n. If you use legacy API style (e.g. `$t`) at vue-i18n, you need to specify `legacy`. * * @default 'composition' */ mode?: I18nMode; /** * Translation function signatures * * @remarks * You can specify the signature of the translation function attached to the binding context when it is codegen in the Vue Compiler. * If you have changed the signature to a non `t` signature in the `setup` hook or `