Communitygithub.com

YepAPI/skills

next-intl 和 react-i18next 模式,包含語言路由、訊息提取、複數形式、RTL 支援以及 Intl API 格式化。

skills 是什麼?

此技能為開發者提供了在 Next.js 和 React 應用程式中實作國際化(i18n)的明確規則與模式。對於 Next.js App Router 專案,它規範使用 `next-intl` 搭配 `useTranslations()` 鉤子、`NextIntlClientProvider` 和語言偵測中介軟體;對於 React SPA,則推薦使用 `react-i18next` 搭配 `useTranslation()` 鉤子與 `i18next-http-backend` 進行延遲載入。技能涵蓋了語言感知路由(例如 `/en/about`)、基於 JSON 的翻譯檔案(按語言和命名空間拆分)、ICU 訊息格式的複數化處理、使用 `Intl` API 進行日期/數字/貨幣格式化,以及透過 CSS 邏輯屬性和 `dir="rtl"` 屬性支援從右至左(RTL)語言。此外,它明確指出了常見的誤用模式,例如硬編碼字串、字串拼接翻譯文字、一次性載入所有語言以及僅在 localStorage 中儲存語言偏好。通過遵循這些模式,開發者可以建立 SEO 友善、可共享且易於維護的多語言應用程式。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/YepAPI/skills/tree/HEAD/skills/i18n

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

i18n

規則

  • Next.js App Router:使用 next-intl — useTranslations() 鉤子、NextIntlClientProvider、用於語言偵測的中介軟體
  • React SPA:使用 react-i18next — useTranslation() 鉤子、搭配 i18next-http-backend 進行延遲載入的 i18n.init()
  • 語言感知路由:/en/about、/fr/about — 使用中介軟體偵測 Accept-Language 標頭並重新導向
  • 翻譯檔案:每個語言每個命名空間一個 JSON 檔案 — messages/en/common.json、messages/fr/common.json
  • 命名空間拆分:每個功能/頁面一個命名空間 — auth.json、dashboard.json、settings.json — 僅載入頁面所需的內容
  • 複數形式:使用 ICU 訊息格式 — {count, plural, one {# 個項目} other {# 個項目}}
  • 插值:t('greeting', { name }) — 絕對不要拼接已翻譯的文字
  • 日期/數字/貨幣:使用 Intl.DateTimeFormat、Intl.NumberFormat — 絕對不要硬編碼格式
  • RTL 支援:在 <html> 上使用 dir="rtl",使用 CSS 邏輯屬性(margin-inline-start 而非 margin-left),用阿拉伯語/希伯來語測試

模式

// next-intl: middleware.ts
import createMiddleware from "next-intl/middleware";
export default createMiddleware({
  locales: ["en", "fr", "de", "ar"],
  defaultLocale: "en",
});

// next-intl: 元件使用方式
import { useTranslations } from "next-intl";
function ProductCard({ price, date }: { price: number; date: Date }) {
  const t = useTranslations("products");
  const format = useFormatter();
  return (
    <div>
      <h2>{t("title")}</h2>
      <p>{format.number(price, { style: "currency", currency: "USD" })}</p>
      <p>{format.dateTime(date, { dateStyle: "medium" })}</p>
    </div>
  );
}

應避免的事項

  • 硬編碼使用者面向的字串 — 每個字串都必須透過 t() 處理
  • 對翻譯文字進行字串拼接 — 使用插值或 ICU 格式
  • 預先載入所有語言 — 按語言和命名空間進行延遲載入
  • 使用 CSS 的 left/right 進行版面佈局 — 使用邏輯屬性以確保 RTL 相容性
  • 僅將語言儲存在 localStorage — 使用基於 URL 的語言以利 SEO 和共享

Individual skills in this repo

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

YepAPI/skills

WCAG 2.1 AA — semantic HTML, keyboard navigation, screen readers.

YepAPI/skills

Experiment setup, variant splitting, statistical significance, and feature flag integration.

YepAPI/skills

CRUD generators, data tables, user management, role-based access, and bulk operations.

YepAPI/skills

Monitor what ChatGPT and Gemini say about your brand using YepAPI.

YepAPI/skills

Queue workers with BullMQ/Inngest/Trigger.dev, job retries, dead letter queues, concurrency.

YepAPI/skills

Commander.js, interactive prompts with Clack, spinners, colors, config files, exit codes, and npm publishing.

YepAPI/skills

cmdk integration, Cmd+K trigger, fuzzy search, grouped actions, keyboard navigation, and dynamic action registration.

YepAPI/skills

Content planning with trend and sentiment data from YepAPI.

YepAPI/skills

Content calendar, keyword-driven planning, and content briefs.

YepAPI/skills

Theme switching with CSS variables, system preference detection, next-themes, and persistence.

YepAPI/skills

Threaded comments, @mentions, reactions, moderation queue, optimistic UI, and cursor pagination.

YepAPI/skills

Competitive analysis between domains using YepAPI.

YepAPI/skills

Layout grids, KPI cards, data tables with sorting/filtering, sidebar navigation, and responsive breakpoints.

YepAPI/skills

Data encryption — TLS everywhere, AES-256-GCM for PII, bcrypt passwords, encrypted backups.

YepAPI/skills

Chart patterns with Recharts/Nivo/D3, responsive containers, color scales, and accessibility.

YepAPI/skills

Drizzle schema definition, push vs migrate, type-safe queries, relations, transactions, and prepared statements.

YepAPI/skills

Upload handling, resize/compress, CDN delivery, blur placeholders, and next/image patterns.

YepAPI/skills

Local business and Google Maps research using YepAPI.

YepAPI/skills

Cursor-based pagination, IntersectionObserver, virtualized lists with @tanstack/react-virtual, and scroll position restoration.

YepAPI/skills

Chat UI components, streaming responses with AI SDK, context window management, and RAG patterns.

相關技能