Skip to content

Commit 922b5b0

Browse files
authored
fix: translate two-factor authentication deadline banner (#776)
Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
1 parent 9be6573 commit 922b5b0

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

locals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ I18N["zh-CN"]["public"] = { // 公共区域翻译
19771977
}],
19781978

19791979
// 其他翻译
1980-
[/to enable two-factor authentication as an additional security measure. Your activity on GitHub includes you in this requirement. You will need to enable two-factor authentication on your account before ([^ ]+), or be restricted from account actions./, "启用双因素身份验证(2FA)作为额外安全措施。您在 GitHub 上的活动让您接收到此要求。您将需要在 $1 前启用双因素身份验证,否则会被限制账户操作。"],
1980+
[/to enable two-factor authentication as an additional security measure. Your activity on GitHub includes you in this requirement. You will need to enable two-factor authentication on your account before ?(.+?), or be restricted from account actions./, "启用双因素身份验证(2FA)作为额外安全措施。您在 GitHub 上的活动让您接收到此要求。您将需要在 $1 前启用双因素身份验证,否则会被限制账户操作。"],
19811981
],
19821982
"time-regexp": [ // 时间正则翻译专项
19831983
/**

test/issue-775-regression.test.cjs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const assert = require('node:assert/strict');
2+
const fs = require('node:fs');
3+
const path = require('node:path');
4+
const test = require('node:test');
5+
const vm = require('node:vm');
6+
7+
const messagePrefix = 'to enable two-factor authentication as an additional security measure. Your activity on GitHub includes you in this requirement. You will need to enable two-factor authentication on your account before';
8+
const messageSuffix = ', or be restricted from account actions.';
9+
10+
function loadPublicRules() {
11+
const filePath = path.join(__dirname, '..', 'locals.js');
12+
const context = vm.createContext({});
13+
14+
vm.runInContext(fs.readFileSync(filePath, 'utf8'), context, {
15+
filename: filePath,
16+
});
17+
18+
return context.I18N['zh-CN'].public.regexp;
19+
}
20+
21+
function loadTwoFactorDeadlineRule() {
22+
const rule = loadPublicRules().find(([pattern]) => (
23+
pattern.source.includes('to enable two-factor authentication as an additional security measure')
24+
));
25+
26+
assert.ok(rule, 'the public dictionary should include the two-factor deadline rule');
27+
return rule;
28+
}
29+
30+
function translateDeadline(deadline, separator = '') {
31+
const [pattern, replacement] = loadTwoFactorDeadlineRule();
32+
return `${messagePrefix}${separator}${deadline}${messageSuffix}`.replace(pattern, replacement);
33+
}
34+
35+
test('translates a joined two-factor authentication deadline', () => {
36+
assert.equal(
37+
translateDeadline('2026年9月14日'),
38+
'启用双因素身份验证(2FA)作为额外安全措施。您在 GitHub 上的活动让您接收到此要求。您将需要在 2026年9月14日 前启用双因素身份验证,否则会被限制账户操作。',
39+
);
40+
});
41+
42+
test('continues to translate a spaced two-factor authentication deadline', () => {
43+
assert.equal(
44+
translateDeadline('2026年9月14日', ' '),
45+
'启用双因素身份验证(2FA)作为额外安全措施。您在 GitHub 上的活动让您接收到此要求。您将需要在 2026年9月14日 前启用双因素身份验证,否则会被限制账户操作。',
46+
);
47+
});
48+
49+
test('preserves a different two-factor authentication deadline', () => {
50+
const translated = translateDeadline('October 3, 2027');
51+
52+
assert.match(translated, /October 3, 2027/);
53+
assert.doesNotMatch(translated, /or be restricted from account actions/);
54+
});

0 commit comments

Comments
 (0)