Skip to content

Commit

Permalink
fix: export TranslationSignatureResolver type (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon authored Jun 13, 2024
1 parent 9065c5e commit 11da741
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
50 changes: 49 additions & 1 deletion docs/@intlify/vue-i18n-extensions-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- [transformVTDirective](#transformvtdirective)
- [Interface](#interface)
- [TransformVTDirectiveOptions](#transformvtdirectiveoptions)
- [TypeAlias](#typealias)
- [TranslationSignatureResolver](#translationsignatureresolver)

## Function

Expand Down Expand Up @@ -127,7 +129,7 @@ Translation function signatures

**Signature:**
```typescript
translationSignatures?: string | string[];
translationSignatures?: string | TranslationSignatureResolver | string[] | TranslationSignatureResolver[] | (string | TranslationSignatureResolver)[];
```

#### Remarks
Expand All @@ -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(`<p v-t="'hello'"></p>`, {
// ...
directiveTransforms: { t: transformVT }
})
```



2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { transformVTDirective } from './transform'
export type { TransformVTDirectiveOptions } from './transform'
export type { TransformVTDirectiveOptions, TranslationSignatureResolver } from './transform'
2 changes: 2 additions & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 11da741

Please sign in to comment.