关于 i18n-frontend-implementer
用于借助 next-intl、react-i18next 等库实现前端国际化的技能,涵盖翻译结构、本地化格式、语言切换和 RTL 支持。
主要功能
- 01国际化设置
- 02带命名空间的翻译词典
- 03复数与本地化格式
- 04语言切换器指引
- 05RTL 与延迟加载翻译
适用场景
- 01为前端添加多语言支持
- 02组织翻译键
- 03按地区格式化日期和数字
- 04支持 RTL 语言
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ patricio0312rev/ skills --skill i18n-frontend-implementer安装后在 Claude Code 中输入/i18n-frontend-implementer确认已加载。
详细介绍
i18n 前端实现者
使用 next-intl、react-i18next 或类似库实现国际化。
核心设置
1. 安装:npm install next-intl 或 react-i18next
2. 创建字典:locales/en.json、locales/es.json
3. Provider 设置:使用 IntlProvider 包装应用
4. 翻译键:采用分层命名空间结构
5. 格式化工具:日期、数字、货币格式化
6. 语言切换器:下拉菜单或旗帜 UI
翻译结构
{
"common": { "nav": { "home": "Home", "about": "About" } },
"auth": { "login": "Sign In", "logout": "Sign Out" },
"errors": { "required": "{field} is required" }
}
使用示例
const t = useTranslations('common');
<h1>{t('nav.home')}</h1>
// With plurals
t('items', { count: 5 }) // "5 items"
// With formatting
<p>{formatDate(date, { dateStyle: 'long' })}</p>
最佳实践
使用命名空间进行组织,将所有文本提取到翻译文件中,正确处理复数形式,按区域设置格式化日期和数字,提供语言切换器,支持 RTL 语言,并延迟加载翻译。
评论
支持 Markdown