|
1 | 1 | const fs = require("fs"); |
2 | 2 | const glob = require("glob"); |
3 | 3 | const parse_rc_file = require("./parse-rc-file"); |
| 4 | +const { AccessKeys } = require("../lib/os-gui/MenuBar.js"); |
4 | 5 |
|
5 | 6 | const base_lang = "en"; |
6 | 7 | const available_langs = fs.readdirSync(__dirname).filter((dir) => dir.match(/^\w+(-\w+)?$/)); |
7 | 8 | const target_langs = available_langs.filter((lang) => lang !== base_lang); |
8 | 9 |
|
9 | 10 | console.log("Target languages:", target_langs); |
10 | 11 |
|
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 | | -} |
28 | 12 | const remove_ellipsis = str => str.replace("...", ""); |
29 | 13 |
|
30 | 14 | const only_unique = (value, index, self) => self.indexOf(value) === index; |
@@ -61,9 +45,9 @@ for (const target_lang of target_langs) { |
61 | 45 | } else { |
62 | 46 | // add_localization(base_string, target_string, 0); |
63 | 47 | 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); |
67 | 51 | } |
68 | 52 | } |
69 | 53 | } |
|
0 commit comments