{"_id":"@enum-plus/plugin-react-i18next","_rev":"3-504162e88fbdbe16d462690225dbf489","name":"@enum-plus/plugin-react-i18next","dist-tags":{"latest":"1.0.0","beta":"1.0.0-beta.1"},"versions":{"1.0.0-beta.0":{"name":"@enum-plus/plugin-react-i18next","version":"1.0.0-beta.0","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","i18next","react-i18next","localization","globalization","internationalization","front-end","node.js","ssr"],"author":{"url":"Leo","name":"李凤宝","email":"shijistar@gmail.com"},"license":"MIT","_id":"@enum-plus/plugin-react-i18next@1.0.0-beta.0","maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"homepage":"https://github.com/shijistar/enum-plus","bugs":{"url":"https://github.com/shijistar/enum-plus/issues"},"dist":{"shasum":"3c91208a6ce1ba915eda8d9e1bbe5c84a3e6d45f","tarball":"https://registry.npmjs.org/@enum-plus/plugin-react-i18next/-/plugin-react-i18next-1.0.0-beta.0.tgz","fileCount":4,"integrity":"sha512-1jpLBKQj7Ool81TppbuWvXbW9XvwG5bAEtN2VvPb4llaJDKQAFeAGdd4/fAfB0DbhQWuY4kD31H6y3pB1UOmFg==","signatures":[{"sig":"MEQCIBgX3hyKXo9p/TL8nEA2HIwFXs8SrovnKb2yulXrK+SSAiBU8pxtIoPxWsxY2pywaJA5gfTEEts6ekbIFlJ9+YPytg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8414},"main":"lib/index.js","types":"lib/index.d.ts","module":"es/index.js","gitHead":"b50d1e199078d350442b2c8bb9ad8a21d289bd38","scripts":{"test":"jest","build":"run-p build:es build:es-legacy build:lib","ts2lib":"tsc -p tsconfig.lib.json","build:es":"father build","build:lib":"run-s ts2lib task:copy-lib","test-legacy":"jest -c jest-legacy.config.js","test:browser":"npm run test:browser:bundle && playwright test","task:copy-lib":"tsx ../../scripts/copy-lib.ts","prepublishOnly":"npm run build && npm run test","build:es-legacy":"cross-env LEGACY=1 father build","test:browser:ui":"npm run test:browser:bundle && playwright test --ui","test:browser:debug":"npm run test:browser:bundle && playwright test --debug","test:browser:bundle":"node scripts/browser-test-bundle.js"},"_npmUser":{"name":"shijistars","email":"shijistar@hotmail.com"},"repository":{"url":"git+https://github.com/shijistar/enum-plus.git","type":"git"},"_npmVersion":"10.9.2","description":"A plugin for enum-plus that supports internationalization of enums through react-i18next","directories":{},"sideEffects":false,"_nodeVersion":"22.13.1","publishConfig":{"registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"packageManager":"npm@10.9.2","peerDependencies":{"i18next":">=14.0.1","enum-plus":"^3.0.0-0","react-i18next":">=10.0.0"},"_npmOperationalInternal":{"tmp":"tmp/plugin-react-i18next_1.0.0-beta.0_1759450478312_0.7664852519768075","host":"s3://npm-registry-packages-npm-production"}},"1.0.0-beta.1":{"name":"@enum-plus/plugin-react-i18next","version":"1.0.0-beta.1","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","i18next","react-i18next","localization","globalization","internationalization","front-end","node.js","ssr"],"author":{"url":"Leo","name":"李凤宝","email":"shijistar@gmail.com"},"license":"MIT","_id":"@enum-plus/plugin-react-i18next@1.0.0-beta.1","maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"homepage":"https://github.com/shijistar/enum-plus","bugs":{"url":"https://github.com/shijistar/enum-plus/issues"},"dist":{"shasum":"e7a4a05dc36c2dffd61d5e86d781d22d3900c802","tarball":"https://registry.npmjs.org/@enum-plus/plugin-react-i18next/-/plugin-react-i18next-1.0.0-beta.1.tgz","fileCount":22,"integrity":"sha512-iHSNGFBVeJU/obzZdxXqsP0kLJUIsak7cZCB+unZ5af/cJOYrVNFODcTaxgcY5qeWW5jwrZT1h/nSsLXMafmsw==","signatures":[{"sig":"MEUCIQD1SV8h7i1eYeK05N7Pl6cBrTpbukbAAaXAZMLCwAotrgIgUSpPxgFhHlCUGv56riz2mDq2K0lV1xG3t9dGHWB+loA=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25889},"main":"lib/index.js","types":"lib/index.d.ts","module":"es/index.js","gitHead":"12ca2afc0d1b87ea17e7a603e57e35d956a5daf2","scripts":{"test":"jest","build":"run-p build:es build:es-legacy build:lib","ts2lib":"tsc -p tsconfig.lib.json","build:es":"father build","build:lib":"run-s ts2lib task:copy-lib","test-legacy":"jest -c jest-legacy.config.js","test:browser":"npm run test:browser:bundle && playwright test","task:copy-lib":"tsx ../../scripts/copy-lib.ts","prepublishOnly":"npm run build && npm run test","build:es-legacy":"cross-env LEGACY=1 father build","test:browser:ui":"npm run test:browser:bundle && playwright test --ui","test:browser:debug":"npm run test:browser:bundle && playwright test --debug","test:browser:bundle":"node scripts/browser-test-bundle.js"},"_npmUser":{"name":"shijistars","email":"shijistar@hotmail.com"},"repository":{"url":"git+https://github.com/shijistar/enum-plus.git","type":"git"},"_npmVersion":"10.9.2","description":"A plugin for enum-plus that supports internationalization of enums through react-i18next","directories":{},"sideEffects":false,"_nodeVersion":"22.13.1","publishConfig":{"registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"packageManager":"npm@10.9.2","readmeFilename":"README.zh-CN.md","peerDependencies":{"i18next":">=14.0.1","enum-plus":"^3.0.0-0","react-i18next":">=10.0.0"},"_npmOperationalInternal":{"tmp":"tmp/plugin-react-i18next_1.0.0-beta.1_1759503587240_0.7785766785588286","host":"s3://npm-registry-packages-npm-production"}},"1.0.0":{"name":"@enum-plus/plugin-react-i18next","version":"1.0.0","description":"A plugin for enum-plus that supports internationalization of enums through react-i18next","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","i18next","react-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":">=14.0.1","react-i18next":">=10.0.0"},"packageManager":"npm@10.9.2","publishConfig":{"registry":"https://registry.npmjs.org/"},"_id":"@enum-plus/plugin-react-i18next@1.0.0","gitHead":"d935912096d5a9ecd6804b305fe816b0eee9974a","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-ThA79yJpZ/QjcMV/SeW23f6spn6Q3MKYob2x6POnERZ20HweSuFJEGC0GSzVZvbh13gyOv30aMxpLUEJYBG5hg==","shasum":"9709ad895f2c40a6922c4949e3ed228f771ae7b6","tarball":"https://registry.npmjs.org/@enum-plus/plugin-react-i18next/-/plugin-react-i18next-1.0.0.tgz","fileCount":22,"unpackedSize":26882,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIFaedf8x9HASVjck9FfB/Xv4J+76OxcVtoI1gozwlEIlAiAhWizdSAmkbU9m4OBBwEZ0B3JPZ1YUOHJghDlyLXwIvw=="}]},"_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-react-i18next_1.0.0_1759671303110_0.06202468073776157"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-03T00:14:38.249Z","modified":"2025-10-05T13:35:03.542Z","1.0.0-beta.0":"2025-10-03T00:14:38.505Z","1.0.0-beta.1":"2025-10-03T14:59:47.390Z","1.0.0":"2025-10-05T13:35:03.318Z"},"bugs":{"url":"https://github.com/shijistar/enum-plus/issues"},"author":{"name":"李凤宝","email":"shijistar@gmail.com","url":"Leo"},"license":"MIT","homepage":"https://github.com/shijistar/enum-plus","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","i18next","react-i18next","localization","globalization","internationalization","front-end","node.js","ssr"],"repository":{"type":"git","url":"git+https://github.com/shijistar/enum-plus.git"},"description":"A plugin for enum-plus that supports internationalization of enums through react-i18next","maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"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-react-i18next` 是 [enum-plus](https://github.com/shijistar/enum-plus) 的一个插件，自动集成 [react-i18next](https://react.i18next.com/getting-started) 实现枚举标签的国际化。它允许你在枚举定义中使用 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-react-i18next\n```\n\n在应用程序的入口文件中，导入 `@enum-plus/plugin-react-i18next` 插件并安装：\n\n```js\nimport reactI18nextPlugin from '@enum-plus/plugin-react-i18next';\nimport { Enum } from 'enum-plus';\n\nEnum.install(reactI18nextPlugin);\n```\n\n## 插件选项\n\n安装插件时，可以传入一个配置对象，用于设置插件的全局选项：\n\n```ts\nEnum.install(reactI18nextPlugin, {\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(reactI18nextPlugin, {\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(reactI18nextPlugin, {\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"}