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

@better-i18n/vite

v0.2.14

Published

Vite plugin for Better i18n — SSR translation injection, zero FOUC

Readme

@better-i18n/vite

Vite plugin for Better i18n — server-side translation injection with zero FOUC.

npm

Features

  • Zero FOUC — Translations are injected server-side into <script> tags, read synchronously before first paint
  • Automatic Locale Detection — URL path → cookie → Accept-Language → default (priority order)
  • Zero Config Provider — <BetterI18nProvider> reads project, locale, messages, and languages from the injected data — no props needed
  • Cookie Persistence — Locale preference is persisted in a configurable cookie
  • CDN-Cached — Singleton @better-i18n/core instance with shared TtlCache across requests

Installation

npm install @better-i18n/vite @better-i18n/use-intl use-intl
# or
bun add @better-i18n/vite @better-i18n/use-intl use-intl

Quick Start

1. Add the plugin to vite.config.ts

import { betterI18n } from "@better-i18n/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    betterI18n({
      project: "acme/dashboard",
      localeCookie: "locale",
    }),
    react(),
  ],
});

2. Wrap your app with the provider — no props needed

import { BetterI18nProvider, useTranslations, LocaleDropdown } from "@better-i18n/use-intl";

function App() {
  return (
    <BetterI18nProvider>
      <LocaleDropdown />
      <HomePage />
    </BetterI18nProvider>
  );
}

function HomePage() {
  const t = useTranslations("home");
  return <h1>{t("title")}</h1>;
}

That's it. The plugin injects everything the provider needs — project, locale, messages, languages, and cookie config — so you don't pass any props.

How It Works

  1. Dev server middleware detects the locale from each incoming request
  2. transformIndexHtml fetches translations from CDN and injects them as <script id="__better_i18n__" type="application/json">
  3. BetterI18nProvider reads this data synchronously on mount (via useState lazy initializer) — before first paint, zero FOUC
  4. On locale switch, the provider persists the cookie and updates the URL prefix automatically

Injected Payload

The plugin injects the following data into the HTML head:

{
  "project": "acme/dashboard",
  "locale": "tr",
  "messages": { "home": { "title": "Ana Sayfa" } },
  "languages": [{ "code": "en", "name": "English", "isDefault": true }, { "code": "tr", "name": "Turkish" }],
  "localeCookie": "locale",
  "supportedLocales": ["en", "tr"]
}

Locale Detection Priority

The plugin detects locale server-side in this order:

| Priority | Source | Example | |----------|--------|---------| | 1 | URL path segment | /tr/about → tr | | 2 | Cookie | locale=tr | | 3 | Accept-Language header | tr-TR,tr;q=0.9 → tr | | 4 | defaultLocale option | "en" |

If the detected locale is not in the project's supported locales (from CDN manifest), it falls back to defaultLocale.

Configuration

betterI18n({
  // Required
  project: "acme/dashboard",     // "org/project" format

  // Optional
  defaultLocale: "en",           // Default: "en"
  localeCookie: "locale",        // Default: "locale" — cookie name for persistence
  cdnBaseUrl: "https://...",     // Default: "https://cdn.better-i18n.com"
});

| Option | Type | Default | Description | |--------|------|---------|-------------| | project | string | — | Project identifier in "org/project" format | | defaultLocale | string | "en" | Fallback locale when none detected | | localeCookie | string | "locale" | Cookie name for persisting locale preference | | cdnBaseUrl | string | "https://cdn.better-i18n.com" | CDN base URL override |

Using with Routers

No Router (Plain Vite SPA)

Works out of the box. On locale switch, the provider calls history.replaceState to update the URL prefix (e.g., /about → /tr/about).

React Router (react-router-dom)

The provider's history.replaceState doesn't notify React Router. Add a LocaleSync component to bridge locale state with the router:

import { useEffect } from "react";
import { BrowserRouter, useNavigate, useLocation } from "react-router-dom";
import { BetterI18nProvider, useLocale } from "@better-i18n/use-intl";

function LocaleSync() {
  const { locale } = useLocale();
  const navigate = useNavigate();
  const location = useLocation();

  useEffect(() => {
    const segments = location.pathname.split("/").filter(Boolean);
    const first = segments[0];
    if (first && /^[a-z]{2}$/i.test(first) && first !== locale) {
      segments[0] = locale;
      navigate("/" + segments.join("/"), { replace: true });
    }
  }, [locale, location.pathname, navigate]);

  return null;
}

function App() {
  return (
    <BrowserRouter>
      <BetterI18nProvider>
        <LocaleSync />
        {/* your routes */}
      </BetterI18nProvider>
    </BrowserRouter>
  );
}

TanStack Router

Detected automatically. useLocaleRouter() uses TanStack Router's router.navigate() for SPA navigation — no extra setup needed.

Peer Dependencies

| Package | Version | |---------|---------| | vite | >=5.0.0 |

Documentation

Full documentation at docs.better-i18n.com/frameworks/vite

License

MIT © Better i18n