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

@dima-algebras/algebras-auto-intl

v1.2.5

Published

automized i18n tool for Next.js projects

Readme

@dima-algebras/algebras-auto-intl

Automated i18n for Next.js (App Router) that:

  • Extracts user-visible strings from JSX during next dev / next build
  • Generates dictionary.json + source.json into your configured output directory
  • Rewrites components automatically to render translated text at runtime
  • Works with Webpack and Turbopack

Installation

npm i @dima-algebras/algebras-auto-intl

CLI Setup

The easiest way to set up Algebras Auto Intl in your Next.js project is using the CLI command:

Using npx (recommended for first-time setup)

npx @dima-algebras/algebras-auto-intl init

Using the installed package

After installation, you can run:

algebras-auto-intl init

Command options

You can provide configuration via command-line flags:

  • --default-locale <code> - Default locale code (e.g., en)
  • --target-locales <codes> - Comma-separated target locale codes (e.g., ru,es,fr)
  • --output-dir <path> - Output directory for intl files (default: ./src/intl)
  • --api-key <key> - Algebras AI API key (optional)
  • --api-url <url> - Algebras AI API URL (optional, default: https://platform.algebras.ai/api/v1)

Examples

# Interactive mode (will prompt for missing options)
algebras-auto-intl init

# With all options provided
algebras-auto-intl init --default-locale en --target-locales ru,es,fr --output-dir ./src/intl --api-key your_api_key_here

# Minimal setup
algebras-auto-intl init --default-locale en --target-locales ru

What the CLI does

The init command automatically:

  • ✅ Checks that you're in a Next.js project
  • ✅ Installs the package if not already installed
  • ✅ Updates next.config.ts/js/mjs with the plugin configuration
  • ✅ Creates the output directory for intl files
  • ✅ Updates .env.local with API credentials (adds empty key with comment if not provided)
  • ✅ The compiler automatically adds IntlWrapper to your layout during build

See supported languages: https://platform.algebras.ai/translation/translate

Quickstart (Next.js App Router)

1) Add the plugin to next.config.ts

import type { NextConfig } from 'next';
import autoIntl, { LanguageCode } from '@dima-algebras/algebras-auto-intl';

const nextConfig: NextConfig = autoIntl({
  defaultLocale: LanguageCode.en,
  targetLocales: [LanguageCode.ru],
  outputDir: './src/intl',
  includeNodeModules: false,
  // Optional: override env vars (not recommended for production)
  // translationApiKey: process.env.ALGEBRAS_API_KEY,
  // translationApiUrl: process.env.ALGEBRAS_API_URL,
})({
  reactStrictMode: true,
});

export default nextConfig;

2) (Optional) Add a locale switcher

'use client';

import LocaleSwitcher from '@dima-algebras/algebras-auto-intl/runtime/client/components/LocaleSwitcher';

export function Header() {
  return (
    <header>
      <LocaleSwitcher />
    </header>
  );
}

Programmatic locale management

If you need to manage locales programmatically without using the LocaleSwitcher component, you can use the useAlgebrasIntl hook:

'use client';

import { useAlgebrasIntl } from '@dima-algebras/algebras-auto-intl/runtime';
import { useRouter } from 'next/navigation';

export function CustomLocaleButton() {
  const { locale, setLocale, getLocales } = useAlgebrasIntl();
  const router = useRouter();
  const availableLocales = getLocales();

  const handleLocaleChange = (newLocale: string) => {
    setLocale(newLocale);
    // Refresh the page to update server components with new locale
    router.refresh();
  };

  return (
    <div>
      <p>Current locale: {locale}</p>
      {availableLocales.map((loc) => (
        <button
          key={loc}
          onClick={() => handleLocaleChange(loc)}
          disabled={loc === locale}
        >
          {loc}
        </button>
      ))}
    </div>
  );
}

How it works:

  • setLocale(locale) - Updates the locale and automatically sets a cookie: locale=${locale}; path=/; max-age=31536000; SameSite=Lax
  • getLocales() - Returns an array of all available locales from your dictionary
  • locale - Current active locale
  • router.refresh() - Required to refresh server components after locale change (from next/navigation)

Server-side locale access:

On the server, you can read the locale from cookies:

import { cookies } from 'next/headers';

export async function ServerComponent() {
  const cookieStore = await cookies();
  const locale = cookieStore.get('locale')?.value || 'en';
  // Use locale...
}

Translation Provider (Algebras AI) — optional

If you provide ALGEBRAS_API_KEY, the generator translates via Algebras AI. If not provided, it falls back to mock translations.

Create a .env:

ALGEBRAS_API_KEY=your_api_key_here
ALGEBRAS_API_URL=https://platform.algebras.ai/api/v1

Output files

The plugin writes generated files to outputDir (default is ./src/intl):

  • dictionary.json: runtime dictionary consumed by IntlWrapper
  • source.json: extracted scope map used by the injector/translator

Selective translation of attributes / props (opt-in)

By default, the compiler does not translate JSX props or HTML attributes. You can opt-in per element using JSX comments placed immediately above the element.

Translate a single attribute

{
  /* @algb-translate-attr-title */
}
<button title="Click to send">Send</button>;

Supports hyphenated attributes too:

{
  /* @algb-translate-attr-aria-label */
}
<button aria-label="Close dialog">×</button>;

Translate multiple attributes on the same element

{
  /* @algb-translate-attrs-[title,placeholder,aria-label] */
}
<input title="Hello" placeholder="Enter text" aria-label="Search" />;

Translate selected props on a component

{
  /* @algb-translate-props-[title,description] */
}
<ProductCard title="New" description="Limited offer" ref={ref} />;

Only the listed props are considered; everything else is ignored.

Notes / troubleshooting

  • Monorepo / file: dependency: Next.js runs the package from dist/. If you change this package locally, run npm run build in the package so dist/ is updated.
  • Dev cache: if you see stale behavior, restart dev and delete .next/ in your app.