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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ttoss/i18n-cli

v0.7.22

Published

**@ttoss/i18n-cli** is a CLI to [extract](https://formatjs.io/docs/getting-started/message-extraction) and [compile](https://formatjs.io/docs/getting-started/message-distribution) translations from your code. It implements [FormatJS Application Workflow](

Downloads

17

Readme

@ttoss/i18n-cli

@ttoss/i18n-cli is a CLI to extract and compile translations from your code. It implements FormatJS Application Workflow.

This package is part of the ttoss ecosystem, so it simplifies the process of extracting and compiling translations of your application and all ttoss packages that it uses. For example, if your application uses the @ttoss/react-i18n, @ttoss/i18n-cli will extract and compile the translations of this package as well.

:::note You should declare your messages as describe in the FormatJS documentation. :::

Installation

pnpm add @ttoss/i18n-cli --dev

Setup

Add this script to your package.json

{
  "scripts": {
    "i18n": "ttoss-i18n"
  }
}

Add to your .gitignore:

i18n/compiled/
i18n/missing/

Usage

Extract only:

pnpm i18n --no-compile # ttoss-i18n --no-compile

This command extracts translations from your code but doesn't compile them. And created a new path (i18n/lang/en.json) if doesn't exists with extracted translations. As followed below:

  • 📂 i18n
    • 📂 lang
      • 📄 en.json
// i18n/lang/en.json
{
  "0XOzcH": {
    "defaultMessage": "My title page",
    "description": "Page title"
  }
}

To translate your text, you only need to duplicate the file i18n/lang/en.json to your new language and translate it, as followed below:

// i18n/lang/pt-BR.json
{
  "0XOzcH": {
    "defaultMessage": "Título da minha página",
    "description": "Título da página"
  }
}

en is the default language, so you don't need to create a file for it. But you need to create a file for each language you want to translate.

Extract and compile:

pnpm i18n # ttoss-i18n

This command extracts translations from your code and compiles them into a usable format. And create a new path (i18n/compiled/LANG.json and i18n/missing/LANG.json) if doesn't exists with compiled translations based in all of the files on path i18n/lang. As followed below:

  • 📂 i18n
    • 📂 compiled
      • 📄 en.json
      • 📄 pt-BR.json
    • 📂 lang
      • 📄 en.json
      • 📄 pt-BR.json
    • 📂 missing
      • 📄 en.json
      • 📄 pt-BR.json

i18n/compiled/en.json

// i18n/compiled/en.json
{
  "0XOzcH": [
    {
      "type": 0,
      "value": "My title page"
    }
  ]
}

i18n/compiled/pt-BR.json

// i18n/compiled/pt-BR.json
{
  "0XOzcH": [
    {
      "type": 0,
      "value": "Título da minha página"
    }
  ]
}

The i18n/missing folder contains all the translations that are missing in the i18n/lang/LANG.json file, compared with i18n/lang/en.json. This folder is useful to know which translations are missing in your application.

Ignoring ttoss packages:

pnpm i18n --ignore-ttoss-packages # ttoss-i18n --ignore-ttoss-packages

This command extracts and compiles translations, ignoring translations from all ttoss packages, if you have them installed in your project.