Skip to content

Commit d31bb59

Browse files
committed
feat: update changelog and clientLocalize plugin for next-international integration
1 parent 6571ab6 commit d31bb59

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

packages/plugin-next-international/CHANGELOG.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@
44

55
## 1.0.0
66

7-
2025-10-5
7+
2025-12-23
88

9-
Initial release of `@enum-plus/plugin-i18next`.
9+
Initial release of `@enum-plus/plugin-next-international`.
1010

1111
### ✨ Features
1212

13-
- Seamless integration of `enum-plus` with `i18next`.
14-
- Global `localize` options:
15-
- `instance`: custom `i18next` instance (defaults to global).
16-
- `tOptions`: static object passed to `i18next.t`.
17-
- Functional `tOptions(key)` returning:
18-
- A dynamic options object, or
19-
- A final translated string (short‑circuit translation).
20-
- Supports enum item `label` fields as i18next keys (e.g. `week.monday`).
21-
- Supports enum type `name` localization key.
22-
23-
### Not Included
24-
25-
- Automatic UI repaint after language change.
26-
27-
> Please consider framework plugins like [@enum-plus/plugin-react](https://www.npmjs.com/package/@enum-plus/plugin-react) / [@enum-plus/plugin-i18next-vue](https://www.npmjs.com/package/@enum-plus/plugin-i18next-vue).
13+
- React integration for `enum-plus` with automatic UI re-render on language change.
14+
- Enum labels & enum name localize to React elements (not plain strings).
15+
- Global localization configuration fields:
16+
- `localize.mode`: localization mode (`text` or `component`).
17+
- `text`: returns plain text, does not auto-update on language change.
18+
- `component`: returns a React component that auto-updates on language change.
19+
- `isMatch.defaultSearchField` (for search helpers)
20+
- Search helper APIs for non-string labels:
21+
- `WeekEnum.isMatch(search, item)` (case-insensitive fuzzy match)
22+
- `WeekEnum.isMatchCaseSensitive(search, item)`
23+
- Works seamlessly with enum-generated option arrays (e.g. for `<Select />`).

packages/plugin-next-international/src/clientLocalize.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use client';
22

33
import type { EnumInit, EnumKey, EnumValue, PluginFunc, ValueTypeFromSingleInit } from 'enum-plus';
4-
import type { ImportedLocales } from 'international-types';
5-
import type { createI18nServer } from 'next-international/server';
64
import LocaleWithWatch from './components/LocaleWithWatch';
75
import { runtime } from './internal';
86
import { isMatchCore } from './isMatch';
@@ -26,35 +24,24 @@ export interface ClientLocalizePluginOptions {
2624
* - **CN:** 本地化模式,`text` 表示返回纯文本,不支持切换语言后自动更新文本,`component` 表示返回一个组件实例,支持切换语言后自动更新UI。
2725
*/
2826
mode?: 'text' | 'component';
29-
getI18n?: ReturnType<typeof createI18nServer<ImportedLocales>>['getI18n'];
3027
};
3128
isMatch?: IsMatchOptions;
3229
}
3330

3431
const clientLocalizePlugin: PluginFunc<ClientLocalizePluginOptions> = (pluginOptions, Enum) => {
3532
Enum.localize = (key: string | undefined) => {
36-
const { mode = 'text' /* getI18n */ } = pluginOptions?.localize ?? {};
33+
const { mode = 'text' } = pluginOptions?.localize ?? {};
3734
const { t } = runtime;
38-
if (!t /* && !getI18n */) {
35+
if (!t) {
3936
throw new Error(
4037
'[enum-plus][plugin-next-international] is not initialized properly. Please make sure to use `PatchedI18nProviderClient` to wrap your application.'
4138
);
4239
}
43-
// if (t) {
4440
if (mode === 'component') {
4541
return <LocaleWithWatch i18nKey={key} />;
4642
} else {
4743
return t(key as string, undefined!);
4844
}
49-
// } else {
50-
// return getI18n?.().then((t) => {
51-
// if (t) {
52-
// return t(key as string, undefined!);
53-
// } else {
54-
// return key;
55-
// }
56-
// });
57-
// }
5845
};
5946

6047
Enum.extends({

0 commit comments

Comments
 (0)