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-vue-i18n

v1.0.0

Published

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

Readme

English | 中文 | CHANGELOG

@enum-plus/plugin-vue-i18n

npm version license

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

简介

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

注意:该插件要求 Vue 3 和 vue-i18n 9 及以上版本,不支持 vue-i18n 的 legacy 模式。

安装

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

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

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

Enum.install(i18nPlugin, {
  localize: {
    instance: i18n,
  },
});

插件选项

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

Enum.install(i18nPlugin, {
  localize: {
    // 传递全局默认的 i18n 实例。如果你想在非组件环境下使用枚举的国际化功能,必须传入该实例
    instance: i18n,
    // 传递给 i18next.t 方法的默认选项
    tOptions: {
      // 设置返回值的默认值
      default: '-',
      // 其它 i18next.t 方法支持的选项
      // 请参考 https://vue-i18n.intlify.dev/api/general.html#translateoptions
    },
  },
});

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';

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

const i18n = useI18n();
i18n.locale.value = 'zh-CN';
WeekEnum.label(1); // 星期一
WeekEnum.name; // 周