保留键会先用源内容初始化一次,之后便不再受自动更新影响。CLI 永远不会覆盖它们——它们适合作为需要人工翻译内容的占位值,例如法律文本、合规文案或营销标语。
配置方法#
在 i18n.json 的某个 bucket 中添加 preservedKeys:
json
{
"buckets": {
"json": {
"include": ["locales/[locale].json"],
"preservedKeys": ["legal/privacy", "legal/terms"]
}
}
}工作方式#
以下面这份源文件为例:
json
{
"welcome": "Welcome to our platform",
"legal": {
"privacy": "We respect your privacy and protect your data.",
"terms": "By using this service, you agree to our terms."
}
}首次运行时,CLI 会原样复制保留键,同时翻译其余所有内容:
json
// locales/es.json (first run)
{
"welcome": "Bienvenido a nuestra plataforma",
"legal": {
"privacy": "We respect your privacy and protect your data.",
"terms": "By using this service, you agree to our terms."
}
}当你手动翻译完法律相关部分后,之后的 CLI 运行都会保留你的译文不变。
键保留 vs. 键锁定#
| 键保留 | 键锁定 | |
|---|---|---|
| 初始值 | 以源值作为占位值 | 源值(始终如此) |
| 手动修改 | 永久保留 | 每次运行都会被源值覆盖 |
| 适用场景 | 法律、合规、人工翻译 | 品牌名称、技术 ID |
键路径写法#
嵌套键使用正斜杠 (/),通配符使用星号 (*):
json
{ "preservedKeys": ["legal/*", "marketing/tagline"] }