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-localize

v1.0.1

Published

A React hook for internationalization with dynamic locale loading and cookie persistence

Readme

next-localize

A React hook for internationalization with dynamic locale loading and cookie persistence. Perfect for Next.js applications.

Features

  • 🌍 Dynamic locale loading - add your own translation files
  • 🍪 Cookie persistence - language preference saved automatically
  • 🔄 Automatic fallback to English if no language is stored
  • 📦 Easy setup with optional locales folder creation
  • 🎯 TypeScript support
  • ⚡ Built with Zustand for optimal performance

Installation

npm install next-localize

During installation, you'll be prompted to create a locales folder with example files. You can skip this if you already have your locale files.

Setup

1. Create Locale Files

Create a locales folder in your project root and add your translation files:

locales/
  en.json
  fr.json
  jp.json

Example en.json:

{
  "welcome": "Hello, World! Welcome to next-localize"
}

2. Initialize Translations

In your app (e.g., app/layout.tsx or _app.tsx):

import { initTranslations } from 'next-localize';
import en from './locales/en.json';
import fr from './locales/fr.json';
import jp from './locales/jp.json';

// Recommended: Initialize all translations at once
initTranslations({
  en,
  fr,
  jp,
});

// Alternative: Add locales individually
import { useLangStore } from 'next-localize';
useLangStore.getState().addLocale('en', en);
useLangStore.getState().addLocale('fr', fr);
useLangStore.getState().addLocale('jp', jp);

3. Use the Hook

import { useTranslate } from 'next-localize';

function MyComponent() {
  const Translate = useTranslate();

  return (
    <div>
      <h1>
        {Translate(
          "Hello, World! Welcome to next-localize",
          "welcome"
        )}
      </h1>
    </div>
  );
}

API

useTranslate()

Returns a translation function that takes:

  • defaultText: Fallback text if translation is not found
  • key: Dot-notation path to the translation (e.g., "Auth.SignupForm.createAnAccount")

useLangStore

Zustand store for managing language state:

import { useLangStore } from 'next-localize';

// Get current language
const lang = useLangStore((s) => s.lang);

// Change language (automatically saved to cookies)
useLangStore.getState().setLang('fr');

// Add a new locale
useLangStore.getState().addLocale('es', spanishTranslations);

// Set all translations
useLangStore.getState().setTranslations({
  en: englishTranslations,
  fr: frenchTranslations,
});

Cookie Management

The package automatically:

  • Saves the selected language to cookies when changed
  • Loads the language from cookies on page load
  • Falls back to English if no cookie is found

Cookie name: use-translate-lang

Next.js Integration

The hook automatically detects the lang parameter from Next.js routes:

// If your route is /[lang]/page, it will use that lang
// Otherwise, it falls back to the cookie or 'en'

License

MIT