You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Integrates with [i18next](https://www.i18next.com) to enable internationalization of enum labels.
11
+
12
+
## Introduction
13
+
14
+
`@enum-plus/plugin-i18next` is a plugin for [enum-plus](https://github.com/shijistar/enum-plus) that automatically integrates with [i18next](https://www.i18next.com/) to achieve internationalization of enum labels. It allows you to use i18next localization keys in your enum definitions, which are dynamically displayed as translated text for the current language.
15
+
16
+
> This plugin does not support automatic UI updates after switching languages, which requires integration with front-end frameworks (such as React, Vue, etc.). Please consider using the [@enum-plus/plugin-react](https://github.com/shijistar/enum-plus/tree/main/packages/plugin-react) or [@enum-plus/plugin-i18next-vue](https://github.com/shijistar/enum-plus/tree/main/packages/plugin-i18next-vue) plugins.
17
+
18
+
## Installation
19
+
20
+
```bash
21
+
npm install @enum-plus/plugin-i18next
22
+
```
23
+
24
+
Import the `@enum-plus/plugin-i18next` plugin and install it in the entry file of your application:
25
+
26
+
```js
27
+
importi18nPluginfrom'@enum-plus/plugin-i18next';
28
+
import { Enum } from'enum-plus';
29
+
30
+
Enum.install(i18nPlugin);
31
+
```
32
+
33
+
## Plugin Options
34
+
35
+
When installing the plugin, you can pass a configuration object to set global options for the plugin:
36
+
37
+
```ts
38
+
Enum.install(i18nextPlugin, {
39
+
localize: {
40
+
// Set the i18next instance, defaults to the global i18next instance if necessary
41
+
instance: i18next,
42
+
// Options to pass to the i18next.t method
43
+
tOptions: {
44
+
// Set the namespace
45
+
ns: 'my-namespace',
46
+
// Set the default value for the return value
47
+
defaultValue: '-',
48
+
// Other options supported by the i18next.t method
49
+
// Please refer to https://www.i18next.com/translation-function/essentials#overview-options
50
+
},
51
+
},
52
+
});
53
+
```
54
+
55
+
`tOptions` also supports a function form to dynamically generate options, and can even directly return the final translated text.
56
+
57
+
```ts
58
+
// Use function form to dynamically generate tOptions
0 commit comments