i18n-patterns — personal-website i18n-patterns, shiqingqi.com, community, personal-website, ide skills, resume, typescript, Claude Code, Cursor, Windsurf

v1.0.0

关于此技能

非常适合需要使用 t() 函数进行高级内联翻译的多语言代理。 Internationalization (i18n) patterns using inline t() calls with compile-time Babel transformation. Use when adding or modifying translated text, working with locales, creating new pages or components that need translations, using the t() function, mentioning i18n, translations, locale switching, useLocale, setLocale, or when the user asks about how translations work in this project. Also use when working with the i18n codegen pipeline, Babel plugin, or generated translation bundles.

# 核心主题

QingqiShi QingqiShi
[4]
[1]
更新于: 3/22/2026

Killer-Skills Review

Decision support comes first. Repository text comes second.

Reference-Only Page Review Score: 6/11

This page remains useful for operators, but Killer-Skills treats it as reference material instead of a primary organic landing page.

Original recommendation layer Concrete use-case guidance Explicit limitations and caution
Review Score
6/11
Quality Score
36
Canonical Locale
en
Detected Body Locale
en

非常适合需要使用 t() 函数进行高级内联翻译的多语言代理。 Internationalization (i18n) patterns using inline t() calls with compile-time Babel transformation. Use when adding or modifying translated text, working with locales, creating new pages or components that need translations, using the t() function, mentioning i18n, translations, locale switching, useLocale, setLocale, or when the user asks about how translations work in this project. Also use when working with the i18n codegen pipeline, Babel plugin, or generated translation bundles.

核心价值

赋予代理商使用 t() 函数进行无缝国际化的能力,生成基于哈希的查找以对 JSON 包进行查找,并利用 Babel 插件进行自动运行时选择,支持使用 JSON 等协议的服务器和客户端组件。

适用 Agent 类型

非常适合需要使用 t() 函数进行高级内联翻译的多语言代理。

赋予的主要能力 · i18n-patterns

使用 t() 函数进行内联内容翻译以支持多语言
生成基于哈希的查找以实现高效的翻译检索
使用 Babel 插件自动选择运行时以支持服务器和客户端组件

! 使用限制与门槛

  • 需要 Babel 插件进行编译时转换
  • 仅限于 JSON 包进行翻译数据存储

Why this page is reference-only

  • - Current locale does not satisfy the locale-governance contract.
  • - The underlying skill quality score is below the review floor.

Source Boundary

The section below is supporting source material from the upstream repository. Use the Killer-Skills review above as the primary decision layer.

实验室 Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

常见问题与安装步骤

以下问题与步骤与页面结构化数据保持一致,便于搜索引擎理解页面内容。

? FAQ

i18n-patterns 是什么?

非常适合需要使用 t() 函数进行高级内联翻译的多语言代理。 Internationalization (i18n) patterns using inline t() calls with compile-time Babel transformation. Use when adding or modifying translated text, working with locales, creating new pages or components that need translations, using the t() function, mentioning i18n, translations, locale switching, useLocale, setLocale, or when the user asks about how translations work in this project. Also use when working with the i18n codegen pipeline, Babel plugin, or generated translation bundles.

如何安装 i18n-patterns?

运行命令:npx killer-skills add QingqiShi/shiqingqi.com/i18n-patterns。支持 Cursor、Windsurf、VS Code、Claude Code 等 19+ IDE/Agent。

i18n-patterns 适用于哪些场景?

典型场景包括:使用 t() 函数进行内联内容翻译以支持多语言、生成基于哈希的查找以实现高效的翻译检索、使用 Babel 插件自动选择运行时以支持服务器和客户端组件。

i18n-patterns 支持哪些 IDE 或 Agent?

该技能兼容 Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer。可使用 Killer-Skills CLI 一条命令通用安装。

i18n-patterns 有哪些限制?

需要 Babel 插件进行编译时转换;仅限于 JSON 包进行翻译数据存储。

安装步骤

  1. 1. 打开终端

    在你的项目目录中打开终端或命令行。

  2. 2. 执行安装命令

    运行:npx killer-skills add QingqiShi/shiqingqi.com/i18n-patterns。CLI 会自动识别 IDE 或 AI Agent 并完成配置。

  3. 3. 开始使用技能

    i18n-patterns 已启用,可立即在当前项目中调用。

! 参考页模式

此页面仍可作为安装与查阅参考,但 Killer-Skills 不再把它视为主要可索引落地页。请优先阅读上方评审结论,再决定是否继续查看上游仓库说明。

Imported Repository Instructions

The section below is supporting source material from the upstream repository. Use the Killer-Skills review above as the primary decision layer.

Supporting Evidence

i18n-patterns

安装 i18n-patterns,这是一款面向AI agent workflows and automation的 AI Agent Skill。支持 Claude Code、Cursor、Windsurf,一键安装。

SKILL.md
Readonly
Imported Repository Instructions
The section below is supporting source material from the upstream repository. Use the Killer-Skills review above as the primary decision layer.
Supporting Evidence

Internationalization (i18n)

How It Works

Translations are written inline using the t() function. A Babel plugin transforms these calls at compile time into hash-based lookups against generated JSON bundles. The same t() API works in both server and client components — the Babel plugin selects the correct runtime automatically.

Source: t({ en: "Hello", zh: "你好" })
  ↓ Babel plugin
Server: __i18n_lookup("a8cfb50c")   — reads from server JSON bundle
Client: useI18nLookup("a8cfb50c")  — reads from React context (hook)

Supported Locales

  • en — English
  • zh — Chinese

Defined as SupportedLocale in src/types.ts. Routes use [locale] parameter: /en/about, /zh/about.

The t() Function

Import from #src/i18n.ts. Pass an object with en and zh string literal properties:

tsx
1import { t } from "#src/i18n.ts"; 2 3// Plain text 4t({ en: "Hello", zh: "你好" }); 5 6// With HTML markup — returns ReactNode instead of string 7t( 8 { en: "<strong>Bold text</strong>", zh: "<strong>粗体文字</strong>" }, 9 { parse: true }, 10);

Both en and zh values must be string literals — no variables, template literals, or expressions. The codegen and Babel plugin rely on statically extracting these at build time.

Supported HTML tags in { parse: true } mode: <strong>, <em>, <b>, <i>, <p>.

Server Components

Use t() directly. No special setup needed — the Babel plugin handles everything:

tsx
1import { t } from "#src/i18n.ts"; 2 3export default function Page() { 4 return <h1>{t({ en: "Welcome", zh: "欢迎" })}</h1>; 5}

For page files (page.tsx under [locale]), the Babel plugin auto-injects setLocale() at the top of the default export function. You do not need to manually call setLocale or accept params — the plugin makes the function async, reads params.locale, and calls setLocale(validateLocale(params.locale)) for you.

Layout files that need the locale for other purposes (e.g. generateMetadata, routing logic) should still read params manually since they have non-i18n reasons to do so.

Client Components

Use t() identically — the Babel plugin detects "use client" and swaps in client-specific lookup functions that read from React context:

tsx
1"use client"; 2 3import { t } from "#src/i18n.ts"; 4 5export function SearchButton() { 6 return <button>{t({ en: "Search", zh: "搜索" })}</button>; 7}

Client translations are provided automatically. The codegen generates a manifest mapping page/layout files to their client translation bundles. The Babel plugin reads this manifest and auto-wraps the default export's return value with <ClientTranslationsProvider>, so client components receive translations without any manual wiring.

Getting the Locale in Client Components

Use the useLocale() hook when you need the locale value itself (not for translations):

tsx
1"use client"; 2 3import { useLocale } from "#src/hooks/use-locale.ts"; 4 5export function LocaleAwareComponent() { 6 const locale = useLocale(); 7 const formatter = new Intl.NumberFormat(locale); 8 return <span>{formatter.format(1234)}</span>; 9}

Generating Localized URLs

tsx
1import { getLocalePath } from "#src/utils/pathname.ts"; 2 3getLocalePath("/about", locale); // → "/en/about" or "/zh/about"

Build Pipeline

Codegen (pnpm codegen:i18n)

The codegen script in tooling/i18n-codegen/ does:

  1. Extracts all t() calls from source files via AST parsing
  2. Generates global JSON bundles: src/_generated/i18n/translations.{en,zh}.json
  3. Traces client component imports from each page/layout entry point
  4. Generates per-page client bundles: src/_generated/i18n/client/{name}.{en,zh}.json
  5. Generates loader modules: src/_generated/i18n/client-loaders/{name}.ts
  6. Generates manifest: src/_generated/i18n/manifest.json

Run codegen after adding/changing any t() call, or the Babel plugin won't find the translation key at runtime.

Babel Plugin (tooling/i18n-babel-plugin/)

Runs at compile time (both dev and build). Transforms:

  • t({en, zh})__i18n_lookup(key) (server) or useI18nLookup(key) (client)
  • t({en, zh}, { parse: true })__i18n_lookupParse(key) or useI18nLookupParse(key)
  • Auto-injects setLocale for page files with t() calls
  • Auto-wraps returns with <ClientTranslationsProvider> for manifest entries

Common Patterns

Adding Translations to a New Page

tsx
1// src/app/[locale]/my-page/page.tsx 2import { t } from "#src/i18n.ts"; 3 4export default function Page() { 5 return ( 6 <div> 7 <h1>{t({ en: "My Page", zh: "我的页面" })}</h1> 8 <p>{t({ en: "Some content", zh: "一些内容" })}</p> 9 </div> 10 ); 11}

Then run pnpm codegen:i18n to regenerate bundles.

Adding Translations to a Client Component

tsx
1// src/components/my-component.tsx 2"use client"; 3 4import { t } from "#src/i18n.ts"; 5 6export function MyComponent() { 7 return <span>{t({ en: "Click me", zh: "点击我" })}</span>; 8}

The parent page/layout must be in the manifest for client translations to work. Run pnpm codegen:i18n — the codegen traces imports and auto-generates the client bundle.

Rich Text with Markup

tsx
1{ 2 t( 3 { 4 en: "Read our <strong>terms of service</strong>", 5 zh: "阅读我们的<strong>服务条款</strong>", 6 }, 7 { parse: true }, 8 ); 9}

Common Mistakes

  • Using variables or template literals in t() — values must be string literals
  • Forgetting to run pnpm codegen:i18n after adding new t() calls
  • Manually adding setLocale to page files — the Babel plugin does this automatically
  • Creating separate translations.json files — translations live inline in the component
  • Using getTranslations() or useTranslations() — these no longer exist; use t() everywhere

相关技能

寻找 i18n-patterns 的替代方案 (Alternative) 或可搭配使用的同类 community Skill?探索以下相关开源技能。

查看全部

openclaw-release-maintainer

Logo of openclaw
openclaw

Your own personal AI assistant. Any OS. Any Platform. The lobster way. 🦞

333.8k
0
AI

widget-generator

Logo of f
f

为prompts.chat的信息反馈系统生成可定制的插件小部件

149.6k
0
AI

flags

Logo of vercel
vercel

React 框架

138.4k
0
浏览器

pr-review

Logo of pytorch
pytorch

Python中具有强大GPU加速的张量和动态神经网络

98.6k
0
开发者工具