{"_id":"@enum-plus/plugin-i18next-vue","name":"@enum-plus/plugin-i18next-vue","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@enum-plus/plugin-i18next-vue","version":"1.0.0","description":"A plugin for enum-plus that supports internationalization of enums through i18next-vue","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","vue","i18next","i18next-vue","localization","globalization","internationalization","front-end","node.js","ssr"],"homepage":"https://github.com/shijistar/enum-plus/tree/master/packages/plugin-i18next-vue","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,"type":"module","main":"lib/index.js","module":"es/index.js","types":"lib/index.d.ts","scripts":{"build":"run-p build:modern build:legacy","build:legacy":"cross-env LEGACY=1 father build","build:modern":"father build","prepublishOnly":"npm run build && npm run test","test":"vitest"},"devDependencies":{"@vitejs/plugin-vue":"^6.0.1","@vitest/browser-playwright":"^4.0.0-beta.17","@vitest/coverage-istanbul":"^4.0.0-beta.17","@vue/test-utils":"^2.4.6","i18next-vue":"^5.3.0","vitest":"^4.0.0-beta.17","vue":"^3.5.22"},"peerDependencies":{"enum-plus":"^3.0.0","i18next":">=23","i18next-vue":">=3.0.0"},"packageManager":"npm@10.9.2","publishConfig":{"registry":"https://registry.npmjs.org/"},"_id":"@enum-plus/plugin-i18next-vue@1.0.0","gitHead":"07930eeea4825fb1383dbb63274d493988e62340","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-Z8u8pB35jCEhRYJ3tl6ipbdUgrI71nkGM5JyVsO6LhLdztSFkSnyppJyclaRyyNEqMyUYDOVOIBJ2DggI613Rg==","shasum":"68318dcce0935dfc8edec7a68e90ab54bd70a6ce","tarball":"https://registry.npmjs.org/@enum-plus/plugin-i18next-vue/-/plugin-i18next-vue-1.0.0.tgz","fileCount":22,"unpackedSize":36308,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAQrng9H5w0DdoHXtz/YCuJVljgXk47zeZYVeFho6D1RAiEA/5fnqk5W5eRyf76hqcnzeNCjlbuJyt5tyvUiCV33ntM="}]},"_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-vue_1.0.0_1760370153674_0.009603576222073862"},"_hasShrinkwrap":false}},"time":{"created":"2025-10-13T15:42:33.594Z","1.0.0":"2025-10-13T15:42:33.882Z","modified":"2025-10-13T15:42:34.134Z"},"maintainers":[{"name":"shijistars","email":"shijistar@hotmail.com"}],"description":"A plugin for enum-plus that supports internationalization of enums through i18next-vue","homepage":"https://github.com/shijistar/enum-plus/tree/master/packages/plugin-i18next-vue","keywords":["enum","enumeration","enum-plus","plugin","typescript","i18n","vue","i18next","i18next-vue","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-i18next-vue\n\n[![npm version](https://img.shields.io/npm/v/@enum-plus/plugin-i18next-vue.svg)](https://www.npmjs.com/package/@enum-plus/plugin-i18next-vue)\n[![license](https://img.shields.io/npm/l/@enum-plus/plugin-i18next-vue.svg)](https://www.npmjs.com/package/@enum-plus/plugin-i18next-vue)\n\n> 集成 [i18next-vue](https://i18next.github.io/i18next-vue) 并实现枚举标签的国际化\n\n## 简介\n\n`@enum-plus/plugin-i18next-vue` 是 [enum-plus](https://github.com/shijistar/enum-plus) 的一个插件，自动集成 [i18next-vue](https://i18next.github.io/i18next-vue) 实现枚举标签的国际化。它允许你在枚举定义中使用 i18next 的本地化键，并动态显示为当前语言的翻译文本。当语言切换时，枚举标签也会相应自动更新。\n\n## 安装\n\n```bash\nnpm install @enum-plus/plugin-i18next-vue\n```\n\n在应用程序的入口文件中，导入 `@enum-plus/plugin-i18next-vue` 插件并安装：\n\n```js\nimport i18nPlugin from '@enum-plus/plugin-i18next-vue';\nimport { Enum } from 'enum-plus';\n\nEnum.install(i18nPlugin);\n```\n\n## 插件选项\n\n安装插件时，可以传入一个配置对象，用于设置插件的全局选项：\n\n```js\nEnum.install(i18nPlugin, {\n  localize: {\n    // 设置 useTranslation 方法的选项\n    useTranslationOptions: {\n      // 设置键值前缀\n      keyPrefix: 'foo',\n      // 其它传递给 useTranslation 的选项\n      // 请参考 https://i18next.github.io/i18next-vue/guide/composition-api.html#customize-t\n    },\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```js\n// 使用函数形式动态生成 tOptions\nEnum.install(i18nPlugin, {\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```js\nEnum.install(i18nPlugin, {\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';\nimport { changeLanguage } from 'i18next';\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\n> **注意**：枚举标签的国际化依赖于 i18next-vue 的 `useTranslation` 方法，因此请确保在 Vue 组件的环境中使用枚举标签，以便它们能够正确响应语言变化。如果在非 Vue 组件环境中，例如 `setTimeout` 的回调函数，枚举标签也可以正常工作，会自动退回到使用 i18next 的默认实例进行翻译。但此时切换语言后不会更新枚举标签，你需要自己监听 i18next 的语言变化事件，并手动更新组件状态。\n","readmeFilename":"README.zh-CN.md","_rev":"1-f08a3524e6e8c588f69008c0b7218bc8"}