Skip to content

Commit ac0467d

Browse files
committed
Fix default parameter text loading in English
1 parent 8e3603a commit ac0467d

File tree

3 files changed

+86
-66
lines changed

3 files changed

+86
-66
lines changed

src/containers/blocks.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class Blocks extends React.Component {
339339
const targetCostumes = target.getCostumes();
340340
const targetSounds = target.getSounds();
341341
const dynamicBlocksXML = this.props.vm.runtime.getBlocksXML();
342-
return makeToolboxXML(target.isStage, target.id, dynamicBlocksXML,
342+
return makeToolboxXML(false, target.isStage, target.id, dynamicBlocksXML,
343343
targetCostumes[targetCostumes.length - 1].name,
344344
stageCostumes[stageCostumes.length - 1].name,
345345
targetSounds.length > 0 ? targetSounds[targetSounds.length - 1].name : ''

src/lib/make-toolbox-xml.js

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const categorySeparator = '<sep gap="36"/>';
44

55
const blockSeparator = '<sep gap="36"/>'; // At default scale, about 28px
66

7-
const motion = function (isStage, targetId) {
7+
const motion = function (_, isStage, targetId) {
88
const stageSelected = ScratchBlocks.ScratchMsgs.translate(
99
'MOTION_STAGE_SELECTED',
1010
'Stage selected: no motion blocks'
@@ -150,7 +150,7 @@ const xmlEscape = function (unsafe) {
150150
});
151151
};
152152

153-
const looks = function (isStage, targetId, costumeName, backdropName) {
153+
const looks = function (_, isStage, targetId, costumeName, backdropName) {
154154
const hello = ScratchBlocks.ScratchMsgs.translate('LOOKS_HELLO', 'Hello!');
155155
const hmm = ScratchBlocks.ScratchMsgs.translate('LOOKS_HMM', 'Hmm...');
156156
return `
@@ -287,7 +287,7 @@ const looks = function (isStage, targetId, costumeName, backdropName) {
287287
`;
288288
};
289289

290-
const sound = function (isStage, targetId, soundName) {
290+
const sound = function (_, isStage, targetId, soundName) {
291291
return `
292292
<category name="%{BKY_CATEGORY_SOUND}" id="sound" colour="#D65CD6" secondaryColour="#BD42BD">
293293
<block id="${targetId}_sound_playuntildone" type="sound_playuntildone">
@@ -342,7 +342,7 @@ const sound = function (isStage, targetId, soundName) {
342342
`;
343343
};
344344

345-
const events = function (isStage) {
345+
const events = function (_, isStage) {
346346
return `
347347
<category name="%{BKY_CATEGORY_EVENTS}" id="events" colour="#FFD500" secondaryColour="#CC9900">
348348
<block type="event_whenflagclicked"/>
@@ -381,7 +381,7 @@ const events = function (isStage) {
381381
`;
382382
};
383383

384-
const control = function (isStage) {
384+
const control = function (_, isStage) {
385385
return `
386386
<category name="%{BKY_CATEGORY_CONTROL}" id="control" colour="#FFAB19" secondaryColour="#CF8B17">
387387
<block type="control_wait">
@@ -428,7 +428,7 @@ const control = function (isStage) {
428428
`;
429429
};
430430

431-
const sensing = function (isStage) {
431+
const sensing = function (isInitialSetup, isStage) {
432432
const name = ScratchBlocks.ScratchMsgs.translate('SENSING_ASK_TEXT', 'What\'s your name?');
433433
return `
434434
<category name="%{BKY_CATEGORY_SENSING}" id="sensing" colour="#4CBFE6" secondaryColour="#2E8EB8">
@@ -458,13 +458,15 @@ const sensing = function (isStage) {
458458
</block>
459459
${blockSeparator}
460460
`}
461-
<block id="askandwait" type="sensing_askandwait">
462-
<value name="QUESTION">
463-
<shadow type="text">
464-
<field name="TEXT">${name}</field>
465-
</shadow>
466-
</value>
467-
</block>
461+
${isInitialSetup ? '' : `
462+
<block id="askandwait" type="sensing_askandwait">
463+
<value name="QUESTION">
464+
<shadow type="text">
465+
<field name="TEXT">${name}</field>
466+
</shadow>
467+
</value>
468+
</block>
469+
`}
468470
<block id="answer" type="sensing_answer"/>
469471
${blockSeparator}
470472
<block type="sensing_keypressed">
@@ -501,7 +503,7 @@ const sensing = function (isStage) {
501503
`;
502504
};
503505

504-
const operators = function () {
506+
const operators = function (isInitialSetup) {
505507
const apple = ScratchBlocks.ScratchMsgs.translate('OPERATORS_JOIN_APPLE', 'apple');
506508
const banana = ScratchBlocks.ScratchMsgs.translate('OPERATORS_JOIN_BANANA', 'banana');
507509
const letter = ScratchBlocks.ScratchMsgs.translate('OPERATORS_LETTEROF_APPLE', 'a');
@@ -610,49 +612,51 @@ const operators = function () {
610612
<block type="operator_or"/>
611613
<block type="operator_not"/>
612614
${blockSeparator}
613-
<block type="operator_join">
614-
<value name="STRING1">
615-
<shadow type="text">
616-
<field name="TEXT">${apple} </field>
617-
</shadow>
618-
</value>
619-
<value name="STRING2">
620-
<shadow type="text">
621-
<field name="TEXT">${banana}</field>
622-
</shadow>
623-
</value>
624-
</block>
625-
<block type="operator_letter_of">
626-
<value name="LETTER">
627-
<shadow type="math_whole_number">
628-
<field name="NUM">1</field>
629-
</shadow>
630-
</value>
631-
<value name="STRING">
615+
${isInitialSetup ? '' : `
616+
<block type="operator_join">
617+
<value name="STRING1">
618+
<shadow type="text">
619+
<field name="TEXT">${apple} </field>
620+
</shadow>
621+
</value>
622+
<value name="STRING2">
623+
<shadow type="text">
624+
<field name="TEXT">${banana}</field>
625+
</shadow>
626+
</value>
627+
</block>
628+
<block type="operator_letter_of">
629+
<value name="LETTER">
630+
<shadow type="math_whole_number">
631+
<field name="NUM">1</field>
632+
</shadow>
633+
</value>
634+
<value name="STRING">
635+
<shadow type="text">
636+
<field name="TEXT">${apple}</field>
637+
</shadow>
638+
</value>
639+
</block>
640+
<block type="operator_length">
641+
<value name="STRING">
642+
<shadow type="text">
643+
<field name="TEXT">${apple}</field>
644+
</shadow>
645+
</value>
646+
</block>
647+
<block type="operator_contains" id="operator_contains">
648+
<value name="STRING1">
632649
<shadow type="text">
633-
<field name="TEXT">${apple}</field>
650+
<field name="TEXT">${apple}</field>
634651
</shadow>
635-
</value>
636-
</block>
637-
<block type="operator_length">
638-
<value name="STRING">
652+
</value>
653+
<value name="STRING2">
639654
<shadow type="text">
640-
<field name="TEXT">${apple}</field>
655+
<field name="TEXT">${letter}</field>
641656
</shadow>
642-
</value>
643-
</block>
644-
<block type="operator_contains" id="operator_contains">
645-
<value name="STRING1">
646-
<shadow type="text">
647-
<field name="TEXT">${apple}</field>
648-
</shadow>
649-
</value>
650-
<value name="STRING2">
651-
<shadow type="text">
652-
<field name="TEXT">${letter}</field>
653-
</shadow>
654-
</value>
655-
</block>
657+
</value>
658+
</block>
659+
`}
656660
${blockSeparator}
657661
<block type="operator_mod">
658662
<value name="NUM1">
@@ -714,7 +718,10 @@ const xmlOpen = '<xml style="display: none">';
714718
const xmlClose = '</xml>';
715719

716720
/**
717-
* @param {!boolean} isStage - Whether the toolbox is for a stage-type target.
721+
* @param {!boolean} isInitialSetup - Whether the toolbox is for initial setup. If the mode is "initial setup",
722+
* blocks with localized default parameters (e.g. ask and wait) should not be loaded. (LLK/scratch-gui#5445)
723+
* @param {?boolean} isStage - Whether the toolbox is for a stage-type target. This is always set to true
724+
* when isInitialSetup is true.
718725
* @param {?string} targetId - The current editing target
719726
* @param {?Array.<object>} categoriesXML - optional array of `{id,xml}` for categories. This can include both core
720727
* and other extensions: core extensions will be placed in the normal Scratch order; others will go at the bottom.
@@ -725,8 +732,9 @@ const xmlClose = '</xml>';
725732
* @param {?string} soundName - The name of the default selected sound dropdown.
726733
* @returns {string} - a ScratchBlocks-style XML document for the contents of the toolbox.
727734
*/
728-
const makeToolboxXML = function (isStage, targetId, categoriesXML = [],
735+
const makeToolboxXML = function (isInitialSetup, isStage = true, targetId, categoriesXML = [],
729736
costumeName = '', backdropName = '', soundName = '') {
737+
isStage = isInitialSetup || isStage;
730738
const gap = [categorySeparator];
731739

732740
costumeName = xmlEscape(costumeName);
@@ -743,15 +751,15 @@ const makeToolboxXML = function (isStage, targetId, categoriesXML = [],
743751
}
744752
// return `undefined`
745753
};
746-
const motionXML = moveCategory('motion') || motion(isStage, targetId);
747-
const looksXML = moveCategory('looks') || looks(isStage, targetId, costumeName, backdropName);
748-
const soundXML = moveCategory('sound') || sound(isStage, targetId, soundName);
749-
const eventsXML = moveCategory('event') || events(isStage, targetId);
750-
const controlXML = moveCategory('control') || control(isStage, targetId);
751-
const sensingXML = moveCategory('sensing') || sensing(isStage, targetId);
752-
const operatorsXML = moveCategory('operators') || operators(isStage, targetId);
753-
const variablesXML = moveCategory('data') || variables(isStage, targetId);
754-
const myBlocksXML = moveCategory('procedures') || myBlocks(isStage, targetId);
754+
const motionXML = moveCategory('motion') || motion(isInitialSetup, isStage, targetId);
755+
const looksXML = moveCategory('looks') || looks(isInitialSetup, isStage, targetId, costumeName, backdropName);
756+
const soundXML = moveCategory('sound') || sound(isInitialSetup, isStage, targetId, soundName);
757+
const eventsXML = moveCategory('event') || events(isInitialSetup, isStage, targetId);
758+
const controlXML = moveCategory('control') || control(isInitialSetup, isStage, targetId);
759+
const sensingXML = moveCategory('sensing') || sensing(isInitialSetup, isStage, targetId);
760+
const operatorsXML = moveCategory('operators') || operators(isInitialSetup, isStage, targetId);
761+
const variablesXML = moveCategory('data') || variables(isInitialSetup, isStage, targetId);
762+
const myBlocksXML = moveCategory('procedures') || myBlocks(isInitialSetup, isStage, targetId);
755763

756764
const everything = [
757765
xmlOpen,

test/integration/localization.test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const {
88
getLogs,
99
loadUri,
1010
scope,
11-
rightClickText
11+
rightClickText,
12+
findByText
1213
} = new SeleniumHelper();
1314

1415
const uri = path.resolve(__dirname, '../../build/index.html');
@@ -66,4 +67,15 @@ describe('Localization', () => {
6667
const logs = await getLogs();
6768
await expect(logs).toEqual([]);
6869
});
70+
71+
// test for #5445
72+
test('Loading with locale shows correct translation for string length block parameter', async () => {
73+
await loadUri(`${uri}?locale=ja`);
74+
await clickText('演算'); // Operators category in Japanese
75+
await new Promise(resolve => setTimeout(resolve, 1000)); // wait for blocks to scroll
76+
await clickText('の長さ', scope.blocksTab); // Click "length <apple>" block
77+
await findByText('3', scope.reportedValue); // Tooltip with result
78+
const logs = await getLogs();
79+
await expect(logs).toEqual([]);
80+
});
6981
});

0 commit comments

Comments
 (0)