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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@easy-lang/react

v1.0.2

Published

React bindings for easy-lang

Readme

easy-lang react

React 项目的多语言翻译工具,基于 easy-lang,支持响应式国际化体验。

特性

  • 轻松集成 React
  • 支持多语言切换
  • 响应式翻译
  • 自动收集未翻译的 key
  • 支持变量替换
  • 依赖 easy-lang、react、zustand(peerDependency)

安装

pnpm add @easy-lang/react
# 或
npm install @easy-lang/react
# 或
yarn add @easy-lang/react

需额外安装 reactzustandeasy-lang 作为 peerDependency。

快速开始

1. 定义翻译文件

// translation.json
{
  "错误": {
    "zh_CN": "错误",
    "zh_HK": "錯誤",
    "en": "Error"
  },
  "保存": {
    "zh_CN": "保存",
    "zh_HK": "保存",
    "en": "Save"
  }
}

2. React 项目

import translations from "./translation.json";
import { createI18nTool } from "easy-lang";
import { createReactI18nTool } from "@easy-lang/react";

const reactI18nTool = createReactI18nTool<
  typeof translations,
  "zh_CN" | "zh_HK" | "en"
>(
  createI18nTool({
    defaultLang: "zh_CN",
    langs: ["zh_CN", "zh_HK", "en"],
    translations,
  })
);

export const useTranslate = reactI18nTool.useTranslate();

function App() {
  const { $t, changeLang, currentLang } = useTranslate();
  return (
    <div>
      <button onClick={() => changeLang("en")}>en</button>
      <button onClick={() => changeLang("zh_CN")}>中文</button>
      <div>当前语言: {currentLang}</div>
      <div>{$t("错误")}</div>
    </div>
  );
}

注意:changeLang 调用后会执行 location.reload() 刷新页面。 如果你的项目只用到了 useTranslate 进行翻译,请设置 autoReload: false,可实现响应式更新。

变量替换

支持在翻译文本中使用 {变量名},如:

{
  "欢迎": {
    "en": "Welcome, {name}!"
  }
}

调用:

useTranslate().$t("欢迎", { name: "Tom" }); // => "Welcome, Tom!"

自动收集未翻译 key

未翻译的 key 会自动收集到 untranslatedList,便于后续补全。

测试

本项目使用 vitest 进行单元测试。

pnpm test

构建

pnpm build

许可证

MIT