npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@enum-plus/plugin-i18next-vue

v1.0.0

Published

A plugin for enum-plus that supports internationalization of enums through i18next-vue

Readme

English | 中文 | CHANGELOG

@enum-plus/plugin-i18next-vue

npm version license

集成 i18next-vue 并实现枚举标签的国际化

简介

@enum-plus/plugin-i18next-vueenum-plus 的一个插件,自动集成 i18next-vue 实现枚举标签的国际化。它允许你在枚举定义中使用 i18next 的本地化键,并动态显示为当前语言的翻译文本。当语言切换时,枚举标签也会相应自动更新。

安装

npm install @enum-plus/plugin-i18next-vue

在应用程序的入口文件中,导入 @enum-plus/plugin-i18next-vue 插件并安装:

import i18nPlugin from '@enum-plus/plugin-i18next-vue';
import { Enum } from 'enum-plus';

Enum.install(i18nPlugin);

插件选项

安装插件时,可以传入一个配置对象,用于设置插件的全局选项:

Enum.install(i18nPlugin, {
  localize: {
    // 设置 useTranslation 方法的选项
    useTranslationOptions: {
      // 设置键值前缀
      keyPrefix: 'foo',
      // 其它传递给 useTranslation 的选项
      // 请参考 https://i18next.github.io/i18next-vue/guide/composition-api.html#customize-t
    },
    // 传递给 i18next.t 方法的默认选项
    tOptions: {
      // 设置命名空间
      ns: 'my-namespace',
      // 设置返回值的默认值
      defaultValue: '-',
      // 其它 i18next.t 方法支持的选项
      // 请参考 https://www.i18next.com/translation-function/essentials#overview-options
    },
  },
});

tOptions 还支持函数形式,以便动态生成选项,

// 使用函数形式动态生成 tOptions
Enum.install(i18nPlugin, {
  localize: {
    tOptions: (key) => {
      if (key === 'week.sunday') {
        return { ns: 'my-namespace' };
      }
      return { ns: 'translation' }; // 默认命名空间
    },
  },
});

你甚至可以在 tOptions 中直接返回一个字符串,作为最终的翻译文本,以完全控制 localize 方法的行为。

Enum.install(i18nPlugin, {
  localize: {
    tOptions: (key) => {
      if (key === 'week.sunday') {
        return '周日'; // 直接返回翻译文本
      }
      return instance.t(key); // 其它情况返回默认翻译
    },
  },
});

基本用法

可以通过在枚举定义中使用本地化键,来实现枚举标签的国际化。

import { Enum } from 'enum-plus';
import { changeLanguage } from 'i18next';

const WeekEnum = Enum(
  {
    Monday: { value: 1, label: 'week.monday' },
    Tuesday: { value: 2, label: 'week.tuesday' },
  },
  {
    name: 'weekDays.name', // 枚举类型名称,可选
  }
);

WeekEnum.label(1); // Monday
WeekEnum.name; // Week

i18next.changeLanguage('zh-CN');
WeekEnum.label(1); // 星期一
WeekEnum.name; // 周

注意:枚举标签的国际化依赖于 i18next-vue 的 useTranslation 方法,因此请确保在 Vue 组件的环境中使用枚举标签,以便它们能够正确响应语言变化。如果在非 Vue 组件环境中,例如 setTimeout 的回调函数,枚举标签也可以正常工作,会自动退回到使用 i18next 的默认实例进行翻译。但此时切换语言后不会更新枚举标签,你需要自己监听 i18next 的语言变化事件,并手动更新组件状态。