-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
仓库 commits 的 “提交检查” 状态有太多组合,是否有更好的方式处理翻译? #111
Labels
enhancement
New feature or request
Comments
事实上我放弃翻译 😂 |
我有一种方法可以很大程度的简化这类词条的数量,不知道合不合适,只需要对正则匹配结果进行翻译替换。 对于这类词条我们现在的正则替换方式是: [/(\d+) failing, (\d+) successful, (\d+) pending, and (\d+) cancelled checks/, "$1 失败,$2 成果,$3 待定,$4 取消"] 但是因为他这个句式是有固定格式的,实际我们需要翻译的只有目前这9种状态的名称,那我们把状态名称也通过正则匹配出来,然后再翻译状态名称。 const translate = {
expected: "缺失",
successful: "成功",
skipped: "跳过",
failing: "失败",
pending: "待定",
cancelled: "取消",
queued: "等待",
"action required": "需要操作",
"in progress": "运行中"
}
const str = "3 failing, 2 successful, 1 pending, and 2 cancelled checks";
const result = str.replace(
/(\d+) ([a-z ]+), (\d+) ([a-z ]+), (\d+) ([a-z ]+), and (\d+) ([a-z ]+) checks/,
(_, $1, $2, $3, $4, $5, $6, $7, $8) => {
return `${$1} ${translate[$2]}, ${$3} ${translate[$4]}, ${$5} ${translate[$6]}, ${$7} ${translate[$8]}`;
}
);
console.log(result); // 3 失败, 2 成功, 1 待定, 2 取消 这样就可以翻译同时含有4种状态提示语的所有排列,所以只需要9条正则就覆盖1到9种状态的全部提示语。 |
优化了一下,只需要一条正则就可以匹配所有的状态提示语 const translate = {
expected: "缺失",
successful: "成功",
skipped: "跳过",
failing: "失败",
pending: "待定",
cancelled: "取消",
queued: "等待",
"action required": "需要操作",
"in progress": "运行中"
}
const str = "3 failing, 2 successful, 1 pending, and 2 cancelled checks";
const result = [...str.matchAll(/(\d+) ([a-z ]+)(?=,| and| checks| check)/g)].map(([_, $1, $2]) => `${$1} ${translate[$2]}`).join(", ");
console.log(result); // 3 失败, 2 成功, 1 待定, 2 取消 |
Merged
可以参考时间正则翻译 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
仓库的提交检查状态是根据检查出的所有状态按任务顺序组合,所以是没有特定的顺序,会出现所有状态的排列组合,目前已知的状态有9种:
所有任务都只有一种相同状态的时候会有复数形式,例如:
当有两种及以上的不同状态时,格式会有变化:
如果按照现在的方式添加翻译,要覆盖所有的状态和所有的排列,需要添加500多个词条,这样感觉是不太合适的
The text was updated successfully, but these errors were encountered: