Communitygithub.com

i18n 與在地化

國際化(i18n)與在地化(L10n)最佳實務。偵測硬編碼字串、管理翻譯、地區檔案與 RTL 支援。

i18n 與在地化 是什麼?

此技能提供一套完整的國際化(i18n)與在地化(L10n)最佳實務指南,協助開發者將應用程式設計成可翻譯、可適應不同語言與地區的版本。它涵蓋 React(react-i18next)、Next.js(next-intl)以及 Python(gettext)等主流框架的實作模式,並說明如何透過命名空間(namespace)組織翻譯檔案,例如 `locales/en/common.json`。技能也納入右至左(RTL)語言的 CSS Logical Properties 支援,以及使用 Intl.DateTimeFormat 與 Intl.NumberFormat 處理日期與數字格式。此外,它提供一份部署前檢查清單與 `i18n_checker.py` 腳本,用於自動偵測硬編碼字串與遺漏的翻譯,幫助團隊維持程式碼品質。此技能適用於公共網站、SaaS 產品以及需要多語言支援的內部工具。

相容平台~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. 最佳實務

應該做 ✅

  • 使用翻譯鍵,而非原始文字
  • 按功能模組命名翻譯命名空間 (namespace)
  • 支援複數形式
  • 依地區處理日期/數字格式
  • 一開始就規劃 RTL 支援
  • 針對複雜字串使用 ICU 訊息格式

不該做 ❌

  • 在元件中直接寫死字串
  • 拼接已翻譯的字串
  • 假設文字長度 (德文通常會長 30%)
  • 忘記 RTL 版面配置
  • 在同一個檔案中混合語言

6. 常見問題

問題解決方案
缺少翻譯回退為預設語言
硬編碼字串使用 linter 或檢查腳本
日期格式使用 Intl.DateTimeFormat
數字格式使用 Intl.NumberFormat
複數形式使用 ICU 訊息格式

7. RTL 支援

/* CSS Logical Properties */
.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

相關技能