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

@harjs/translation

v1.0.1

Published

A simple, lightweight and type-safe translation manager for JavaScript and TypeScript applications.

Readme

@harjs/translation

A simple, lightweight, and type-safe translation manager for JavaScript and TypeScript applications. Works perfectly with React, Next.js (App Router / Pages Router), and supports dynamic string formatting.

npm
version npm
downloads license bundle
size

Features

  • React & Next.js Ready: Fully compatible with Client Components ("use client").
  • Type-Safe: Full TypeScript support for your translation keys with IntelliSense and auto-completion.
  • Zero External Dependencies: Lightweight and optimized for performance.
  • Dynamic Formatting: Seamlessly inject dynamic values into translation strings using {0}, {1}, and other placeholders.

Installation

npm install @harjs/translation

Usage Guide

1. Define Your Translations and Types

Create your dictionary files and define a base type to ensure type safety across your application.

locales/tr.ts

export const tr = {
  welcome: "Hoş geldiniz, {0}!",
  logout: "Çıkış Yap",
  items_count: "Sepetinizde {0} adet {1} var.",
};

export type BaseLocale = typeof tr;

locales/en.ts

import type { BaseLocale } from "./tr";

export const en: Partial<BaseLocale> = {
  welcome: "Welcome, {0}!",
  logout: "Logout",
  items_count: "You have {0} {1} in your cart.",
};

locales/index.ts

import { tr } from "./tr";
import { en } from "./en";

export const translations = {
  tr,
  en,
};

2. Set Up the LanguageProvider

Wrap your application with LanguageProvider to manage the active language globally.

Next.js Example (app/layout.tsx)

import { LanguageProvider } from "@harjs/translation";

export default function RootLayout({ children }: { children: React.ReactNode }) {
  const currentLang = "tr"; // Retrieve from cookies, URL parameters, or state.

  return (
    <html lang={currentLang}>
      <body>
        <LanguageProvider language={currentLang}>{children}</LanguageProvider>
      </body>
    </html>
  );
}

3. Use in Components

Use useLanguage to access the current language and useTranslation to perform type-safe translations.

"use client";

import React from "react";
import { useLanguage, useTranslation } from "@harjs/translation";
import { translations } from "./locales";
import type { BaseLocale } from "./locales/tr";

export default function ProfileComponent() {
  const currentLang = useLanguage();

  const { t } = useTranslation<BaseLocale>(currentLang, translations);

  return (
    <div>
      <h1>{t("welcome", "Kaan")}</h1>
      <p>{t("items_count", 3, "products")}</p>
      <button>{t("logout")}</button>
    </div>
  );
}

API Reference

<LanguageProvider language={string | undefined} />

A React Context provider that stores and exposes the active language code ("tr", "en", etc.).

Props

| Prop | Type | Description | | ---------- | --------------------- | ----------------------------------- | | language | string \| undefined | The currently active language code. |

useLanguage()

Returns the current language code defined by LanguageProvider.

Return Type

string | undefined;

Example

const currentLanguage = useLanguage();

useTranslation<TBaseLocale>(currentLanguage, translations)

Merges translation dictionaries and returns a type-safe translation function.

Parameters

currentLanguage
string | undefined;

The active language code, typically provided by useLanguage().

translations
Record<string, Record<string, any>>;

An object containing your translation dictionaries.

Returns

{
  t: (key, ...args) => string;
  currentLanguage: string | undefined;
}
t(key, ...args)

Returns the translated string for the specified key and replaces placeholders ({0}, {1}, etc.) with the provided arguments.

Examples
t("logout");
// Output: "Logout"

t("welcome", "Kaan");
// Output: "Welcome, Kaan!"

t("items_count", 3, "products");
// Output: "You have 3 products in your cart."
currentLanguage
const { currentLanguage } = useTranslation(language, translations);

License

MIT License