diff --git a/docs/@intlify/vue-i18n-extensions-api.md b/docs/@intlify/vue-i18n-extensions-api.md index 37c58ca..a583fec 100644 --- a/docs/@intlify/vue-i18n-extensions-api.md +++ b/docs/@intlify/vue-i18n-extensions-api.md @@ -6,6 +6,8 @@ - [transformVTDirective](#transformvtdirective) - [Interface](#interface) - [TransformVTDirectiveOptions](#transformvtdirectiveoptions) +- [TypeAlias](#typealias) + - [TranslationSignatureResolver](#translationsignatureresolver) ## Function @@ -127,7 +129,7 @@ Translation function signatures **Signature:** ```typescript -translationSignatures?: string | string[]; +translationSignatures?: string | TranslationSignatureResolver | string[] | TranslationSignatureResolver[] | (string | TranslationSignatureResolver)[]; ``` #### Remarks @@ -136,3 +138,49 @@ You can specify the signature of the translation function attached to the bindin +## TypeAlias + +### TranslationSignatureResolver + +Translation signature resolver + +**Signature:** +```typescript +type TranslationSignatureResolver = (context: TransformContext) => string; +``` + +#### Remarks + +This resolver is used at ['translationSignatures' option](#transformvtdirectiveoptions) + +###1 Examples + + +```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 } +}) +``` + + + diff --git a/src/index.ts b/src/index.ts index 5b5891f..4f59980 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ export { transformVTDirective } from './transform' -export type { TransformVTDirectiveOptions } from './transform' +export type { TransformVTDirectiveOptions, TranslationSignatureResolver } from './transform' diff --git a/src/transform.ts b/src/transform.ts index dab60ee..d282312 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -56,6 +56,8 @@ type VTDirectiveValue = { * @remarks * This resolver is used at {@link TransformVTDirectiveOptions | 'translationSignatures' option} * + * @public + * * @example * ```js * import { compile } from '@vue/compiler-dom'