Intlayer 消息格式化与编辑器
利用 {{var}} 插值、t()、plural()、enu()、select()、cond() 和 Markdown 构建、测试并验证类型安全的 Intlayer 内容声明。
模板18
INTLAYER 编辑器
语法有效
36 字符1 行
测试变量与实时预览
调整变量并切换语言以验证 CLDR 复数规则
语言环境:
渲染输出 (en):
Hello Alex, welcome to Intlayer!
导出为 Intlayer 类型安全声明
Intlayer 在编译时通过完整的 TypeScript 自动补全来验证翻译。
Intlayer Message Format Syntax Cheat Sheet
快速语法规则以及每个模式如何映射到 Intlayer 的类型安全声明
| 功能 | 语法 | 示例 | 备注 | Intlayer 等效写法 |
|---|---|---|---|---|
| Variable Interpolation | {{variableName}} | Hello {{name}}! | Double curly braces for dynamic parameter insertion | useIntlayer(key).name or resolveMessage() |
| Multilingual Translation | t({ en: "...", fr: "..." }) | t({ en: "Hello", fr: "Bonjour" }) | Locale-keyed translations with type safety and fallback | t({ [locale]: string }) |
| Pluralization (plural) | plural({ one: "...", other: "..." }) | plural({ one: "1 item", other: "{{count}} items" }) | CLDR cardinal plural rules with automatic count lookup | plural({ [category]: string }) |
| Exact Enumeration (enu) | enu({ 0: "...", 1: "...", fallback: "..." }) | enu({ 0: "Zero", 1: "One", fallback: "{{count}}" }) | Exact numeric matching with fallback for remaining counts | enu({ [number]: string, fallback }) |
| Dynamic Selection (select) | select({ key: "...", fallback: "..." }, "variable") | select({ admin: "Admin", fallback: "User" }, "role") | Branch on any custom string variable discriminator | select({ [key]: string }, variableKey) |
| Gender Agreement (gender) | gender({ male: "...", female: "...", fallback: "..." }) | gender({ male: "He", female: "She", fallback: "They" }) | Grammatical gender concordance with automatic lookup | gender({ male, female, fallback }) |
| Boolean Condition (cond) | cond({ true: "...", false: "..." }) | cond({ true: "Logged In", false: "Guest" }) | Evaluates boolean state conditions | cond({ true: string, false: string }) |
| Markdown Content (md) | md("# ...\n**bold**") | md("# Title\n\n**Bold** {{variable}}") | Rich markdown rendered to React / HTML nodes | md(markdownString) |
| Embedded HTML (html) | html("<tag>...</tag>") | html("<p>Visit <a href=\"/\">home</a></p>") | Embedded safe HTML markup for links and formatting | html(htmlString) |
Intlayer 基于编译器的架构用编译时类型安全和自动化提取取代了复杂的运行时消息解析。