Communitygithub.com

AbobakrDiara61/railway-system

国际化与本地化模式。检测硬编码字符串、管理翻译、语言文件、RTL 支持。

railway-system 是什么?

该技能提供了国际化 (i18n) 和本地化 (L10n) 的最佳实践指南。它涵盖了核心概念如区域设置和 RTL(从右到左)语言支持,并针对 React (react-i18next)、Next.js (next-intl) 和 Python (gettext) 等流行框架提供了具体的实现模式。技能中提供了实用的文件结构和清单,帮助开发者避免硬编码字符串并正确处理复数、日期和数字格式。此外,该技能还包含一个脚本 (`scripts/i18n_checker.py`),用于检测项目中硬编码的字符串和缺失的翻译,确保代码具有完整的本地化能力。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/AbobakrDiara61/railway-system/tree/HEAD/frontend/skills/i18n-localization

在你喜欢的 AI 中提问

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

文档

i18n 与本地化

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


1. 核心概念

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

2. 何时使用 i18n

项目类型需要 i18n?
公共网页应用✅ 是
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(_("Welcome to our app"))

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

Astropy is the core Python package for astronomy, providing essential functionality for astronomical research and data analysis.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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 悬停效果

AbobakrDiara61/railway-system

Best practices for Remotion - Video creation in React

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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

AbobakrDiara61/railway-system

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.

AbobakrDiara61/railway-system

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

相关技能