Communitygithub.com

jralvarenga/better-translate

Smallest Better Translate setup for plain TypeScript, Node.js, Bun, APIs, and shared libraries.

What is better-translate?

better-translate is a Claude Code agent skill that smallest Better Translate setup for plain TypeScript, Node.js, Bun, APIs, and shared libraries.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/jralvarenga/better-translate/tree/HEAD/skills/core

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

Core Skill

Use this guide when you want the smallest possible Better Translate setup.

What this package is for

@better-translate/core is the base translation engine.

Use it when:

  • the app is plain TypeScript
  • the code runs on Node.js, Bun, or an API
  • you want one shared translator file before adding framework adapters

Smallest correct setup

Create one translator file and export it:

import { configureTranslations } from "@better-translate/core";

const en = {
  home: {
    title: "Hello",
  },
} as const;

const es = {
  home: {
    title: "Hola",
  },
} as const;

export const translator = await configureTranslations({
  availableLocales: ["en", "es"] as const,
  defaultLocale: "en",
  fallbackLocale: "en",
  messages: { en, es },
});

Keep TypeScript autocomplete available

TypeScript key autocomplete depends on the shared exported translator.

  • Keep each messages object as const
  • Export one shared translator
  • Call translator.t(...) from code that needs typed keys
import { translator } from "./i18n";

translator.t("home.title");
translator.t("home.title", { locale: "es" });

That keeps locale values and translation keys inferred from the messages you configured.

When to add another package

  • Add @better-translate/react when React components need hooks or locale switching
  • Add @better-translate/nextjs when Next.js routes or server helpers need locale awareness
  • Add @better-translate/astro when Astro requests need locale awareness
  • Add @better-translate/md when content files should follow the same locale setup

Auto-extract strings without naming keys

Use { bt: true } in any t() call to write source text directly instead of inventing a key:

t("Hello world", { bt: true });

Then run npx bt extract to generate keys automatically and rewrite the calls. See skills/cli/SKILL.md for the full setup.

Main idea

Do not create one translation system per framework.

Create one core translator first, then let adapters read from it.

Related Skills