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

lgtm-translate

v0.5.11

Published

LGTM Translate SDK — build-time code transforms, runtime translation delivery, and CI/CD manifest sync

Downloads

99

Readme

lgtm-translate

Client SDK for LGTM-translate — AI-powered internationalization. One package handles build-time string extraction, runtime translation delivery, and CI/CD manifest sync.

Setup (Next.js)

1. Install

npm install lgtm-translate

2. Add the build plugin

// next.config.js
const { withLgtmTranslate } = require('lgtm-translate/plugin');

module.exports = withLgtmTranslate({
  // your existing Next.js config
});

The plugin scans JSX at build time:

  • Detects user-facing text and generates content-based IDs (project_7f3a)
  • Injects data-lgtm-translate attributes on elements
  • Extracts t() calls and @lgtm-translate annotated objects/arrays
  • Writes the lgtm-translate.json manifest

3. Wrap your app with the provider

// app/layout.tsx
import { LgtmTranslateProvider } from 'lgtm-translate';

export default function RootLayout({ children }) {
  return (
    <LgtmTranslateProvider project="my-app" defaultLocale="en">
      {children}
    </LgtmTranslateProvider>
  );
}

The provider detects the user's language, fetches translations from the LGTM-translate server, and swaps element text via data-lgtm-translate attributes.

4. Use t() for dynamic strings

import { t } from 'lgtm-translate';

// Static JSX text is auto-detected — no t() needed
<button>Cancel</button>

// Use t() for strings the AST can't trace
const msg = t("Something went wrong");
const cart = t("{count:number} items in your cart");

5. Sync manifest in CI/CD

LGTM_API_KEY=lgtm_sk_... npx lgtm-translate sync

Reads lgtm-translate.json, authenticates with the server, and uploads new/changed strings for translation.

Features

  • Auto-detection — hardcoded JSX strings and ternaries are extracted without any developer annotation
  • Content-based IDs — same text = same ID = one translation shared everywhere
  • Variable interpolation{userName} placeholders preserved across all languages
  • CLDR plural rules{count:number} triggers plural form generation for 40+ locales
  • Human overrides — AI translations are never overwritten once a human edits them
  • Text change detection — changing element text automatically generates a new ID; no manual ID management

Development

Prerequisites

  • Node.js 22+
  • npm

Install dependencies

cd sdk
npm install

Run tests

npx vitest run

Type check

npx tsc --noEmit

Build

npx tsc

Output goes to dist/.

Package Structure

sdk/
├── src/
│   ├── index.ts                  # Main exports: LgtmTranslateProvider, t(), useTranslation
│   ├── plugin/
│   │   ├── index.ts              # Plugin exports: withLgtmTranslate
│   │   ├── babel-plugin.ts       # Babel AST visitor — scans JSX, extracts strings, injects IDs
│   │   ├── id-generator.ts       # Content-based ID hashing (project prefix + CRC)
│   │   ├── manifest.ts           # Reads/writes lgtm-translate.json manifest
│   │   └── with-lgtm-translate.ts # Next.js config wrapper (adds Babel loader via webpack)
│   ├── runtime/
│   │   ├── provider.tsx          # LgtmTranslateProvider — fetches translations, swaps DOM text
│   │   ├── t.ts                  # t() function — build-time extraction + runtime lookup
│   │   ├── plurals.ts            # CLDR plural category selection
│   │   ├── interpolate.ts        # Variable interpolation ({name} → value)
│   │   ├── locale.ts             # Browser locale detection + fallback
│   │   └── id-generator-browser.ts # Browser-compatible ID generator (Web Crypto API)
│   └── cli/
│       ├── bin.ts                # CLI entry point (npx lgtm-translate <command>)
│       └── sync.ts               # Manifest upload — reads JSON, authenticates, POSTs to server
├── __tests__/
│   ├── plugin/                   # Plugin unit tests (Babel transforms, ID generation, manifest)
│   ├── runtime/                  # Runtime unit tests (provider, t(), plurals, interpolation)
│   ├── cli/                      # CLI unit tests (sync command)
│   └── exports.test.ts           # Package export validation
├── dist/                         # Compiled output (tsc)
├── package.json
├── tsconfig.json
└── vitest.config.ts

Full Spec

See docs/LGTM-translate_Shared_Translations_Spec.md for the complete product specification including ID generation rules, shared translation flow, text change handling, cleanup, caching strategy, and auth model. (Note: the spec filename retains its original name.)