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

@morabotti/i18n-types-generator-cli

v0.1.0

Published

Typescript type generation for i18n keys/namespaces

Readme

Typescript type generation for i18n files.

This CLI tool was used to help with type-safety while using i18n translations. Especially designed for react-i18next while using HttpApi

Install

Install as dev dependency:

npm install -g @morabotti/i18n-types-generator-cli

Usage

You can run the the cli with i18n-types-generator command. You can use nodemon to watch for changes in locales file and hot build the latest type file.

Example npm scripts:

"scripts": {
  "i18n": "i18n-types-generator -l en -p \"locales/{{lang}}/{{ns}}.json\" -o \"src/generated/translations.generated.ts\"",
  "i18n:watch": "nodemon --exec \"npm run i18n\" --watch locales"
},

CLI tool accepts following option parameters:

Options:
  --help            Show help                       [boolean]
  --version         Show version number             [boolean]
  -p, --path        Path to translations            [string] [required]
  -o, --output      Path to output file             [string] [required]
  -l, --lang        Default language                [string]
  -d, --delimiter   Delimiter between ns & key      [string] [default: ":"]

| Option | Description | Example value | Required/Optional | | --- | ----------- | ----------- | --- | | Path | Define path to source files. {{ns}} is currently required. | locales/{{lang}}/{{ns}}.json | Required | | Output | Path to generated typescript file. This file should be included in version control. | src/generated/translations.generated.ts | Required | | Lang | Default language that has the "most" values. This language will construct the types/enums. | en | Optional | | Delimiter | Delimiter for namespace mapping. | : | Optional (default: ":") |

Example with react-i18next hook

import { KeyPrefix, useTranslation, UseTranslationResponse } from 'react-i18next';
import { TranslationsMapping, Namespace } from '@generated/translations.generated';

interface ResponseContext<T extends Namespace[]>
  extends Omit<UseTranslationResponse<T, KeyPrefix<T>>, 't'> {
  t: (key: TranslationsMapping<T>, values?: Record<string, string | number>) => string;
}

export const useLanguage = <T extends Namespace[]> (
  namespaces?: T
): ResponseContext<T> => {
  return useTranslation(namespaces) as ResponseContext<T>;
};

With this custom hook, you will every single time have strongly typed paths. No more typos.

Whats being exported

All of the enum keys/types are converted to PascalCase

  • Enum Language: Collection of languages. Gotten with {{lang}} variable in cli option --path.
  • Enum Namespace: Collection of namespaces.
  • List of type keys *Keys: Keys types contain all of the key paths for specific namespace.
  • Type TranslationKey: All of the *Keys types combined.
  • Type TranslationMapping: Way to select certain *Keys with Namespace. Only Singular Namespace.
  • Type TranslationMapping<X extends Namespace[]>: Way to select multiple *Keys with list of Namespace's. If there are multiple namespaces, Keys include namespace e.g. namespace:${NamespaceKeys}.

Development

Install the bin npm install -g . Or use npm run start with npm link/npm unlink Run with i18n-types-generator -p "/locales/{{lang}}/{{ns}}.json" -o "/example.generated.ts" format or simply with npm run start

TODO

  • Unit/Type testing for generated file
  • Support for different formatting