Skip to content

Commit 8077c06

Browse files
authored
refactor: Use localizable messages. (#458)
* refactor: Use localizable messages. * chore: Fix post-rebase.
1 parent a0bf76f commit 8077c06

File tree

11 files changed

+226
-186
lines changed

11 files changed

+226
-186
lines changed

src/actions/clipboard.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Gesture,
1010
ShortcutRegistry,
1111
Events,
12+
Msg,
1213
utils as blocklyUtils,
1314
clipboard,
1415
ICopyData,
@@ -104,7 +105,8 @@ export class Clipboard {
104105
*/
105106
private registerCutContextMenuAction() {
106107
const cutAction: ContextMenuRegistry.RegistryItem = {
107-
displayText: (scope) => `Cut (${getShortActionShortcut('cut')})`,
108+
displayText: (scope) =>
109+
Msg['CUT_SHORTCUT'].replace('%1', getShortActionShortcut('cut')),
108110
preconditionFn: (scope) => {
109111
const ws = scope.block?.workspace;
110112
if (!ws) return 'hidden';
@@ -199,7 +201,8 @@ export class Clipboard {
199201
*/
200202
private registerCopyContextMenuAction() {
201203
const copyAction: ContextMenuRegistry.RegistryItem = {
202-
displayText: (scope) => `Copy (${getShortActionShortcut('copy')})`,
204+
displayText: (scope) =>
205+
Msg['COPY_SHORTCUT'].replace('%1', getShortActionShortcut('copy')),
203206
preconditionFn: (scope) => {
204207
const ws = scope.block?.workspace;
205208
if (!ws) return 'hidden';
@@ -304,7 +307,8 @@ export class Clipboard {
304307
*/
305308
private registerPasteContextMenuAction() {
306309
const pasteAction: ContextMenuRegistry.RegistryItem = {
307-
displayText: (scope) => `Paste (${getShortActionShortcut('paste')})`,
310+
displayText: (scope) =>
311+
Msg['PASTE_SHORTCUT'].replace('%1', getShortActionShortcut('paste')),
308312
preconditionFn: (scope: ContextMenuRegistry.Scope) => {
309313
let block;
310314
if (scope.focusedNode instanceof Blockly.Block) {

src/actions/delete.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import {
88
ContextMenuRegistry,
99
Gesture,
10+
Msg,
1011
ShortcutRegistry,
1112
utils as BlocklyUtils,
1213
LineCursor,
1314
} from 'blockly';
15+
import {getShortActionShortcut} from '../shortcut_formatting';
1416
import * as Constants from '../constants';
1517
import type {WorkspaceSvg} from 'blockly';
1618
import {Navigation} from '../navigation';
@@ -102,16 +104,17 @@ export class DeleteAction {
102104

103105
const deleteItem: ContextMenuRegistry.RegistryItem = {
104106
displayText: (scope) => {
107+
const shortcut = getShortActionShortcut(this.deleteShortcutName);
105108
if (!this.oldContextMenuItem) {
106-
return 'Delete block (Del)';
109+
return Msg['DELETE_BLOCK'].replace('%1', shortcut);
107110
}
108111

109112
type DisplayTextFn = (p1: ContextMenuRegistry.Scope) => string;
110113
// Use the original item's text, which is dynamic based on the number
111114
// of blocks that will be deleted.
112115
const oldDisplayText = this.oldContextMenuItem
113116
.displayText as DisplayTextFn;
114-
return oldDisplayText(scope) + ' (Del)';
117+
return oldDisplayText(scope) + ` (${shortcut})`;
115118
},
116119
preconditionFn: (scope, menuOpenEvent: Event) => {
117120
const ws = scope.block?.workspace;

src/actions/edit.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import {ContextMenuRegistry, LineCursor} from 'blockly';
7+
import {ContextMenuRegistry, LineCursor, Msg} from 'blockly';
88
import {Navigation} from 'src/navigation';
9+
import {getShortActionShortcut} from '../shortcut_formatting';
10+
import * as Constants from '../constants';
911

1012
/**
1113
* Action to edit a block. This just moves the cursor to the first
@@ -50,7 +52,10 @@ export class EditAction {
5052
*/
5153
private registerContextMenuAction() {
5254
const editAboveItem: ContextMenuRegistry.RegistryItem = {
53-
displayText: 'Edit Block contents (→︎)',
55+
displayText: Msg['EDIT_BLOCK_CONTENTS'].replace(
56+
'%1',
57+
getShortActionShortcut(Constants.SHORTCUT_NAMES.RIGHT),
58+
),
5459
preconditionFn: (scope: ContextMenuRegistry.Scope, menuOpenEvent) => {
5560
if (menuOpenEvent instanceof PointerEvent) return 'hidden';
5661
const workspace = scope.block?.workspace;

src/actions/enter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {
88
Events,
9+
Msg,
910
ShortcutRegistry,
1011
utils as BlocklyUtils,
1112
getFocusManager,

src/actions/insert.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
import {
88
ContextMenuRegistry,
9+
Msg,
910
ShortcutRegistry,
1011
utils as BlocklyUtils,
1112
} from 'blockly';
13+
import {getShortActionShortcut} from '../shortcut_formatting';
1214
import * as Constants from '../constants';
1315
import type {WorkspaceSvg} from 'blockly';
1416
import {Navigation} from '../navigation';
@@ -69,7 +71,10 @@ export class InsertAction {
6971
private registerContextMenuAction() {
7072
const insertAboveItem: ContextMenuRegistry.RegistryItem = {
7173
displayText: () => {
72-
return 'Insert Block (I)';
74+
return Msg['INSERT_BLOCK'].replace(
75+
'%1',
76+
getShortActionShortcut(this.insertShortcutName),
77+
);
7378
},
7479
preconditionFn: (
7580
scope: ContextMenuRegistry.Scope,

0 commit comments

Comments
 (0)