translation-strings
它能做什么
这项技能检查软件项目中如何为翻译准备文字。适用于为应用支持多种语言做准备的开发者。
适用场景
- ✓当项目把文字和数字拼接在一起,以构建翻译句子的时候。
- ✓当为新应用设置翻译库的时候。
- ✓当为新语言准备代码中面向用户的文字的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/translation-strings/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的应用在代码里这样拼接句子:'Found ' + count + ' results'。我该如何让这些内容可以翻译?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会找出由文字片段拼接而成的句子,并用一条带有命名占位符的消息加以替换。之后由翻译库处理复数形式。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Write internationalisation-friendly translation strings
Naive string concatenation produces untranslatable sentences because word order varies dramatically across languages. A pattern like "Found " + count + " results" cannot be translated correctly into languages where the number appears in a different position or where the noun form changes depending on the count. Bad i18n strings force translators to work around developer mistakes — or simply leave content untranslated.
Quick Reference
- Never concatenate translated strings with variables — use named placeholders
- Use ICU MessageFormat for pluralisation, gender, and select patterns
- Keep translation keys descriptive and scoped to their feature context
- Extract all user-visible strings — do not hardcode any copy in components
Check
Check whether translation strings use proper message formatting with placeholders rather than string concatenation.
Fix
Replace concatenated translation strings with ICU message format patterns and ensure pluralisation is handled via the library, not conditionals.
Explain
Explain why string concatenation breaks translations and how ICU MessageFormat handles variable word order, pluralisation, and gender.
Code Review
Review components and utility functions for hardcoded user-visible strings, string concatenation involving translated text, and missing plural forms.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/translation-strings
常见问题
什么是 ICU MessageFormat?
它是一种标准写法,用于编写包含数字、复数和性别的可翻译消息。
为什么不能拼接文字片段?
不同语言的词序不同,因此拼接的片段通常无法被正确翻译。
直接写在组件中的文字呢?
这项技能指出,所有面向用户的文字都应提取到翻译文件中,而不是直接写在组件里。
详情
作者的原始描述
Use when reviewing a codebase for internationalisation readiness, setting up an i18n library, or preparing strings for a new locale.
热度
- GitHub 星标
- 75k
- 排名
- #3062
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。