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

next-i18n-auto

v1.0.1

Published

Automatic multilingual support for Next.js projects without manual text wrapping

Downloads

183

Readme

next-i18n-auto

Automatic multilingual support for Next.js projects without manual text wrapping or translation functions.

Features

  • Zero Code Changes: Write normal JSX like <h1>Welcome</h1> - no wrapping or translation functions needed
  • Automatic Text Extraction: Scans your components and extracts all text nodes at build time
  • Automatic Translation: Translates all text to target languages using LibreTranslate
  • Runtime Language Switching: Switch languages dynamically in the browser
  • Type-Safe: Full TypeScript support
  • Simple Integration: Just add a postbuild script to your package.json

Installation

npm install next-i18n-auto

Quick Start

1. Add LibreTranslate API Key

Create .env.local in your project root:

LIBRETRANSLATE_API_KEY=your_api_key_here

Get a free API key from LibreTranslate.

2. Add Postbuild Script

In your package.json:

{
  "scripts": {
    "build": "next build",
    "postbuild": "next-i18n-auto --languages fr,es,de && cp -r locales public/"
  }
}

Windows users, use:

"postbuild": "next-i18n-auto --languages fr,es,de && xcopy /E /I locales public\locales"

3. Initialize in Your App

'use client';

import { useEffect } from 'react';
import { initializeI18n } from 'next-i18n-auto/client';

export default function RootLayout({ children }) {
  useEffect(() => {
    initializeI18n({ defaultLanguage: 'en' });
  }, []);

  return <html><body>{children}</body></html>;
}

4. Create Language Switcher

'use client';

import { useLanguage } from 'next-i18n-auto/client';

export default function LanguageSwitcher() {
  const { language, switchLanguage, isLoading } = useLanguage();

  return (
    <div>
      <button onClick={() => switchLanguage('en')} disabled={isLoading}>
        English
      </button>
      <button onClick={() => switchLanguage('fr')} disabled={isLoading}>
        Français
      </button>
    </div>
  );
}

5. Write Normal JSX

export default function Hero() {
  return (
    <div>
      <h1>Welcome to our website</h1>
      <p>We provide amazing services</p>
      <button>Get Started</button>
    </div>
  );
}

After build, this becomes:

<h1 data-i18n="hero_a3c5f1d2">Welcome to our website</h1>

CLI Options

next-i18n-auto [options]
  • --languages <codes> - Target language codes (required)
  • --source <code> - Source language (default: en)
  • --output <dir> - Output directory (default: locales)
  • --root <dir> - Project root directory
  • --api-url <url> - Custom LibreTranslate API URL

API Reference

React Hooks

import { useLanguage, usePreloadLanguages } from 'next-i18n-auto/client';

const { language, switchLanguage, isLoading } = useLanguage();
usePreloadLanguages(['fr', 'es', 'de']);

Vanilla JavaScript

import { initializeI18n, switchLanguage, getCurrentLanguage } from 'next-i18n-auto/client';

await initializeI18n({ localesPath: '/locales' });
await switchLanguage('fr');
const lang = getCurrentLanguage();

How It Works

Build Time

  1. Scans JSX/TSX files in your project
  2. Extracts all text nodes
  3. Generates unique IDs (e.g., componentName_hash)
  4. Adds data-i18n attributes automatically
  5. Translates texts using LibreTranslate
  6. Creates JSON files per language

Runtime

  1. Loads selected language JSON
  2. Finds elements with data-i18n attributes
  3. Updates text content
  4. Persists selection in localStorage

Documentation

See DOCUMENTATION.md for detailed documentation.

See EXAMPLE.md for complete integration examples.

Supported Languages

Any language supported by LibreTranslate: en, fr, es, de, it, pt, ru, zh, ja, ko, ar, and more...

Limitations

  • Text must be directly in JSX (not in variables)
  • Dynamic template strings with variables won't be translated
  • Very short text (< 2 chars) is skipped
  • Numbers/symbols-only text is skipped

Troubleshooting

Translations not working:

  • Check LIBRETRANSLATE_API_KEY in .env.local
  • Verify locales/ copied to public/locales/
  • Check postbuild script ran successfully

Text not extracted:

  • Ensure text is directly in JSX
  • Check files are in scanned directories
  • Verify .tsx or .jsx extension

License

MIT

Contributing

Contributions welcome! Open an issue or PR on GitHub.