一键导入
react-i18n-localization
Add i18n localization to a React + Vite + TypeScript SPA using i18next and react-i18next with structured JSON translation files
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Add i18n localization to a React + Vite + TypeScript SPA using i18next and react-i18next with structured JSON translation files
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | react-i18n-localization |
| description | Add i18n localization to a React + Vite + TypeScript SPA using i18next and react-i18next with structured JSON translation files |
| source | auto-skill |
| extracted_at | 2026-06-24T07:32:01.167Z |
When you need to add multi-language support to a React (Vite/TypeScript) frontend that has hardcoded English strings.
bun add i18next react-i18next
(or npm install / yarn add depending on the package manager)
src/i18n/)src/i18n/index.ts — Config file:
i18next and initReactI18nextlocalStorage (fallback to 'en')i18n.use(initReactI18next).init(...) with resources, lng, fallbackLng, interpolation: { escapeValue: false }languageChanged event to persist to localStoragesrc/i18n/{locale}.json — One JSON file per language:
common, nav, footer, home, login, register, search, dashboard, notFound, loginForm, registerForm, houseForm, filters, booking, etc.{{variable}} for interpolation (e.g., "welcome": "Welcome, {{name}}")_other suffix for plurals (e.g., "room" / "room_other")emailPlaceholder, passwordPlaceholderAdd import './i18n'; to src/main.tsx (before App import). No provider wrapper needed — initReactI18next handles it via React context internally.
For each component file:
import { useTranslation } from 'react-i18next';const { t } = useTranslation(); (add i18n if language switching is needed)t('namespace.key') or t('namespace.key', { var: value })t('common.room', { count: house.rooms })Priority order for updating files:
Add a toggle button in the Navbar:
const { t, i18n } = useTranslation();
function toggleLanguage() {
i18n.changeLanguage(i18n.language === 'en' ? 'my' : 'en');
}
Display the other language name so users know what they'll switch to.
Before writing translation files, read every component to build a complete inventory of hardcoded strings. This prevents missing strings and multiple passes. Group them by feature/domain for the JSON structure.
escapeValue: false is needed for React since React already escapes output<Input> and <textarea> elements need translation too — easy to misstoLocaleDateString() automatically respects the browser locale but won't change with i18n language switch unless you pass the locale explicitly