Skip to content

Commit 52b7b76

Browse files
committed
Use OS-GUI's new AccessKeys API for localization preprocessing
1 parent dafef7b commit 52b7b76

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

localization/preprocess.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
11
const fs = require("fs");
22
const glob = require("glob");
33
const parse_rc_file = require("./parse-rc-file");
4+
const { AccessKeys } = require("../lib/os-gui/MenuBar.js");
45

56
const base_lang = "en";
67
const available_langs = fs.readdirSync(__dirname).filter((dir) => dir.match(/^\w+(-\w+)?$/));
78
const target_langs = available_langs.filter((lang) => lang !== base_lang);
89

910
console.log("Target languages:", target_langs);
1011

11-
// @TODO: DRY hotkey helpers
12-
// & defines accelerators (hotkeys) in menus and buttons and things, which get underlined in the UI.
13-
// & can be escaped by doubling it, e.g. "&Taskbar && Start Menu"
14-
function index_of_hotkey(text) {
15-
// Returns the index of the ampersand that defines a hotkey, or -1 if not present.
16-
17-
// return english_text.search(/(?<!&)&(?!&|\s)/); // not enough browser support for negative lookbehind assertions
18-
19-
// The space here handles beginning-of-string matching and counteracts the offset for the [^&] so it acts like a negative lookbehind
20-
return ` ${text}`.search(/[^&]&[^&\s]/);
21-
}
22-
function has_hotkey(text) {
23-
return index_of_hotkey(text) !== -1;
24-
}
25-
function remove_hotkey(text) {
26-
return text.replace(/\s?\(&.\)/, "").replace(/([^&]|^)&([^&\s])/, "$1$2");
27-
}
2812
const remove_ellipsis = str => str.replace("...", "");
2913

3014
const only_unique = (value, index, self) => self.indexOf(value) === index;
@@ -61,9 +45,9 @@ for (const target_lang of target_langs) {
6145
} else {
6246
// add_localization(base_string, target_string, 0);
6347
add_localization(remove_ellipsis(base_string), remove_ellipsis(target_string), 1);
64-
if (has_hotkey(base_string)) {
65-
// add_localization(remove_hotkey(base_string), remove_hotkey(target_string), 2);
66-
add_localization(remove_ellipsis(remove_hotkey(base_string)), remove_ellipsis(remove_hotkey(target_string)), 3);
48+
if (AccessKeys.has(base_string)) {
49+
// add_localization(AccessKeys.remove(base_string), AccessKeys.remove(target_string), 2);
50+
add_localization(remove_ellipsis(AccessKeys.remove(base_string)), remove_ellipsis(AccessKeys.remove(target_string)), 3);
6751
}
6852
}
6953
}

0 commit comments

Comments
 (0)