Communitygithub.com

i18n 與本地化處理

偵測程式碼中的硬編碼字串,管理翻譯文件、語言環境設定與 RTL 支援。

i18n 與本地化處理 是什麼?

這項技能專注於國際化(i18n)與本地化(L10n)的最佳實踐。它能協助開發者偵測並管理應用程式中的硬編碼字串,將所有使用者介面文字萃取為翻譯金鑰,並建立對應的語言環境檔案。技能涵蓋多種主流框架的實作模式,包括 React (react-i18next)、Next.js (next-intl) 與 Python (gettext),並提供標準化的檔案結構建議,例如按功能區分 `common.json`、`auth.json` 等翻譯命名空間。此外,也深入說明 RTL(由右至左)語言的 CSS 邏輯屬性處理方式,以及使用 `Intl.DateTimeFormat` 與 `Intl.NumberFormat` 處理地區格式。最後提供一份出貨前檢查清單,並包含一個 `scripts/i18n_checker.py` 腳本,可自動掃描專案中的硬編碼字串與遺漏的翻譯項目。

相容平台~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?
公開網站✅ 是
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

相關技能