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

v1.0.0

Published

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

Readme

English | 中文 | CHANGELOG

enum-plus for Globalization with i18next

简介

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

该插件不支持切换语言后自动更新 UI,这需要结合前端框架(如 React、Vue 等)来实现。请考虑使用 @enum-plus/plugin-react@enum-plus/plugin-vue 插件。

安装

npm install @enum-plus/plugin-i18next

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

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

Enum.install(i18nextPlugin);

插件选项

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

Enum.install(i18nextPlugin, {
  localize: {
    // 设置 i18next 实例,如果有必要,默认为全局的 i18next 实例
    instance: i18next,
    // 传递给 i18next.t 方法的默认选项
    tOptions: {
      // 设置命名空间
      ns: 'my-namespace',
      // 设置返回值的默认值
      defaultValue: '-',
      // 其它 i18next.t 方法支持的选项
      // 请参考 https://www.i18next.com/translation-function/essentials#overview-options
    },
  },
});

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

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

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

Enum.install(i18nextPlugin, {
  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

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