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

remix-i18n

v2.0.0

Published

[英文文档](./README.md)

Readme

Remix I18n

英文文档

概述

Remix I18n 是一个为 Remix 应用程序设计的国际化库,提供简单易用的 API 来处理多语言支持、翻译和语言切换。

安装

npm install @your-org/remix-i18n
# 或
yarn add @your-org/remix-i18n
# 或
pnpm add @your-org/remix-i18n

快速开始

1. 初始化 I18n 实例

// app/i18n.ts
import { RemixI18n } from '@your-org/remix-i18n';

export const i18n = new RemixI18n({
  supportedLanguages: ['en', 'zh', 'es'],
  fallbackLng: 'en',
});

// 设置翻译
const enTranslations = {
  greeting: 'Hello, {{name}}!',
  welcome: 'Welcome to our application',
  menu: {
    home: 'Home',
    about: 'About',
    contact: 'Contact',
  },
};

const zhTranslations = {
  greeting: '你好,{{name}}!',
  welcome: '欢迎使用我们的应用',
  menu: {
    home: '首页',
    about: '关于我们',
    contact: '联系我们',
  },
};

i18n.set('en', enTranslations);
i18n.set('zh', zhTranslations);

2. 在根组件中提供 I18n 上下文

// app/root.tsx
import { I18nProvider } from '@your-org/remix-i18n';
import { i18n } from './i18n';

export default function App() {
  return (
    <I18nProvider i18n={i18n}>
      <Outlet />
    </I18nProvider>
  );
}

3. 在组件中使用翻译

// app/routes/index.tsx
import { useI18n } from '@your-org/remix-i18n';

export default function Home() {
  const i18n = useI18n();
  return (
    <div>
      <h1>{i18n.t('welcome')}</h1>
      <p>{i18n.t('greeting', { name: 'John' })}</p>
      <nav>
        <ul>
          <li>{i18n.t('menu.home')}</li>
          <li>{i18n.t('menu.about')}</li>
          <li>{i18n.t('menu.contact')}</li>
        </ul>
      </nav>
    </div>
  );
}

4. 切换语言

// app/routes/settings.tsx
import { useI18n } from '@your-org/remix-i18n';

export default function Settings() {
  const i18n = useI18n();

  const handleLanguageChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
    i18n.locale(e.target.value);
  };

  return (
    <div>
      <h2>设置</h2>
      <select value={i18n.locale()} onChange={handleLanguageChange}>
        <option value="en">English</option>
        <option value="zh">中文</option>
        <option value="es">Español</option>
      </select>
    </div>
  );
}

API 文档

RemixI18n 类

构造函数

new RemixI18n(options: RemixI18nOptions)
参数
  • supportedLanguages: 支持的语言列表
  • fallbackLng: 回退语言

方法

  • locale(lang?: string): string 获取或设置当前语言

  • set(lang: string, dict: I18nDict): void 设置指定语言的翻译字典

  • t(key: string, params?: any, lang?: string): string 获取翻译,支持参数替换

  • setOnChange(fn: (locale: string) => void): void 设置语言变化时的回调函数

组件和钩子

  • I18nProvider 组件 提供 I18n 上下文

  • useI18n() 钩子 获取 I18n 实例

赞助

维护者: Willin Wang

如果您对本项目感兴趣,可以通过以下方式支持我:

许可证

Apache-2.0