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

@gira-de/t9n-cli

v1.2.0

Published

> A tiny Node.js based CLI that provides some tools to improve all things around t9n (translation) and i18n (internationalization).

Downloads

105

Readme

T9N CLI

A tiny Node.js based CLI that provides some tools to improve all things around t9n (translation) and i18n (internationalization).

What is this for?

This cli is designed to support developers as well as translators and make their life easier. It...

  • 📝 Makes it easy to create a list of type safe translation keys.
  • 🪄 Makes it transform these translation keys into something translation agencies can work with (xlsx 🤩).
  • 🚨 Shows developers and other stakeholders if translations are missing.
  • 🛬 Allows seamless imports of new translations provided by a translation agency.

The Workflow

Everything here is built around the following workflow. Sure, use it however you like, but this was in our mind when we created it.

  1. Install this package.
  2. Put all translation keys in a file called meta.json and run t9n typedefs <filename> whenever it changes to create a typescript declaration file. Use this declaration file with your translation library to use your translation keys safe. (💡 Using Svelte? Use our Svelte Wrapper to make life even easier.)
  3. If it is time to get some actual translations, run t9n export <folderpath> to create a xlsx-sheet with all translation keys. Send this to your translation agency.
  4. Once the translation is done, import the translated xlsx with t9n import <filename> to create json files for every defined language. Like en.json, de.json,... .
  5. Repeat.

Installation

# using npm
npm install @gira-de/t9n-cli -D

# or using yarn
yarn add @gira-de/t9n-cli -D

You should also be able to use the command line tool via npx:

npx t9n

Usage

Now you need to create some files and put everything together. Here is an example (final) folder structure:

.
└── app/
    ├── src/
    │   └── t9n.ts
    └── locale/
        ├── meta.json
        ├── en.json (<-- updated by t9n cli)
        └── types.ts (<-- generated by t9n cli)
  1. Create a file called ./locale/meta.json. This json describes the structure of the actual language files. Every possible translation key as well as a initial translation needs to be described here.
{
  "pageOne": {
    "headline": "This is a fancy headline written by a developer. Don't trust this! 🦹‍♀️🦹‍♂️"
  }
}
  1. Create a file called ./locale/.json (for example de.json). This is the actual language file.
{
  "pageOne": {
    "headline": "Das ist die Überschrift von einem echten Übersetzer. Echt. 👩‍🏫👨‍🏫"
  }
}
  1. Call the CLI to generate a type definition based on the language files. This command will generate a Typescript declaration file:
npx t9n typedefs ./meta.json -o locale-types.ts
  1. Use the generated type definition in your code:
import type { TranslationArgs } from '../locale/types';

Commands

typedefs

This command will generate a Typescript declaration file (*.ts) based on the provided json file.

t9n typedefs <filename>

Flags

-o, --output <filename>     Filename/-path for the declaration file

export

This command creates a xlsx translation file based on a meta.json within a given folder. If there are additional languages files (for example de.json, en.json) within this folder, the command will put this into the resulting xlsx too.

This command currently needs some config:

// t9n.config.json
{
  "version": "0.0.1",
  "worksheetName": "Translation",
  "languages": ["meta", "de"]
};
t9n export <folderpath>

Flags

-o, --output <folderpath> Folderpath for the resulting xlsx

import

Import a translation.xlsx and create .json file out of it (like de.json, en.json,...).

t9n import <excel-input> [--output <folderpath>]

Flags

-o, --output <folderpath> Folderpath for the resulting <language>.json.

check

This command checks all .json compared to a meta.json reference within a given folder. The result will be printed to stdout.

t9n check <input>

Prints a table like this to stdout:

| (index) | __filename | translationKeys | missingTranslationKeys | coverage | missingParams | | ------- | ------------ | --------------- | ---------------------- | -------- | -------------- | | 0 | 'de' | 3 | 1 | 0.67 | [] | | 1 | 'en' | 3 | 2 | 0.33 | ['missingKey'] |