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

easy-peasy-translation

v1.0.4

Published

Easy React Translations Library. Simple setup. Translate text on screen using JSON translation files.

Readme

React - Easy Translation

Easily add language translations to your React/Next application.

Prerequisites

This project was built using React (version 19.0.0).

Table of contents

Installation

To install the library, run:

$ npm i easy-peasy-translation

Usage

LanguageProvider

The LanuageProvider must be added to the top level of your application as it sets up the required Context.

Props:

url (Optional) - Used for remote files

| Type | Description | | ------ | ------------------------------------------------------------------------------------------------------- | | string | The url to language files directory. If not included will look in your server public "locale" directory |

files (Optional) - Used for local files

| Type | Description | | ------------------- | -------------------------------------------------------------------------- | | Array(LanguageFile) | A list of Language File objects ({name: "en", file: en}) see example below |

supported (Required)

| Type | Description | | ------------- | --------------------------- | | Array[string] | List of supported languages |

Example:

For ReactJS. The provider can be added directly to the top level.

Remote URL

import { LanguageProvider } from "easy-peasy-translation";
function main() {
  return (
    <LanguageProvider
      url="<http path to language directory>"
      supported={["en", "fr"]}
    >
      <div>...</div>
    </LanguageProvider>
  );
}
export default main;

Local Files

import { LanguageProvider } from "easy-peasy-translation";

import en from "./features/Languages/en.json";
import fr from "./features/Languages/fr.json";
function main() {
  return (
    <LanguageProvider
      files={[
        { name: "en", file: en },
        { name: "fr", file: fr },
      ]}
      supported={["en", "fr"]}
    >
      <div>...</div>
    </LanguageProvider>
  );
}
export default main;

For NextJS. The provider needs to be added from inside a client component.

function main() {
  return (
    <Lang>
      <div>...</div>
    </Lang>
  );
}
export default main;
"use client";
import React from "react";
import { LanguageProvider } from "easy-peasy-translation";

function Lang({ children }: { children: React.ReactNode }) {
  return (
    <LanguageProvider
      url="<http path to language directory>"
      supported={["en", "fr"]}
    >
      {children}
    </LanguageProvider>
  );
}
export default Lang;

Language Files

Language files are JSON files that are seperated into sections. Language files must be localed in at publicly accessable url. http://someurl.com/locale

If url is not supplied, falls back to '/Public/Locale/'

Language file names must be named based on the supported language:

Files:

  • en.json
  • fr.json

The first section for each language file MUST have the "@" section. See below for an example.

Usage:

Basic

{
  "@": {
    "key": "This is the text to be translated"
  }
}

Multiple (Pipe split)

{
  "@": {
    "key": "This is the text | to translate to that is indexed"
  }
}

Tokenized

{
  "@": {
    "key": "This is a token [$0] and some more tokens [$1] [$2]"
  }
}

Example:

en.json

{
  "@": {
    "title": "This is an English language file",
    "multiple": "This is a string | That can be indexed",
    "tokens": "This is an indexed string | With tokens [$0] [$1]"
  },
  "section1": {
    "title": "This is section one",
    "tokens": "This is a string with tokens [$0] [$1]"
  },
  "section2": {
    "title": "This is section two",
    "subtitle": "This is section two"
  }
}

useTranslation

This is the most common way to use the translation library.

Usage:

useTranslation("section");

Options:

section (Optional)

| Type | Default value | Description | | ------ | ------------- | ------------------------------------------------------- | | string | undefined | All translations will use a passed "section" as default |

Translate

Usage:

translate("@text@", "section", ["tokens"])[idx];

Options:

@text@ (Required)

| Type | value | Description | | ------ | -------- | ---------------------------------------------------------------- | | string | "@text@" | The translation key that must match the key in the language file |

section (Optional)

| Type | value | Description | | ------ | --------- | --------------------------------------------- | | string | "section" | Section of the language file this key exists. |

if "-" is passed in the section field. Looks in the current section.

tokens (Optional)

| Type | value | Description | | -------------- | -------------------- | ---------------------------------------------------------------------------- | | Array[strings] | ["token1", "token2"] | Token strings. Language matches tokens on an index. See language file above. |

Basic

translate("@title@");

Multiple (Pipe split)

translate("@multiple@")[0];
translate("@multiple@")[1];

Tokenized

translate("@tokens@", "section1", ["token1", "token2"]);

Example:

import { useTranslation } from "easy-peasy-translation";

function MyComponent() {
  const { translate: t } = useTranslation("section1"); // Switch default to Section1

  return (
    <div>
      <p>{t("@title@")}</p>
      <p>{t("@title@", "@")}</p>
      <p>{t("@multple@", "@")[1]}</p>
      <p>{t("@tokens@", "@", ["token1", "token2"])[1]}</p>
      <p>{t("@title@", "section2")}</p>
    </div>
  );
}
export default MyComponent;

Translate Group

This function can be used to translate an Array of Translation Objects

Usage:

group([{ text: "@text@", section: "section", tokens: ["tokens"] }]);

Options:

object (Required)

| Type | value | Description | | --------- | ----------------- | ------------------------------------ | | Array[{}] | [{text:"@text@"}] | Pass an array of Translation Objects |

Basic

import { useTranslation } from "easy-peasy-translation";

function MyComponent() {
  const { group: t } = useTranslation();
  const translations = t([{ text: "@title@" }, { text: "@subtitle@" }]);

  return (
    <div>
      <p>{translations.title}</p>
      <p>{translations.subtitle}</p>
    </div>
  );
}
export default MyComponent;

Multiple (Pipe split)

import { useTranslation } from "easy-peasy-translation";

function MyComponent() {
  const { group: t } = useTranslation();
  const translations = t([{ text: "@multiple@" }]);

  return (
    <div>
      <p>{translations.multiple[0]}</p>
      <p>{translations.multiple[1]}</p>
    </div>
  );
}
export default MyComponent;

Tokenized

import { useTranslation } from "easy-peasy-translation";

function MyComponent() {
  const { group: t } = useTranslation("section1");
  const translations = t([
    { text: "@tokens@", "-", ["token1", "token2"] }
  ]);

  return (
    <div>
      <p>{translations.tokens}</p>
    </div>
  );
}
export default MyComponent;

Example:

import { useTranslation } from "easy-peasy-translation";

function MyComponent() {
  const { group: t } = useTranslation("Section2");
  const translations = t([
    { text: "@title@" },
    { text: "@subtitle@" },
    { text: "@tokens@", category: "@", tokens: ["token1", "token2"] },
  ]);

  return (
    <div>
      <p>{translations.title}</p>
      <p>{translations.subtitle}</p>
      <p>{translations.tokens[0]}</p>
      <p>{translations.tokens[1]}</p>
    </div>
  );
}
export default MyComponent;

Translation

The Translation Component can also be used. This component translates @text@ tokens by passing JSX.

Options:

category (Required)

| Type | Default value | Description | | ------ | ------------- | ---------------------------------------------------------------- | | string | undefined | The translation key that must match the key in the language file |

@text@ (Required)

| Type | Default value | Description | | ------ | ------------- | ------------------------------------------------------- | | string | "" | All translations will use a passed "section" as default |

Example:

"use client";
import { Translation } from "easy-peasy-translation";

function MyComponent() {
  return (
    <div>
      <Translation category={"Section2"}>
        <h3>@title@</h3>
        <p>@subtitle@</p>
      </Translation>
    </div>
  );
}
export default MyComponent;

Versioning

  • 1.0.4
  • 1.0.2
  • 1.0.1
  • 1.0.0

Authors