GNU Gettext PO 文件格式化与编辑器
使用 msgid、msgstr、msgid_plural 和 printf 占位符(%s、%d)格式化、验证和测试 GNU Gettext PO 翻译文件。
模板9
PO 编辑器
语法有效
68 字符3 行
测试变量与实时预览
调整变量并切换语言以验证 CLDR 复数规则
语言环境:
在消息字符串中未检测到变量。
渲染输出 (fr):
# Simple greeting
msgid "Hello, world!"
msgstr "Bonjour, le monde !"
导出为 Intlayer 类型安全声明
Intlayer 在编译时通过完整的 TypeScript 自动补全来验证翻译。
GNU Gettext PO Syntax Cheat Sheet
快速语法规则以及每个模式如何映射到 Intlayer 的类型安全声明
| 功能 | 语法 | 示例 | 备注 | Intlayer 等效写法 |
|---|---|---|---|---|
| Singular Message | msgid "..." \n msgstr "..." | msgid "Hello" \n msgstr "Bonjour" | msgid is source key, msgstr is translated text | t({ en: "Hello", fr: "Bonjour" }) |
| Plural Messages | msgid_plural "..." \n msgstr[N] "..." | msgid "file" \n msgid_plural "files" \n msgstr[0] "fichier" \n msgstr[1] "fichiers" | Plural-Forms header defines index calculation | plural({ one: "file", other: "{{count}} files" }) |
| Context (msgctxt) | msgctxt "context" \n msgid "..." | msgctxt "menu" \n msgid "File" | Disambiguates identical msgid in different contexts | Separate keys or select() nodes |
| Printf Specifiers | %s, %d, %1$s | msgid "%d items found" | Position-aware C printf formatters | {{count}} or named interpolations |
| Comments | # translator, #: reference, #, flag | #: src/app.tsx:42 | Standard PO comments generated by xgettext | TypeScript comments in .content.ts |
Intlayer 基于编译器的架构用编译时类型安全和自动化提取取代了复杂的运行时消息解析。