Skip to content

Commit 0632931

Browse files
committed
Localized strings in mrc_call_python_function.ts.
1 parent e56ebb8 commit 0632931

File tree

5 files changed

+160
-42
lines changed

5 files changed

+160
-42
lines changed

src/blocks/mrc_call_python_function.ts

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -166,65 +166,88 @@ const CALL_PYTHON_FUNCTION = {
166166
switch (this.mrcFunctionKind) {
167167
case FunctionKind.BUILT_IN: {
168168
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
169-
tooltip = 'Calls the builtin function ' + functionName + '.';
169+
tooltip = Blockly.Msg.CALL_BUILTIN_FUNCTION_TOOLTIP;
170+
tooltip = tooltip.replace('{{functionName}}', functionName);
170171
break;
171172
}
172173
case FunctionKind.MODULE: {
173174
const moduleName = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
174175
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
175-
tooltip = 'Calls the module function ' + moduleName + '.' + functionName + '.';
176+
tooltip = Blockly.Msg.CALL_MODULE_FUNCTION_TOOLTIP;
177+
tooltip = tooltip
178+
.replace('{{moduleName}}', moduleName)
179+
.replace('{{functionName}}', functionName);
176180
break;
177181
}
178182
case FunctionKind.STATIC: {
179183
const className = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
180184
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
181-
tooltip = 'Calls the static method ' + className + '.' + functionName + '.';
185+
tooltip = Blockly.Msg.CALL_STATIC_METHOD_TOOLTIP;
186+
tooltip = tooltip
187+
.replace('{{className}}', className)
188+
.replace('{{functionName}}', functionName);
182189
break;
183190
}
184191
case FunctionKind.CONSTRUCTOR: {
185192
const className = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
186-
tooltip = 'Constructs an instance of the class ' + className + '.';
193+
tooltip = Blockly.Msg.CALL_CONSTRUCTOR_TOOLTIP;
194+
tooltip = tooltip.replace('{{className}}', className);
187195
break;
188196
}
189197
case FunctionKind.INSTANCE: {
190198
const className = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
191199
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
192-
tooltip = 'Calls the instance method ' + className + '.' + functionName + '.';
200+
tooltip = Blockly.Msg.CALL_INSTANCE_METHOD_TOOLTIP;
201+
tooltip = tooltip
202+
.replace('{{className}}', className)
203+
.replace('{{functionName}}', functionName);
193204
break;
194205
}
195206
case FunctionKind.INSTANCE_WITHIN: {
196207
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
197-
tooltip = 'Calls the instance method ' + functionName + '.';
208+
tooltip = Blockly.Msg.CALL_INSTANCE_METHOD_WITHIN_TOOLTIP;
209+
tooltip = tooltip.replace('{{functionName}}', functionName);
198210
break;
199211
}
200212
case FunctionKind.EVENT: {
201213
const eventName = this.getFieldValue(FIELD_EVENT_NAME);
202-
tooltip = 'Fires the event ' + eventName + '.';
214+
tooltip = Blockly.Msg.CALL_INSTANCE_METHOD_WITHIN_TOOLTIP;
215+
tooltip = tooltip.replace('{{eventName}}', eventName);
203216
break;
204217
}
205218
case FunctionKind.INSTANCE_COMPONENT: {
206219
const className = this.mrcComponentClassName;
207220
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
208221
if (this.mrcMechanismId) {
209-
tooltip = 'Calls the instance method ' + className + '.' + functionName +
210-
' on the component named ' + this.getFieldValue(FIELD_COMPONENT_NAME) +
211-
' in the mechanism named ' + this.getFieldValue(FIELD_MECHANISM_NAME) + '.';
222+
tooltip = Blockly.Msg.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD;
223+
tooltip = tooltip
224+
.replace('{{className}}', className)
225+
.replace('{{functionName}}', functionName)
226+
.replace('{{componentName}}', this.getFieldValue(FIELD_COMPONENT_NAME))
227+
.replace('{{mechanismName}}', this.getFieldValue(FIELD_MECHANISM_NAME));
212228
} else {
213-
tooltip = 'Calls the instance method ' + className + '.' + functionName +
214-
' on the component named ' + this.getFieldValue(FIELD_COMPONENT_NAME) + '.';
229+
tooltip = Blockly.Msg.CALL_COMPONENT_INSTANCE_METHOD;
230+
tooltip = tooltip
231+
.replace('{{className}}', className)
232+
.replace('{{functionName}}', functionName)
233+
.replace('{{componentName}}', this.getFieldValue(FIELD_COMPONENT_NAME));
215234
}
216235
break;
217236
}
218237
case FunctionKind.INSTANCE_ROBOT: {
219238
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
220-
tooltip = 'Calls the robot method ' + functionName + '.';
239+
tooltip = Blockly.Msg.CALL_INSTANCE_METHOD_WITHIN_TOOLTIP;
240+
tooltip = tooltip.replace('{{functionName}}', functionName);
221241
break;
222242
}
223243
case FunctionKind.INSTANCE_MECHANISM: {
224244
const className = this.mrcMechanismClassName;
225245
const functionName = this.getFieldValue(FIELD_FUNCTION_NAME);
226-
tooltip = 'Calls the instance method ' + className + '.' + functionName +
227-
' on the mechanism named ' + this.getFieldValue(FIELD_MECHANISM_NAME) + '.';
246+
tooltip = Blockly.Msg.CALL_MECHANISM_INSTANCE_METHOD;
247+
tooltip = tooltip
248+
.replace('{{className}}', className)
249+
.replace('{{functionName}}', functionName)
250+
.replace('{{mechanismName}}', this.getFieldValue(FIELD_MECHANISM_NAME));
228251
break;
229252
}
230253
default:
@@ -347,31 +370,31 @@ const CALL_PYTHON_FUNCTION = {
347370
switch (this.mrcFunctionKind) {
348371
case FunctionKind.BUILT_IN:
349372
this.appendDummyInput(INPUT_TITLE)
350-
.appendField('call')
373+
.appendField(Blockly.Msg.CALL)
351374
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
352375
break;
353376
case FunctionKind.MODULE:
354377
this.appendDummyInput(INPUT_TITLE)
355-
.appendField('call')
378+
.appendField(Blockly.Msg.CALL)
356379
.appendField(createFieldNonEditableText(''), FIELD_MODULE_OR_CLASS_NAME)
357380
.appendField('.')
358381
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
359382
break;
360383
case FunctionKind.STATIC:
361384
this.appendDummyInput(INPUT_TITLE)
362-
.appendField('call')
385+
.appendField(Blockly.Msg.CALL)
363386
.appendField(createFieldNonEditableText(''), FIELD_MODULE_OR_CLASS_NAME)
364387
.appendField('.')
365388
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
366389
break;
367390
case FunctionKind.CONSTRUCTOR:
368391
this.appendDummyInput(INPUT_TITLE)
369-
.appendField('create')
392+
.appendField(Blockly.Msg.CREATE)
370393
.appendField(createFieldNonEditableText(''), FIELD_MODULE_OR_CLASS_NAME);
371394
break;
372395
case FunctionKind.INSTANCE:
373396
this.appendDummyInput(INPUT_TITLE)
374-
.appendField('call')
397+
.appendField(Blockly.Msg.CALL)
375398
.appendField(createFieldNonEditableText(''), FIELD_MODULE_OR_CLASS_NAME)
376399
.appendField('.')
377400
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
@@ -380,7 +403,7 @@ const CALL_PYTHON_FUNCTION = {
380403
const input = this.getInput(INPUT_TITLE);
381404
if (!input) {
382405
this.appendDummyInput(INPUT_TITLE)
383-
.appendField('call')
406+
.appendField(Blockly.Msg.CALL)
384407
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
385408
}
386409
break;
@@ -389,14 +412,14 @@ const CALL_PYTHON_FUNCTION = {
389412
const input = this.getInput(INPUT_TITLE);
390413
if (!input) {
391414
this.appendDummyInput(INPUT_TITLE)
392-
.appendField('fire')
415+
.appendField(Blockly.Msg.FIRE)
393416
.appendField(createFieldNonEditableText(''), FIELD_EVENT_NAME);
394417
}
395418
break;
396419
}
397420
case FunctionKind.INSTANCE_COMPONENT: {
398421
const titleInput = this.appendDummyInput(INPUT_TITLE)
399-
.appendField('call');
422+
.appendField(Blockly.Msg.CALL);
400423
if (this.mrcMechanismId) {
401424
titleInput
402425
.appendField(createFieldNonEditableText(''), FIELD_MECHANISM_NAME)
@@ -412,15 +435,15 @@ const CALL_PYTHON_FUNCTION = {
412435
}
413436
case FunctionKind.INSTANCE_ROBOT: {
414437
this.appendDummyInput(INPUT_TITLE)
415-
.appendField('call')
416-
.appendField(createFieldNonEditableText('robot'))
438+
.appendField(Blockly.Msg.CALL)
439+
.appendField(createFieldNonEditableText(Blockly.Msg.ROBOT))
417440
.appendField('.')
418441
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
419442
break;
420443
}
421444
case FunctionKind.INSTANCE_MECHANISM: {
422445
this.appendDummyInput(INPUT_TITLE)
423-
.appendField('call')
446+
.appendField(Blockly.Msg.CALL)
424447
.appendField(createFieldNonEditableText(''), FIELD_MECHANISM_NAME)
425448
.appendField('.')
426449
.appendField(createFieldNonEditableText(''), FIELD_FUNCTION_NAME);
@@ -641,10 +664,9 @@ const CALL_PYTHON_FUNCTION = {
641664
if (privateComponent.className === this.mrcComponentClassName &&
642665
privateComponent.componentId === this.mrcComponentId) {
643666
foundComponent = true;
644-
warnings.push(
645-
'This blocks calls a method on a private component in the ' +
646-
mechanism.className + ' mechanism.'
647-
);
667+
let warning = Blockly.Msg.WARNING_CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT;
668+
warning = warning.replace('{{mechanismClassName}}', mechanism.className);
669+
warnings.push(warning);
648670
break
649671
}
650672
}
@@ -664,7 +686,7 @@ const CALL_PYTHON_FUNCTION = {
664686
}
665687

666688
if (!foundComponent) {
667-
warnings.push('This block calls a method on a component that no longer exists.');
689+
warnings.push(Blockly.Msg.WARNING_CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT);
668690
}
669691

670692
if (this.mrcMechanismId) {
@@ -682,9 +704,7 @@ const CALL_PYTHON_FUNCTION = {
682704
}
683705
}
684706
if (!foundMechanism) {
685-
warnings.push(
686-
'This block calls a method on a component that belongs to a mechanism that no ' +
687-
'longer exists.');
707+
warnings.push(Blockly.Msg.WARNING_CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM);
688708
}
689709
}
690710

@@ -698,7 +718,7 @@ const CALL_PYTHON_FUNCTION = {
698718
// visible warning on it.
699719
if (this.mrcFunctionKind === FunctionKind.INSTANCE_ROBOT) {
700720
if (editor.getModuleType() === storageModule.ModuleType.MECHANISM) {
701-
warnings.push('This block is not allowed to be used inside a mechanism.');
721+
warnings.push(Blockly.Msg.WARNING_CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM);
702722
} else {
703723
let foundRobotMethod = false;
704724
const robotMethods = editor.getMethodsFromRobot();
@@ -728,7 +748,7 @@ const CALL_PYTHON_FUNCTION = {
728748
}
729749
}
730750
if (!foundRobotMethod) {
731-
warnings.push('This block calls a method that no longer exists.');
751+
warnings.push(Blockly.Msg.WARNING_CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD);
732752
}
733753
}
734754
}
@@ -744,7 +764,7 @@ const CALL_PYTHON_FUNCTION = {
744764
// visible warning on it.
745765
if (this.mrcFunctionKind === FunctionKind.INSTANCE_MECHANISM) {
746766
if (editor.getModuleType() === storageModule.ModuleType.MECHANISM) {
747-
warnings.push('This block is not allowed to be used inside a mechanism.');
767+
warnings.push(Blockly.Msg.WARNING_CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM);
748768
} else {
749769
let foundMechanism = false;
750770
const mechanismsInRobot = editor.getMechanismsFromRobot();
@@ -786,15 +806,15 @@ const CALL_PYTHON_FUNCTION = {
786806
}
787807
}
788808
if (!foundMechanismMethod) {
789-
warnings.push('This block calls a method that no longer exists.');
809+
warnings.push(Blockly.Msg.WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD);
790810
}
791811

792812
// Since we found the mechanism, we can break out of the loop.
793813
break;
794814
}
795815
}
796816
if (!foundMechanism) {
797-
warnings.push('This block calls a method in a mechanism that no longer exists.');
817+
warnings.push(Blockly.Msg.WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM);
798818
}
799819
}
800820
}

src/blocks/tokens.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,29 @@ export function customTokens(t: (key: string) => string): typeof Blockly.Msg {
6161
OPMODE_ENABLED_TOOLTIP: t('BLOCKLY.TOOLTIP.OPMODE_ENABLED'),
6262
OPMODE_NAME_TOOLTIP: t('BLOCKLY.TOOLTIP.OPMODE_NAME'),
6363
OPMODE_GROUP_TOOLTIP: t('BLOCKLY.TOOLTIP.OPMODE_GROUP'),
64+
CALL: t('BLOCKLY.CALL'),
65+
ROBOT_LOWER_CASE: t('BLOCKLY.ROBOT_LOWER_CASE'),
66+
CREATE: t('BLOCKLY.CREATE'),
67+
FIRE: t('BLOCKLY.FIRE'),
68+
WARNING_CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT: t('BLOCKLY.WARNING.CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT'),
69+
WARNING_CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT: t('BLOCKLY.WARNING.CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT'),
70+
WARNING_CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM: t('BLOCKLY.WARNING.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM'),
71+
WARNING_CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM: t('BLOCKLY.WARNING.CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM'),
72+
WARNING_CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD: t('BLOCKLY.WARNING.CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD'),
73+
WARNING_CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM: t('BLOCKLY.WARNING.CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM'),
74+
WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD: t('BLOCKLY.WARNING.CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD'),
75+
WARNING_CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM: t('BLOCKLY.WARNING.CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM'),
76+
CALL_BUILTIN_FUNCTION_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_BUILTIN_FUNCTION'),
77+
CALL_MODULE_FUNCTION_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_MODULE_FUNCTION'),
78+
CALL_STATIC_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_STATIC_METHOD'),
79+
CALL_CONSTRUCTOR_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_CONSTRUCTOR'),
80+
CALL_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_INSTANCE_METHOD'),
81+
CALL_INSTANCE_METHOD_WITHIN_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_INSTANCE_METHOD_WITHIN'),
82+
FIRE_EVENT_TOOLTIP: t('BLOCKLY.TOOLTIP.FIRE_EVENT'),
83+
CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_MECHANISM_COMPONENT_INSTANCE_METHOD'),
84+
CALL_COMPONENT_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_COMPONENT_INSTANCE_METHOD'),
85+
CALL_ROBOT_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_ROBOT_INSTANCE_METHOD'),
86+
CALL_MECHANISM_INSTANCE_METHOD_TOOLTIP: t('BLOCKLY.TOOLTIP.CALL_MECHANISM_INSTANCE_METHOD'),
6487
MRC_CATEGORY_HARDWARE: t('BLOCKLY.CATEGORY.HARDWARE'),
6588
MRC_CATEGORY_ROBOT: t('BLOCKLY.CATEGORY.ROBOT'),
6689
MRC_CATEGORY_COMPONENTS: t('BLOCKLY.CATEGORY.COMPONENTS'),

src/i18n/locales/en/translation.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
"DISPLAY_GROUP": "Display Group",
5858
"PRINT": "print",
5959
"NO_MECHANISM_CONTENTS": "No Mechanism Contents",
60+
"CALL": "call",
61+
"ROBOT": "robot",
62+
"CREATE": "create",
63+
"FIRE": "fire",
6064
"TOOLTIP":{
6165
"EVALUATE_BUT_IGNORE_RESULT": "Executes the connected block and ignores the result. Allows you to call a function and ignore the return value.",
6266
"NONE": "Returns None.",
@@ -65,7 +69,18 @@
6569
"OPMODE_NAME": "The name shown on the Driver Station. If blank will use the class name.",
6670
"OPMODE_GROUP": "An optional group to group OpModes on Driver Station",
6771
"COMPONENTS": "These components are visible in this mechanism, the robot, and all opmodes.",
68-
"PRIVATE_COMPONENTS": "These components will not be visible in the robot or opmodes. They are only accessible within this mechanism."
72+
"PRIVATE_COMPONENTS": "These components will not be visible in the robot or opmodes. They are only accessible within this mechanism.",
73+
"CALL_BUILTIN_FUNCTION": "Calls the builtin function {{functionName}}.",
74+
"CALL_MODULE_FUNCTION": "Calls the module function {{moduleName}}.{{functionName}}.",
75+
"CALL_STATIC_METHOD": "Calls the static method {{className}}.{{functionName}}.",
76+
"CALL_CONSTRUCTOR": "Constructs an instance of the class {{className}}.",
77+
"CALL_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}}.",
78+
"CALL_INSTANCE_METHOD_WITHIN": "Calls the instance method {{functionName}}.",
79+
"FIRE_EVENT": "Fires the event named {{eventName}}.",
80+
"CALL_MECHANISM_COMPONENT_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}} on the component named {{componentName}} in the mechanism named {{mechanismName}}.",
81+
"CALL_COMPONENT_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}} on the component named {{componentName}}.",
82+
"CALL_ROBOT_INSTANCE_METHOD": "Calls the robot method {{functionName}}.",
83+
"CALL_MECHANISM_INSTANCE_METHOD": "Calls the instance method {{className}}.{{functionName}} on the mechanism named {{mechanismName}}."
6984
},
7085
"CATEGORY":{
7186
"LISTS": "Lists",
@@ -84,6 +99,16 @@
8499
"ADD_MECHANISM": "+ Mechanism",
85100
"ADD_COMPONENT": "+ Component",
86101
"TEST": "Test"
102+
},
103+
"WARNING":{
104+
"CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT": "This blocks calls a method on a private component in the {{mechanismClassName}} mechanism.",
105+
"CALL_COMPONENT_INSTANCE_METHOD_MISSING_COMPONENT": "This block calls a method on a component that no longer exists.",
106+
"CALL_MECHANISM_COMPONENT_INSTANCE_METHOD_MISSING_MECHANISM": "This block calls a method on a component that belongs to a mechanism that no longer exists.",
107+
"CALL_ROBOT_INSTANCE_METHOD_INSIDE_MECHANISM": "This block is not allowed to be used inside a mechanism.",
108+
"CALL_ROBOT_INSTANCE_METHOD_MISSING_METHOD": "This block calls a method that no longer exists in the robot.",
109+
"CALL_MECHANISM_INSTANCE_METHOD_INSIDE_MECHANISM": "This block is not allowed to be used inside a mechanism.",
110+
"CALL_MECHANISM_INSTANCE_METHOD_MISSING_METHOD": "This block calls a method that no longer exists in the mechanism.",
111+
"CALL_MECHANISM_INSTANCE_METHOD_MISSING_MECHANISM": "This block calls a method in a mechanism that no longer exists."
87112
}
88113
}
89114
}

0 commit comments

Comments
 (0)