home / skills / lobehub / lobe-chat / i18n

i18n skill

/.agents/skills/i18n

This skill guides you through i18n tasks using react-i18next in React/TypeScript, helping create keys, manage locales, and implement translations.

npx playbooks add skill lobehub/lobe-chat --skill i18n

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.1 KB
---
name: i18n
description: Internationalization guide using react-i18next. Use when adding translations, creating i18n keys, or working with localized text in React components (.tsx files). Triggers on translation tasks, locale management, or i18n implementation.
---

# LobeChat Internationalization Guide

- Default language: Chinese (zh-CN)
- Framework: react-i18next
- **Only edit files in `src/locales/default/`** - Never edit JSON files in `locales/`
- Run `pnpm i18n` to generate translations (or manually translate zh-CN/en-US for dev preview)

## Key Naming Convention

**Flat keys with dot notation** (not nested objects):

```typescript
// ✅ Correct
export default {
  'alert.cloud.action': '立即体验',
  'sync.actions.sync': '立即同步',
  'sync.status.ready': '已连接',
};

// ❌ Avoid nested objects
export default {
  alert: { cloud: { action: '...' } },
};
```

**Patterns:** `{feature}.{context}.{action|status}`

**Parameters:** Use `{{variableName}}` syntax
```typescript
'alert.cloud.desc': '我们提供 {{credit}} 额度积分',
```

**Avoid key conflicts:**
```typescript
// ❌ Conflict
'clientDB.solve': '自助解决',
'clientDB.solve.backup.title': '数据备份',

// ✅ Solution
'clientDB.solve.action': '自助解决',
'clientDB.solve.backup.title': '数据备份',
```

## Workflow

1. Add keys to `src/locales/default/{namespace}.ts`
2. Export new namespace in `src/locales/default/index.ts`
3. For dev preview: manually translate `locales/zh-CN/{namespace}.json` and `locales/en-US/{namespace}.json`
4. Run `pnpm i18n` to generate all languages (CI handles this automatically)

## Usage

```tsx
import { useTranslation } from 'react-i18next';

const { t } = useTranslation('common');

t('newFeature.title')
t('alert.cloud.desc', { credit: '1000' })

// Multiple namespaces
const { t } = useTranslation(['common', 'chat']);
t('common:save')
```

## Common Namespaces

**Most used:** `common` (shared UI), `chat` (chat features), `setting` (settings)

Others: auth, changelog, components, discover, editor, electron, error, file, hotkey, knowledgeBase, memory, models, plugin, portal, providers, tool, topic

Overview

This skill is an i18n guide for React projects using react-i18next, focused on adding and managing translations in TypeScript (.tsx) components. It enforces file locations, key naming conventions, and a repeatable workflow so localized text stays consistent and conflict-free. Use it when creating translation keys, updating default language content, or integrating localized strings into components.

How this skill works

It inspects translation tasks and suggests edits only for files under src/locales/default/, following a flat key, dot-notation convention. The guide explains how to add namespaces, export them, preview translations, and run pnpm i18n to generate language bundles. It also shows how to call t() in components and pass parameters safely.

When to use it

  • Adding new translation keys or namespaces in src/locales/default/
  • Localizing React (.tsx) components with react-i18next
  • Resolving key conflicts and designing consistent key patterns
  • Preparing translations for CI or running pnpm i18n locally
  • Previewing or manually translating zh-CN/en-US for development

Best practices

  • Only edit files in src/locales/default/; do not modify generated locales/ JSON files
  • Use flat keys with dot notation: {feature}.{context}.{action|status}
  • Avoid nested objects in exports; prefer string-key objects to prevent conflicts
  • Use {{variableName}} for interpolation and pass values via t(key, {value})
  • Keep common UI strings in a common namespace (common) and group feature-specific text by namespace

Example use cases

  • Add a new namespace file src/locales/default/notifications.ts and export it from src/locales/default/index.ts
  • Create keys like 'sync.actions.sync' and use t('sync.actions.sync') in a button component
  • Localize a message with parameters: 'alert.cloud.desc' -> t('alert.cloud.desc', { credit: 1000 })
  • Resolve conflicting keys by refactoring to more specific names (e.g., change clientDB.solve to clientDB.solve.action)
  • Run pnpm i18n after edits so CI or build processes generate locales for zh-CN and en-US

FAQ

Which files may I edit?

Edit only files under src/locales/default/. Do not change generated JSON files in locales/.

How should I name keys?

Use flat dot-notated keys like 'feature.context.action' rather than nested objects.

How do I preview translations during development?

Manually translate locales/zh-CN/{ns}.json and locales/en-US/{ns}.json for dev preview, then run pnpm i18n.