I18n

lobehub/lobehub/.agents/skills/i18n

作者 lobehub6a3eba96b010无许可证83K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库今天更新

Use for user-facing strings and react-i18next locale keys, namespaces, interpolation, translations or bun run i18n.

AI 生成的概览

指导在 LobeHub 代码库中添加和管理 react-i18next 语言键与命名空间。

功能
该技能说明 react-i18next 项目中面向用户字符串的约定:扁平点号键、命名空间组织、双花括号插值以及避免键冲突。它描述了向默认语言源文件添加键、导出命名空间,并由每日自动化工作流生成其他语言的流程。它还介绍组件中的翻译用法,并列出项目常用命名空间。
适用场景
在向该代码库添加、编辑或审查面向用户字符串和语言键时使用。涉及命名空间、插值或项目翻译生成流程时也适用。
运行要求
需要 react-i18next 框架和项目的语言文件结构;手动运行翻译使用 bun run i18n,并需要 OPENAI_API_KEY。不附带脚本,仅为说明文档。

LobeHub Internationalization Guide

  • Default language: English (en-US)
  • Framework: react-i18next
  • Only edit files in packages/locales/src/default/ - Never edit JSON files in locales/ (except hand-written en-US/zh-CN previews)
  • Leave generated locales to the daily auto-i18n.yml workflow by default; run bun run i18n manually only when they are needed immediately

Key Naming Convention

Flat keys with dot notation (not nested objects):

typescript
// ✅ Correctexport default {  'alert.cloud.action': '立即体验',  'sync.actions.sync': '立即同步',  'sync.status.ready': '已连接',};
// ❌ Avoid nested objectsexport 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 packages/locales/src/default/{namespace}.ts
  2. Export new namespace in packages/locales/src/default/index.ts
  3. For dev preview: manually translate locales/zh-CN/{namespace}.json and locales/en-US/{namespace}.json
  4. Leave all other locales to .github/workflows/auto-i18n.yml, which runs daily and opens an automated translation PR
  5. Run bun run i18n manually only when the branch needs those translations immediately; it is slow and requires OPENAI_API_KEY

Usage

tsx
import { useTranslation } from 'react-i18next';
const { t } = useTranslation('common');
t('newFeature.title');t('alert.cloud.desc', { credit: '1000' });
// Multiple namespacesconst { 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

来源与署名

来源:lobehub/lobehub位于.agents/skills/i18n提交6a3eba9

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架