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 🙏

© 2025 – Pkg Stats / Ryan Hefner

teatag

v0.0.1-alpha.10

Published

Dead simple i18n solution in Vanilla JS, React, TS(X), and Astro

Downloads

3,585

Readme

teatag

A dead simple i18n solution for Vanilla JS, React, TypeScript, and Astro

Features

  • Dead simple: Just use t tag - no complex setup, Babel, SWC settings are required
  • Framework agnostic: Works with React, Astro, Vanilla JS, and more
  • YAML-based: Human-readable translation files
  • Fast extraction: CLI tool extracts all translatable strings using regular expressions

Installation

npm install teatag
# or
pnpm add teatag
# or
yarn add teatag

Quick Start

1. Write your code with t tagged template literals

import { getTranslation } from 'teatag'

function getLocale() {
  // Get locale from your app (environment, user preference, etc.)
  return 'en'
}

const t = getTranslation(getLocale())
const name = 'John'

console.log(t`Hello, ${name}!`)
console.log(t`Welcome to our app!`)

2. Extract translatable strings

npx teatag extract --lang ja

This creates a locales/ja.yaml file with extracted strings:

'Hello, ${name}!': ''
'Welcome to our app!': ''

3. Add your translations

Edit the generated YAML file:

'Hello, ${name}!': 'こんにちは、${name}!'
'Welcome to our app!': '私たちのアプリへようこそ!'

4. Load translations and use them

Node.js:

import { addLocale, getTranslation } from 'teatag'
import fs from 'fs'

// Load translations
const jaTranslations = fs.readFileSync('./locales/ja.yaml', 'utf-8')
addLocale('ja', jaTranslations)

// Use translations
const t = getTranslation('ja')
const name = 'John'

console.log(t`Hello, ${name}!`) // Output: こんにちは、John!
console.log(t`Welcome to our app!`) // Output: 私たちのアプリへようこそ!

Frontend (Vite):

Configure your vite.config.ts to handle YAML files:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'

export default defineConfig({
  plugins: [react()],
  assetsInclude: ['**/*.yaml'],
  resolve: {
    alias: {
      'src/': `${__dirname}/src/`,
      'locales/': `${__dirname}/locales/`,
    },
  },
})

Then import and use translations:

import { addLocale, getTranslation } from 'teatag'
import ja from 'locales/ja.yaml?raw'

// Load translations
addLocale('ja', ja)

// Use translations
const t = getTranslation('ja')
const name = 'John'

console.log(t`Hello, ${name}!`) // Output: こんにちは、John!
console.log(t`Welcome to our app!`) // Output: 私たちのアプリへようこそ!

CLI Commands

The CLI automatically extracts strings from:

  • .ts - TypeScript files
  • .tsx - TypeScript React files
  • .js - JavaScript files
  • .jsx - JavaScript React files
  • .astro - Astro components

Examples:

# Extract to Japanese
npx teatag extract --lang ja

# Custom source and output directories
npx teatag extract --lang fr --src ./app --out ./translations

You can view full help text in the command line:

$ pnpm teatag extract --help

Usage: teatag extract [options]

Extract translatable strings from source code

Options:
  --lang <language>  Target language code (e.g., ja, fr, es)
  --src <directory>  Source directory to scan (default: "./src")
  --out <directory>  Output directory for locale files (default: "./locales")
  -h, --help         display help for command

Check out the examples/ directory for more examples.

API Reference

getTranslation(locale: string)

Returns a template literal function for the specified locale.

const t = getTranslation('ja')
const result = t`Hello, ${name}!`

addLocale(locale: string, yamlContent: string)

Loads translations from YAML content for the specified locale.

import fs from 'fs'

const yamlContent = fs.readFileSync('./locales/ja.yaml', 'utf-8')
addLocale('ja', yamlContent)

Why Yaml?

teatag uses .yaml over .po for

  • Translator readability
  • No need for complex extract/transform/conversion between po<->json
  • Easier to port to other languages

License

MIT