Skip to content

Commit

Permalink
馃攢 Merge pull request #1297 from jovotech/v4/docs/i18n
Browse files Browse the repository at this point in the history
馃摑 Add typescript section to i18n docs
  • Loading branch information
Jan K枚nig committed Apr 26, 2022
2 parents c9c12d5 + 8af36e0 commit 62f8d8b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion docs/i18n.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,24 @@ build() {
}
```

By default, `$t()` is expected to return a string. This is why you need to typecast to a different type if you're returning something else, for example:
## TypeScript

By default, the `$t` method introduced in the [content access](#content-access) section is expected to return a string. This is why you need to typecast to a different type if you're returning something else, for example:

```typescript
this.$t<string[]>('hello');

// Alternative
this.$t('hello') as string[];
```

To get hints for the i18n keys when using `$t`, you can add the following to your `app.ts` file:

```typescript
declare module '@jovotech/framework/dist/types/I18Next' {
interface I18NextResources {
// Reference resources here
en: typeof en;
}
}
```

0 comments on commit 62f8d8b

Please sign in to comment.