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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-translation-wizard

v1.0.3

Published

A powerful translation automation tool that scans project files and extracts strings for i18n usage in React and Next.js.

Readme

React Translation Automation Tool

A powerful Node.js script for automating the internationalization (i18n) process in React and Next applications. This tool scans your React components, extracts text content, generates translation keys, and replaces the text with translation function calls.

Features

  • Automatic Text Extraction: Finds and extracts all visible text in JSX/TSX files
  • Translation Key Generation: Creates structured translation keys based on folder and file names
  • Multi-language Support: Manages multiple language files simultaneously
  • Smart Import Handling: Adds translation imports only where needed
  • Next.js Support: Properly handles "use client" and "use server" directives
  • Configurable: Highly customizable via configuration file
  • Hook Insertion: Adds translation hooks only to main components
  • Flexible Format: Works with various translation libraries and patterns

Configuration

Create a translation.config.json file in the project root (use example.translation.config.json as a template):

{
  "srcDir": "app",
  "languages": [
    {
      "name": "en",
      "file": "messages/en.json"
    },
    {
      "name": "fr",
      "file": "messages/fr.json"
    }
  ],
  "import": {
    "functionName": "useTranslations",
    "packagePath": "next-intl",
    "statement": ""
  },
  "hook": {
    "variableName": "t",
    "functionName": "useTranslations",
    "statement": "const t = useTranslations();"
  },
  "textReplacement": {
    "format": "{t(\"$KEY\")}"
  }
}

Configuration Options

Project Paths

  • srcDir: Path to your React components directory

Languages

  • languages: Array of language configurations
    • name: Language code (e.g., "en", "fr")
    • file: Path to the JSON translation file

Translation Import

  • import.functionName: Name of the translation function to import
  • import.packagePath: Package or path to import from
  • import.statement: (Optional) Custom import statement

Translation Hook

  • hook.variableName: Variable name for translations (usually "t")
  • hook.functionName: Function name to call (should match the imported function)
  • hook.statement: (Optional) Custom hook statement

Text Replacement

  • textReplacement.format: Format for replacing text nodes (use $KEY as placeholder)

Usage

Run the script:

npx react-translation-wizard

How It Works

  1. Scanning: The script scans all JSX/TSX files in the specified source directory
  2. Text Extraction: Identifies all text nodes in the components
  3. Key Generation: Creates translation keys based on folder and file names
  4. Translation Files: Updates the primary language file with the extracted text
  5. Secondary Languages: Adds empty strings for keys in secondary language files
  6. Code Modification: Replaces text nodes with translation function calls
  7. Import Handling: Adds necessary imports for the translation function
  8. Hook Insertion: Adds translation hooks to main component functions

Example

Before:

function MyComponent() {
  return (
    <div>
      <h1>Welcome to our site</h1>
      <p>Please sign in to continue</p>
    </div>
  );
}

After:

import { useTranslation } from "@/utils/translate";

function MyComponent() {
  const { t } = useTranslation();
  return (
    <div>
      <h1>{t("components.my_component.welcome_to_our_site")}</h1>
      <p>{t("components.my_component.please_sign_in_to_continue")}</p>
    </div>
  );
}

Dependencies

  • ts-morph: TypeScript compiler API wrapper
  • fs-extra: Enhanced file system methods
  • glob: File pattern matching

Created By

⚡⚡ Kashyap Trivedi ⚡⚡