Communitygithub.com

i18n 与本地化

国际化与本地化的最佳实践:检测硬编码字符串、管理翻译文件、支持区域设置和 RTL(从右至左)布局。

i18n 与本地化 是什么?

该技能提供了全面的国际化(i18n)与本地化(L10n)最佳实践指南,适用于 AI 辅助开发或自动化工具场景。它涵盖了核心概念(如区域设置和 RTL 支持)、项目类型决策矩阵以及主流框架(React 的 react-i18next、Next.js 的 next-intl、Python 的 gettext)的实现模式。技能还定义了推荐的翻译文件结构(按语言和功能命名空间组织 JSON 文件),并列举了常见陷阱与解决方案,包括硬编码字符串、日期/数字格式化和复数规则。此外,它提供了 RTL 布局的 CSS 逻辑属性示例、发布前检查清单以及一个用于检测硬编码字符串和缺失翻译的检测脚本(i18n_checker.py)。该技能支持 Cursor、Claude Code 和 Codex 等平台,帮助开发者在多语言应用开发中遵循结构化流程,避免常见错误。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/AlperTuncOrtak/crypto-data-pipeline/tree/HEAD/skills/i18n-localization

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

i18n 与本地化 是做什么的?

国际化(i18n)与本地化(L10n)最佳实践。


1. 核心概念

术语含义
i18n国际化——使应用可翻译
L10n本地化——实际翻译
Locale区域设置——语言+地区(en-US, tr-TR)
RTL从右至左语言(阿拉伯语、希伯来语)

2. 何时使用 i18n

项目类型需要 i18n?
公共 Web 应用✅ 是
SaaS 产品✅ 是
内部工具⚠️ 可能
单区域应用⚠️ 考虑未来
个人项目❌ 可选

3. 实现模式

React (react-i18next)

import { useTranslation } from 'react-i18next';

function Welcome() {
  const { t } = useTranslation();
  return <h1>{t('welcome.title')}</h1>;
}

Next.js (next-intl)

import { useTranslations } from 'next-intl';

export default function Page() {
  const t = useTranslations('Home');
  return <h1>{t('title')}</h1>;
}

Python (gettext)

from gettext import gettext as _

print(_("欢迎使用我们的应用"))

4. 文件结构

locales/
├── en/
│   ├── common.json
│   ├── auth.json
│   └── errors.json
├── tr/
│   ├── common.json
│   ├── auth.json
│   └── errors.json
└── ar/          # RTL
    └── ...

5. 最佳实践

应做 ✅

  • 使用翻译键,而非原始文本
  • 按功能对翻译进行命名空间管理
  • 支持复数形式
  • 针对每个区域设置处理日期/数字格式
  • 从一开始就规划 RTL 支持
  • 对复杂字符串使用 ICU 消息格式

不应做 ❌

  • 在组件中硬编码字符串
  • 拼接已翻译的字符串
  • 假设文本长度(德语通常比英语长 30%)
  • 忘记 RTL 布局
  • 在同一文件中混合不同语言

6. 常见问题

问题解决方案
缺少翻译回退到默认语言
硬编码字符串使用 linter 或检查脚本
日期格式使用 Intl.DateTimeFormat
数字格式使用 Intl.NumberFormat
复数形式使用 ICU 消息格式

7. RTL 支持

/* CSS 逻辑属性 */
.container {
  margin-inline-start: 1rem;  /* 而非 margin-left */
  padding-inline-end: 1rem;   /* 而非 padding-right */
}

[dir="rtl"] .icon {
  transform: scaleX(-1);
}

8. 检查清单

在发布之前:

  • 所有面向用户的字符串均使用翻译键
  • 所有支持的语言均有对应的语言文件
  • 日期/数字格式化使用 Intl API
  • 已测试 RTL 布局(如适用)
  • 已配置回退语言
  • 组件中无硬编码字符串

脚本

脚本用途命令
scripts/i18n_checker.py检测硬编码字符串与缺失翻译python scripts/i18n_checker.py <project_path>

何时使用

当任务明确符合上述概述范围时,可使用此技能来执行所述的工作流或操作。

限制

  • 仅当任务与上述范围清晰匹配时才使用此技能。
  • 不要将输出视为环境特定验证、测试或专家审核的替代品。
  • 如果缺少必要的输入、权限、安全边界或成功标准,请停下来要求澄清。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

AlperTuncOrtak/crypto-data-pipeline

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

AlperTuncOrtak/crypto-data-pipeline

Advanced JavaScript animation library skill for creating complex, high-performance web animations.

AlperTuncOrtak/crypto-data-pipeline

One sentence - what this skill does and when to invoke it

AlperTuncOrtak/crypto-data-pipeline

Audit and fix animation performance issues including layout thrashing, compositor properties, scroll-linked motion, and blur effects. Use when animations stutter, transitions jank, or reviewing CSS/JS animation performance.

AlperTuncOrtak/crypto-data-pipeline

Pull a YouTube video transcript into a queryable markdown vault with yt-dlp subtitle discovery, VTT cleanup, metadata frontmatter, and capture-seed stubs.

AlperTuncOrtak/crypto-data-pipeline

Expert in building portfolios that actually land jobs and clients - not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

AlperTuncOrtak/crypto-data-pipeline

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO.

AlperTuncOrtak/crypto-data-pipeline

AI-powered animation tool for creating motion in logos, UI, icons, and social media assets.

AlperTuncOrtak/crypto-data-pipeline

CRITICAL: Use for Makepad animation system. Triggers on: makepad animation, makepad animator, makepad hover, makepad state, makepad transition, "from: { all: Forward", makepad pressed, makepad 动画, makepad 状态, makepad 过渡, makepad 悬停效果

AlperTuncOrtak/crypto-data-pipeline

Best practices for Remotion - Video creation in React

AlperTuncOrtak/crypto-data-pipeline

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays

AlperTuncOrtak/crypto-data-pipeline

Seek and analyze video content using Memories.ai Large Visual Memory Model for persistent video intelligence

AlperTuncOrtak/crypto-data-pipeline

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

AlperTuncOrtak/crypto-data-pipeline

Three.js animation - keyframe animation, skeletal animation, morph targets, animation mixing. Use when animating objects, playing GLTF animations, creating procedural motion, or blending animations.

AlperTuncOrtak/crypto-data-pipeline

Automate TikTok tasks via Rube MCP (Composio): upload/publish videos, post photos, manage content, and view user profiles/stats. Always search tools first for current schemas.

AlperTuncOrtak/crypto-data-pipeline

Video and audio perception, indexing, and editing. Ingest files/URLs/live streams, build visual/spoken indexes, search with timestamps, edit timelines, add overlays/subtitles, generate media, and create real-time alerts.

AlperTuncOrtak/crypto-data-pipeline

Upload, stream, search, edit, transcribe, and generate AI video and audio using the VideoDB SDK.

AlperTuncOrtak/crypto-data-pipeline

One sentence - what this skill does and when to invoke it

AlperTuncOrtak/crypto-data-pipeline

Automate YouTube tasks via Rube MCP (Composio): upload videos, manage playlists, search content, get analytics, and handle comments. Always search tools first for current schemas.

AlperTuncOrtak/crypto-data-pipeline

Extract transcripts from YouTube videos and generate comprehensive, detailed summaries using intelligent analysis frameworks

相关技能