{"_id":"@enum-plus/plugin-next-international","name":"@enum-plus/plugin-next-international","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@enum-plus/plugin-next-international","version":"1.0.0","description":"A plugin for enum-plus that supports internationalization of enums through next-international","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","next-international","localization","globalization","internationalization","front-end","node.js","ssr"],"homepage":"https://github.com/shijistar/enum-plus/tree/master/packages/plugin-i18next","bugs":{"url":"https://github.com/shijistar/enum-plus/issues"},"repository":{"type":"git","url":"git+https://github.com/shijistar/enum-plus.git"},"license":"MIT","author":{"name":"李凤宝","email":"shijistar@gmail.com","url":"Leo"},"sideEffects":false,"main":"lib/index.js","module":"es/index.js","types":"lib/index.d.ts","scripts":{"build":"run-p build:es build:es-legacy build:lib","build:es":"father build","build:es-legacy":"cross-env LEGACY=1 father build","build:lib":"run-s ts2lib task:copy-lib","prepublishOnly":"npm run build && npm run test","task:copy-lib":"tsx ../../scripts/copy-lib.ts","test":"jest","test-legacy":"jest -c jest-legacy.config.js","test:browser":"npm run test:browser:bundle && playwright test","test:browser:bundle":"node scripts/browser-test-bundle.js","test:browser:debug":"npm run test:browser:bundle && playwright test --debug","test:browser:ui":"npm run test:browser:bundle && playwright test --ui","ts2lib":"tsc -p tsconfig.lib.json"},"devDependencies":{"next":"^16.0.8","next-international":"^1.3.1"},"peerDependencies":{"enum-plus":"^3.0.0","next-international":">=1.1.0","react":">=16.0.0"},"packageManager":"npm@10.9.2","publishConfig":{"registry":"https://registry.npmjs.org/"},"_id":"@enum-plus/plugin-next-international@1.0.0","gitHead":"d31bb59153c52f8b38042702a854539362b380b2","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-azwCKyUvGTysLnzzMi9XqvYRd1YiPa6CHr6VjBmLCIIsa6eoWKFXl/mywZ6QdV3og0yT0dcihXHbllIpiSxlNA==","shasum":"62c25294db46f9cee6c98c2e34d6c6aefc70bfa1","tarball":"https://registry.npmjs.org/@enum-plus/plugin-next-international/-/plugin-next-international-1.0.0.tgz","fileCount":94,"unpackedSize":181758,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC3Pjq7oPW2wYEzuT8QCJP9ozOYpC+wCyEYGPekcl3FCgIhAMzRgt4d/6Hc3UShHUUgD9VdL8S+g+vklDu0dLwFXagp"}]},"_npmUser":{"name":"shijistars","email":"shijistar@hotmail.com"},"directories":{},"maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/plugin-next-international_1.0.0_1766489177773_0.08771358262178586"},"_hasShrinkwrap":false}},"time":{"created":"2025-12-23T11:26:17.611Z","1.0.0":"2025-12-23T11:26:17.910Z","modified":"2025-12-23T11:26:18.247Z"},"maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"description":"A plugin for enum-plus that supports internationalization of enums through next-international","homepage":"https://github.com/shijistar/enum-plus/tree/master/packages/plugin-i18next","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","next-international","localization","globalization","internationalization","front-end","node.js","ssr"],"repository":{"type":"git","url":"git+https://github.com/shijistar/enum-plus.git"},"author":{"name":"李凤宝","email":"shijistar@gmail.com","url":"Leo"},"bugs":{"url":"https://github.com/shijistar/enum-plus/issues"},"license":"MIT","readme":"<!-- markdownlint-disable MD001 MD009 MD033 MD041 -->\n\n[English](./README.md) | [中文](./README.zh-CN.md) | [CHANGELOG](./CHANGELOG.md)\n\n# @enum-plus/plugin-next-international\n\n[![npm version](https://img.shields.io/npm/v/@enum-plus/plugin-next-international.svg)](https://www.npmjs.com/package/@enum-plus/plugin-next-international)\n[![license](https://img.shields.io/npm/l/@enum-plus/plugin-next-international.svg)](https://www.npmjs.com/package/@enum-plus/plugin-next-international)\n\n> 集成 [next-international](https://next-international.vercel.app) 并实现枚举标签的国际化\n\n## 简介\n\n`@enum-plus/plugin-next-international` 是 [enum-plus](https://github.com/shijistar/enum-plus) 的一个插件，自动集成 [next-international](https://next-international.vercel.app) 实现枚举标签的国际化。它允许你在枚举定义中使用 next-international 的本地化键，并动态显示为当前语言的翻译文本。\n\n> ⚠️ 请注意，该插件仅支持在客户端环境，不支持在服务端渲染。\n\n## 安装\n\n```bash\nnpm install @enum-plus/plugin-next-international\n```\n\n在应用程序的入口文件中，导入 `@enum-plus/plugin-next-international` 插件并安装：\n\n```js\nimport { clientI18nPlugin } from '@enum-plus/plugin-next-international';\nimport { Enum } from 'enum-plus';\n\nEnum.install(clientI18nPlugin);\n```\n\n## 插件选项\n\n安装插件时，可以传入一个配置对象，用于设置插件的全局选项：\n\n```ts\nEnum.install(clientI18nPlugin, {\n  localize: {\n    /**\n     * 本地化输出结果，默认为 'text'\n     *\n     * - `text`: 返回纯文本字符串，不会随语言变化而变化\n     * - `component`: 返回 React 组件实例，切换语言后会自动更新显示内容\n     */\n    mode: 'text',\n  },\n  isMatch: {\n    defaultSearchField: 'label', // isMatch 方法的默认搜索字段，默认为 'label'\n  },\n});\n```\n\n## 用法\n\n### 枚举标签响应语言的变化\n\n可以通过在枚举定义中使用本地化键，来实现枚举标签的国际化。\n\n- **使用文本模式（默认）**\n\n```js\nimport { clientI18nPlugin } from '@enum-plus/plugin-next-international';\nimport { Enum } from 'enum-plus';\nimport { useChangeLocale } from './path/to/client';\n\n// index.js\nEnum.install(clientI18nPlugin, {\n  localize: {\n    mode: 'text',\n  },\n});\n\n// SomeComponent.js\nconst changeLanguage = useChangeLocale();\nconst WeekEnum = Enum(\n  {\n    Monday: { value: 1, label: 'week.monday' },\n    Tuesday: { value: 2, label: 'week.tuesday' },\n  },\n  {\n    name: 'weekDays.name', // 枚举类型名称，可选\n  }\n);\n\nWeekEnum.label(1); // Monday\nWeekEnum.name; // Week\n\nchangeLanguage('zh-CN');\nWeekEnum.label(1); // 星期一\nWeekEnum.name; // 周\n```\n\n- **使用组件模式**\n\n```js\nimport { clientI18nPlugin } from '@enum-plus/plugin-next-international';\nimport { Enum } from 'enum-plus';\nimport { useChangeLocale } from './path/to/client';\n\n// index.js\nEnum.install(clientI18nPlugin, {\n  localize: {\n    mode: 'component',\n  },\n});\n\n// SomeComponent.js\nconst changeLanguage = useChangeLocale();\nconst WeekEnum = Enum(\n  {\n    Monday: { value: 1, label: 'week.monday' },\n    Tuesday: { value: 2, label: 'week.tuesday' },\n  },\n  {\n    name: 'weekDays.name', // 枚举类型名称，可选\n  }\n);\n\nWeekEnum.label(1); // React组件，显示为 Monday，可自动响应语言变化\nWeekEnum.name; // React组件，显示为 Week，可自动响应语言变化\n\nchangeLanguage('zh-CN');\nWeekEnum.label(1); // React组件，显示为 星期一，可自动响应语言变化\nWeekEnum.name; // React组件，显示为 周，可自动响应语言变化\n```\n\n从枚举生成的UI组件，当语言变化时，标签会自动更新：\n\n```tsx\nimport { Button, Select } from 'antd';\nimport { useChangeLocale } from './path/to/client';\n\nconst changeLanguage = useChangeLocale();\n\n<Select options={WeekEnum.items} defaultValue={WeekEnum.Monday} />;\n// 选中并显示: Monday\n\n<Button onClick={() => changeLanguage('zh-CN')}>切换语言</Button>;\n\n// 切换语言后，选中项的文本会自动更新为: 星期一\n```\n\n### 下拉框搜索\n\n在 `组件` 模式下，由于枚举的 `label` 已经变成了组件实例，而不是字符串类型，故无法直接用于文本搜索。可以使用 `isMatch` 或 `isMatchCaseSensitive` 方法来实现对枚举项的过滤。\n\n```tsx\nimport { Select } from 'antd';\n\n<Select options={WeekEnum.items} filterOption={WeekEnum.isMatch} />;\n```\n\n## 其它API\n\n### 💎 isMatch\n\n<sup>**_\\[方法]_**</sup> &nbsp; `isMatch(searchText: string, item: EnumItem): boolean`\n\n`isMatch` 方法用于根据搜索文本过滤枚举项，支持对枚举项的 `label` 进行模糊匹配，且忽略大小写。\n\n- 下拉框搜索\n\n```tsx\nimport { Select } from 'antd';\n\n<Select options={WeekEnum.items} filterOption={WeekEnum.isMatch} />;\n```\n\n- 常规过滤的用法\n\n```js\nWeekEnum.items.filter((item) => WeekEnum.isMatch('Mon', item)); // 过滤出 label 中包含 'Mon' 的枚举项\n```\n\n### 💎 isMatchCaseSensitive\n\n<sup>**_\\[方法]_**</sup> &nbsp; `isMatchCaseSensitive(searchText: string, item: EnumItem): boolean`\n\n`isMatchCaseSensitive` 方法用于根据搜索文本过滤枚举项，支持对枚举项的 `label` 进行模糊匹配，且区分大小写。\n\n- 下拉框搜索\n\n```tsx\nimport { Select } from 'antd';\n\n<Select options={WeekEnum.items} filterOption={WeekEnum.isMatchCaseSensitive} />;\n```\n\n- 常规过滤用法\n\n```js\nWeekEnum.items.filter((item) => WeekEnum.isMatch('mon', item)); // 过滤出 label 中包含 'mon' 的枚举项 (区分大小写)\n```\n","readmeFilename":"README.zh-CN.md","_rev":"1-cef875a2e9214ec4388cba30a2be1525"}