SkillAtlasSkill 详情

core

The type-safe i18n toolkit for TypeScript

审核状态:已审核Quality 80Security 92

复制安装命令

用 Codex 或 Claude 安装复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它先审查 Skill 页面再帮你安装。

复制前请先查看来源、License 和安全提示。

项目 README

来源文件:README.md

抓取于 2026年7月29日
Better Translate

Better Translate

The type-safe i18n toolkit for TypeScript
better-translate.com »

Docs · Quick Start · Issues

npm version npm downloads License CI

About

Better Translate is a type-safe i18n toolkit for TypeScript. Write your translation config once and it works across Next.js, Astro, React, TanStack Router, Node, Bun, and Expo — same API, same types, same experience everywhere. A built-in CLI generates translated locale files using any AI provider or local Ollama models, so you ship multilingual apps without manual work.

Why Better Translate

i18n in TypeScript projects is usually an afterthought. You wire up a library, scatter translation keys across your codebase, and cross your fingers that nothing drifts out of sync. Better Translate treats translations as first-class TypeScript: keys are inferred, interpolations are typed, and the CLI handles generation so you never write a locale file by hand again.

Quick Start

# Install the CLI globally
npm install -g @better-translate/cli

# Install the core package (or a framework adapter)
npm install @better-translate/core

Create a better-translate.config.ts at the root of your project:

import { createGoogleGenerativeAI } from "@ai-sdk/google";
import { defineConfig } from "@better-translate/cli";

const google = createGoogleGenerativeAI({ apiKey: process.env.GOOGLE_API_KEY });

export default defineConfig({
  model: google("gemini-2.0-flash"),
  defaultLocale: "en",
  targetLocales: ["es", "fr", "ja"],
  messagesDir: "./messages",
});

Extract source strings and generate all locale files:

bt extract   # scans source files and updates messages/en.json
bt generate  # translates into every target locale

Use translations in your app:

import { configureTranslations, createTranslationHelpers } from "@better-translate/core";
import en from "./messages/en.json";
import es from "./messages/es.json";

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

const { t } = createTranslationHelpers(translator);

t("hero.title")                        // fully typed, autocomplete works
t("hero.greeting", { params: { name } }) // interpolation is type-checked
t("hero.title", { locale: "es" })      // per-call locale override

Framework Support

Framework / RuntimePackage
Next.js (App Router)@better-translate/nextjs
Astro@better-translate/astro
React@better-translate/react
TanStack Router / Start@better-translate/tanstack-router
Expo (React Native)@better-translate/react
Node.js@better-translate/core
Bun@better-translate/core
Markdown / MDX@better-translate/md

Key Features

  • Type-safe by default — Full TypeScript inference on translation keys and interpolation variables. Typos and missing keys are compile errors.
  • Autocomplete everywhere — Your editor knows every key in your messages object from the moment you type t(".
  • Same config, every environment — Write once, run anywhere. Next.js, Astro, React, Node — identical API.
  • CLI toolchain — bt extract pulls source strings out of your code. bt generate calls your AI model and writes every locale file.
  • Bring your own model — Pass any AI SDK language model to the config: OpenAI, Gemini, Claude, or a local Ollama model.
  • Locale switching — Switch locales at runtime without a page reload. Per-call overrides render any locale on demand.
  • RTL support — Built-in right-to-left layout utilities for Arabic, Hebrew, and other RTL languages.

Documentation

Contributing

Better Translate is free and open source under the MIT License. Contributions are welcome.

Security

If you discover a security vulnerability, please see SECURITY.md for responsible disclosure instructions.

License

MIT

其他

低风险

  • 来源需自行核对维护者身份。
  • 包含脚本或命令调用,安装前请复核。
  • 未检测到明显外部权限要求。
  • 未检测到高风险命令。
  • 扫描发现:0 条。

Codex — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/jralvarenga/better-translate.git
  3. 将 "skills/core" 文件夹复制到 Codex 的 skills 目录中。
  4. 重启 Codex 让新的 skill 生效。

Codex — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Codex 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Codex 让新的 skill 生效。

Claude Code — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/jralvarenga/better-translate.git
  3. 将 "skills/core" 文件夹复制到 Claude Code 的 skills 目录中。
  4. 重启 Claude Code 让新的 skill 生效。

Claude Code — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Claude Code 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Claude Code 让新的 skill 生效。

Cursor — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/jralvarenga/better-translate.git
  3. 将 "skills/core" 文件夹复制到 Cursor 的 skills 目录中。
  4. 重启 Cursor 让新的 skill 生效。

Cursor — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Cursor 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Cursor 让新的 skill 生效。

GitHub Copilot — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/jralvarenga/better-translate.git
  3. 将 "skills/core" 文件夹复制到 GitHub Copilot 的 skills 目录中。
  4. 重启 GitHub Copilot 让新的 skill 生效。

GitHub Copilot — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 GitHub Copilot 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 GitHub Copilot 让新的 skill 生效。

Windsurf — Git Clone 安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 克隆仓库:git clone https://github.com/jralvarenga/better-translate.git
  3. 将 "skills/core" 文件夹复制到 Windsurf 的 skills 目录中。
  4. 重启 Windsurf 让新的 skill 生效。

Windsurf — 手动复制安装

  1. 安装前请先查看来源仓库和风险报告。
  2. 从源仓库下载 SKILL.md 及相关文件。
  3. 在 Windsurf 的 skills 目录中创建新文件夹。
  4. 将所有 skill 文件复制到新文件夹中。
  5. 重启 Windsurf 让新的 skill 生效。
查看 SKILL.md 原文
name: core
description: Smallest Better Translate setup for plain TypeScript, Node.js, Bun, APIs, and shared libraries.

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.

发现问题?提交给管理员复核

评分:

评论 (0)

暂无评论,成为第一个评论者吧!