internationalization
БесплатноБез исполняемых скриптовНе проверен國際化與本地化開發:i18n/l10n 架構設計、翻譯管理、多語言應用最佳實踐
от miles990★ 26 звёзд на GitHubОб этом скилле
國際化與本地化 Internationalization & Localization
讓你的應用程式走向全世界
核心概念
┌─────────────────────────────────────────────────────────────────┐
│ i18n vs l10n │
│ │
│ 國際化 (Internationalization - i18n) │
│ ├─ 設計支援多語言的架構 │
│ ├─ 抽離可翻譯的字串 │
│ ├─ 處理日期、數字、貨幣格式 │
│ └─ 一次性工程工作 │
│ │
│ 本地化 (Localization - l10n) │
│ ├─ 針對特定語言/地區的翻譯 │
│ ├─ 文化適應(圖片、顏色、符號) │
│ ├─ 法規遵循(隱私、內容) │
│ └─ 持續性工作 │
│ │
│ i18n = 讓應用「能」支援多語言 │
│ l10n = 讓應用「實際」支援某語言 │
└─────────────────────────────────────────────────────────────────┘
適用場景
- 新專案的多語言架構設計
- 現有專案添加多語言支援
- 翻譯工作流程優化
- RTL (右到左) 語言支援
- 日期/數字/貨幣格式化
i18n 架構設計
翻譯檔案結構
推薦結構:按語言分類
locales/
├── en/
│ ├── common.json # 共用詞彙
│ ├── home.json # 首頁
│ └── settings.json # 設定頁
├── zh-TW/
│ ├── common.json
│ ├── home.json
│ └── settings.json
└── ja/
├── common.json
├── home.json
└── settings.json
替代結構:按功能分類
locales/
├── common/
│ ├── en.json
│ ├── zh-TW.json
│ └── ja.json
└── settings/
├── en.json
├── zh-TW.json
└── ja.json
翻譯 Key 命名規範
## 命名原則
1. **階層式命名**
✅ `settings.notifications.email.title`
❌ `settingsNotificationsEmailTitle`
2. **語意優先於位置**
✅ `action.save`, `action.cancel`
❌ `button1`, `button2`
3. **避免縮寫**
✅ `error.network.timeout`
❌ `err.net.to`
4. **使用英文小寫**
✅ `user.profile.avatar`
❌ `User.Profile.Avatar`
## 常用前綴
| 前綴 | 用途 | 範例 |
|------|------|------|
| `action.` | 動作按鈕 | `action.submit`, `action.delete` |
| `label.` | 表單標籤 | `label.email`, `label.password` |
| `error.` | 錯誤訊息 | `error.required`, `error.invalid` |
| `message.` | 一般訊息 | `message.success`, `message.loading` |
| `title.` | 頁面標題 | `title.home`, `title.settings` |
| `hint.` | 提示文字 | `hint.password_format` |
主流框架實作
React (react-i18next)
// i18n.ts - 配置
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
i18n
.use(LanguageDetector)
.use(initReactI18next)
.init({
fallbackLng: 'en',
supportedLngs: ['en', 'zh-TW', 'ja'],
ns: ['common', 'home', 'settings'],
defaultNS: 'common',
interpolation: {
escapeValue: false,
},
detection: {
order: ['querystring', 'cookie', 'localStorage', 'navigator'],
caches: ['localStorage', 'cookie'],
},
});
// 使用
import { useTranslation } from 'react-i18next';
function MyComponent() {
const { t, i18n } = useTranslation();
return (
<div>
<h1>{t('title.welcome')}</h1>
<p>{t('message.greeting', { name: 'John' })}</p>
<button onClick={() => i18n.changeLanguage('zh-TW')}>
中文
</button>
</div>
);
}
Vue (vue-i18n)
// i18n.ts
import { createI18n } from 'vue-i18n';
const i18n = createI18n({
legacy: false,
locale: 'en',
fallbackLocale: 'en',
messages: {
en: { /* ... */ },
'zh-TW': { /* ... */ },
},
});
// 使用
<template>
<h1>{{ $t('title.welcome') }}</h1>
<p>{{ $t('message.greeting', { name: 'John' }) }}</p>
</template>
<script setup>
import { useI18n } from 'vue-i18n';
const { t, locale } = useI18n();
</script>
Next.js (next-intl)
// middleware.ts
import createMiddleware from 'next-intl/middleware';
export default createMiddleware({
locales: ['en', 'zh-TW', 'ja'],
defaultLocale: 'en',
localePrefix: 'as-needed',
});
// app/[locale]/layout.tsx
import { NextIntlClientProvider } from 'next-intl';
import { getMessages } from 'next-intl/server';
export default async function LocaleLayout({
children,
params: { locale }
}) {
const messages = await getMessages();
return (
<NextIntlClientProvider messages={messages}>
{children}
</NextIntlClientProvider>
);
}
// 使用
import { useTranslations } from 'next-intl';
function Page() {
const t = useTranslations('home');
return <h1>{t('title')}</h1>;
}
複雜翻譯處理
複數形式 (Pluralization)
// en.json
{
"items": {
"zero": "No items",
"one": "{{count}} item",
"other": "{{count}} items"
}
}
// zh-TW.json (中文無複數變化)
{
"items": "{{count}} 個項目"
}
// 使用
t('items', { count: 5 }) // "5 items" / "5 個項目"
插值與格式化
{
"greeting": "Hello, {{name}}!",
"date": "Today is {{date, datetime}}",
"price": "Price: {{amoun
Установить internationalization в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл internationalization?
國際化與本地化開發:i18n/l10n 架構設計、翻譯管理、多語言應用最佳實踐
Как установить скилл internationalization?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл internationalization запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic