{"_id":"@enum-plus/plugin-i18next","name":"@enum-plus/plugin-i18next","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@enum-plus/plugin-i18next","version":"1.0.0","description":"A plugin for enum-plus that supports internationalization of enums through i18next","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","i18next","localization","globalization","internationalization","front-end","node.js","ssr"],"homepage":"https://github.com/shijistar/enum-plus","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"},"peerDependencies":{"enum-plus":"^3.0.0","i18next":">=8.4.0"},"packageManager":"npm@10.9.2","publishConfig":{"registry":"https://registry.npmjs.org/"},"_id":"@enum-plus/plugin-i18next@1.0.0","gitHead":"d935912096d5a9ecd6804b305fe816b0eee9974a","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Du+STJ2QRFjgLOmgVyT0jE7CqMAN+6DbBGrX0ajkfm6wFfwPAnp7fXykMwNI2aZozf4It25nONFJofLM6VmcXg==","shasum":"f732a58ba3f7045050edab73b042628d59d049ed","tarball":"https://registry.npmjs.org/@enum-plus/plugin-i18next/-/plugin-i18next-1.0.0.tgz","fileCount":22,"unpackedSize":28845,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIAqNhTyB162QKcLCvQtPHXjncelBme++7qS1n0tdnqqLAiBK13xQx+WavAEIFDkCsn9Ti2tmS6X8Ll1uMQpt/F8dEg=="}]},"_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-i18next_1.0.0_1759671273821_0.2036693921493069"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-05T13:34:33.712Z","1.0.0":"2025-10-05T13:34:34.016Z","modified":"2025-10-05T13:34:34.352Z"},"maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"description":"A plugin for enum-plus that supports internationalization of enums through i18next","homepage":"https://github.com/shijistar/enum-plus","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","i18next","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 for Globalization with i18next\n\n## 简介\n\n`@enum-plus/plugin-i18next` 是 [enum-plus](https://github.com/shijistar/enum-plus) 的一个插件，自动集成 [i18next](https://www.i18next.com/) 实现枚举标签的国际化。它允许你在枚举定义中使用 i18next 的本地化键，并动态显示为当前语言的翻译文本。\n\n> 该插件不支持切换语言后自动更新 UI，这需要结合前端框架（如 React、Vue 等）来实现。请考虑使用 [@enum-plus/plugin-react](https://github.com/shijistar/enum-plus/tree/main/packages/plugin-react) 或 [@enum-plus/plugin-vue](https://github.com/shijistar/enum-plus/tree/main/packages/plugin-vue) 插件。\n\n## 安装\n\n```bash\nnpm install @enum-plus/plugin-i18next\n```\n\n在应用程序的入口文件中，导入 `@enum-plus/plugin-i18next` 插件并安装：\n\n```js\nimport i18nextPlugin from '@enum-plus/plugin-i18next';\nimport { Enum } from 'enum-plus';\n\nEnum.install(i18nextPlugin);\n```\n\n## 插件选项\n\n安装插件时，可以传入一个配置对象，用于设置插件的全局选项：\n\n```ts\nEnum.install(i18nextPlugin, {\n  localize: {\n    // 设置 i18next 实例，如果有必要，默认为全局的 i18next 实例\n    instance: i18next,\n    // 传递给 i18next.t 方法的默认选项\n    tOptions: {\n      // 设置命名空间\n      ns: 'my-namespace',\n      // 设置返回值的默认值\n      defaultValue: '-',\n      // 其它 i18next.t 方法支持的选项\n      // 请参考 https://www.i18next.com/translation-function/essentials#overview-options\n    },\n  },\n});\n```\n\n`tOptions` 还支持函数形式，以便动态生成选项，\n\n```ts\n// 使用函数形式动态生成 tOptions\nEnum.install(i18nextPlugin, {\n  localize: {\n    tOptions: (key) => {\n      if (key === 'week.sunday') {\n        return { ns: 'my-namespace' };\n      }\n      return { ns: 'translation' }; // 默认命名空间\n    },\n  },\n});\n```\n\n你甚至可以在 `tOptions` 中直接返回一个字符串，作为最终的翻译文本，以完全控制 `localize` 方法的行为。\n\n```ts\nEnum.install(i18nextPlugin, {\n  localize: {\n    tOptions: (key) => {\n      if (key === 'week.sunday') {\n        return '周日'; // 直接返回翻译文本\n      }\n      return instance.t(key); // 其它情况返回默认翻译\n    },\n  },\n});\n```\n\n## 基本用法\n\n可以通过在枚举定义中使用本地化键，来实现枚举标签的国际化。\n\n```js\nimport { Enum } from 'enum-plus';\n\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\ni18next.changeLanguage('zh-CN');\nWeekEnum.label(1); // 星期一\nWeekEnum.name; // 星期\n```\n","readmeFilename":"README.zh-CN.md","_rev":"1-e38bb3ad73cfbbd02302010bcaf0554b"}