跳到正文
Skillpedia
网站与界面(前端)75k · #3062

translation-strings

它能做什么

这项技能检查软件项目中如何为翻译准备文字。适用于为应用支持多种语言做准备的开发者。

适用场景

  • ✓当项目把文字和数字拼接在一起,以构建翻译句子的时候。
  • ✓当为新应用设置翻译库的时候。
  • ✓当为新语言准备代码中面向用户的文字的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/translation-strings/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/translation-strings/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#3062
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能