gt@2.13.0
gtderivet-functiondx
概述
t() 函数现在可自动派生动态内容,无需再用 derive() 包裹变量。此功能默认启用,开箱即用,并可与 GT CLI 配合使用。
这是 derive() 系列改进的最新一步。首先,gt-react@10.15.0 为 t 标签模板字面量提供了 derive() 支持。随后,gt@2.12.0 扩展了 derive(),使其能够解析对象和数组中的值。现在,使用 t() 时,gt@2.13.0 完全不再需要调用 derive()。
前后对比
const noun = cond ? "boy" : "girl"
const result = t("The " + derive(noun))现在,直接使用这个变量:
const noun = cond ? "boy" : "girl"
const result = t("The " + noun)CLI 在解析你的 t() 调用时会自动处理派生——它会识别可能字符串值有限的变量,并在后台自动完成派生。
配置
默认启用自动派生。如需禁用,请在 gt.config.json 中将 autoDerive 设为 false:
{
"files": {
"gt": {
"parsingFlags": {
"autoDerive": false
}
}
}
}注意: 这仅适用于
t()函数。t标签模板宏不受影响——它已经可以通过 gt-react@10.15.0 中引入的模板字面量语法处理派生。