Skip to content

Commit 609ff1c

Browse files
authored
Merge pull request scratchfoundation#5463 from apple502j/apple-banana
Fix default parameter text loading in English
2 parents c7e3479 + eb7a449 commit 609ff1c

File tree

3 files changed

+88
-66
lines changed

3 files changed

+88
-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(target);
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: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ 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+
/* eslint-disable no-unused-vars */
8+
const motion = function (isInitialSetup, isStage, targetId) {
89
const stageSelected = ScratchBlocks.ScratchMsgs.translate(
910
'MOTION_STAGE_SELECTED',
1011
'Stage selected: no motion blocks'
@@ -150,7 +151,7 @@ const xmlEscape = function (unsafe) {
150151
});
151152
};
152153

153-
const looks = function (isStage, targetId, costumeName, backdropName) {
154+
const looks = function (isInitialSetup, isStage, targetId, costumeName, backdropName) {
154155
const hello = ScratchBlocks.ScratchMsgs.translate('LOOKS_HELLO', 'Hello!');
155156
const hmm = ScratchBlocks.ScratchMsgs.translate('LOOKS_HMM', 'Hmm...');
156157
return `
@@ -287,7 +288,7 @@ const looks = function (isStage, targetId, costumeName, backdropName) {
287288
`;
288289
};
289290

290-
const sound = function (isStage, targetId, soundName) {
291+
const sound = function (isInitialSetup, isStage, targetId, soundName) {
291292
return `
292293
<category name="%{BKY_CATEGORY_SOUND}" id="sound" colour="#D65CD6" secondaryColour="#BD42BD">
293294
<block id="${targetId}_sound_playuntildone" type="sound_playuntildone">
@@ -342,7 +343,7 @@ const sound = function (isStage, targetId, soundName) {
342343
`;
343344
};
344345

345-
const events = function (isStage) {
346+
const events = function (isInitialSetup, isStage) {
346347
return `
347348
<category name="%{BKY_CATEGORY_EVENTS}" id="events" colour="#FFD500" secondaryColour="#CC9900">
348349
<block type="event_whenflagclicked"/>
@@ -381,7 +382,7 @@ const events = function (isStage) {
381382
`;
382383
};
383384

384-
const control = function (isStage) {
385+
const control = function (isInitialSetup, isStage) {
385386
return `
386387
<category name="%{BKY_CATEGORY_CONTROL}" id="control" colour="#FFAB19" secondaryColour="#CF8B17">
387388
<block type="control_wait">
@@ -428,7 +429,7 @@ const control = function (isStage) {
428429
`;
429430
};
430431

431-
const sensing = function (isStage) {
432+
const sensing = function (isInitialSetup, isStage) {
432433
const name = ScratchBlocks.ScratchMsgs.translate('SENSING_ASK_TEXT', 'What\'s your name?');
433434
return `
434435
<category name="%{BKY_CATEGORY_SENSING}" id="sensing" colour="#4CBFE6" secondaryColour="#2E8EB8">
@@ -458,13 +459,15 @@ const sensing = function (isStage) {
458459
</block>
459460
${blockSeparator}
460461
`}
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>
462+
${isInitialSetup ? '' : `
463+
<block id="askandwait" type="sensing_askandwait">
464+
<value name="QUESTION">
465+
<shadow type="text">
466+
<field name="TEXT">${name}</field>
467+
</shadow>
468+
</value>
469+
</block>
470+
`}
468471
<block id="answer" type="sensing_answer"/>
469472
${blockSeparator}
470473
<block type="sensing_keypressed">
@@ -501,7 +504,7 @@ const sensing = function (isStage) {
501504
`;
502505
};
503506

504-
const operators = function () {
507+
const operators = function (isInitialSetup) {
505508
const apple = ScratchBlocks.ScratchMsgs.translate('OPERATORS_JOIN_APPLE', 'apple');
506509
const banana = ScratchBlocks.ScratchMsgs.translate('OPERATORS_JOIN_BANANA', 'banana');
507510
const letter = ScratchBlocks.ScratchMsgs.translate('OPERATORS_LETTEROF_APPLE', 'a');
@@ -610,49 +613,51 @@ const operators = function () {
610613
<block type="operator_or"/>
611614
<block type="operator_not"/>
612615
${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">
616+
${isInitialSetup ? '' : `
617+
<block type="operator_join">
618+
<value name="STRING1">
619+
<shadow type="text">
620+
<field name="TEXT">${apple} </field>
621+
</shadow>
622+
</value>
623+
<value name="STRING2">
624+
<shadow type="text">
625+
<field name="TEXT">${banana}</field>
626+
</shadow>
627+
</value>
628+
</block>
629+
<block type="operator_letter_of">
630+
<value name="LETTER">
631+
<shadow type="math_whole_number">
632+
<field name="NUM">1</field>
633+
</shadow>
634+
</value>
635+
<value name="STRING">
636+
<shadow type="text">
637+
<field name="TEXT">${apple}</field>
638+
</shadow>
639+
</value>
640+
</block>
641+
<block type="operator_length">
642+
<value name="STRING">
643+
<shadow type="text">
644+
<field name="TEXT">${apple}</field>
645+
</shadow>
646+
</value>
647+
</block>
648+
<block type="operator_contains" id="operator_contains">
649+
<value name="STRING1">
632650
<shadow type="text">
633-
<field name="TEXT">${apple}</field>
651+
<field name="TEXT">${apple}</field>
634652
</shadow>
635-
</value>
636-
</block>
637-
<block type="operator_length">
638-
<value name="STRING">
653+
</value>
654+
<value name="STRING2">
639655
<shadow type="text">
640-
<field name="TEXT">${apple}</field>
656+
<field name="TEXT">${letter}</field>
641657
</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>
658+
</value>
659+
</block>
660+
`}
656661
${blockSeparator}
657662
<block type="operator_mod">
658663
<value name="NUM1">
@@ -709,12 +714,16 @@ const myBlocks = function () {
709714
</category>
710715
`;
711716
};
717+
/* eslint-enable no-unused-vars */
712718

713719
const xmlOpen = '<xml style="display: none">';
714720
const xmlClose = '</xml>';
715721

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

732742
costumeName = xmlEscape(costumeName);
@@ -743,15 +753,15 @@ const makeToolboxXML = function (isStage, targetId, categoriesXML = [],
743753
}
744754
// return `undefined`
745755
};
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);
756+
const motionXML = moveCategory('motion') || motion(isInitialSetup, isStage, targetId);
757+
const looksXML = moveCategory('looks') || looks(isInitialSetup, isStage, targetId, costumeName, backdropName);
758+
const soundXML = moveCategory('sound') || sound(isInitialSetup, isStage, targetId, soundName);
759+
const eventsXML = moveCategory('event') || events(isInitialSetup, isStage, targetId);
760+
const controlXML = moveCategory('control') || control(isInitialSetup, isStage, targetId);
761+
const sensingXML = moveCategory('sensing') || sensing(isInitialSetup, isStage, targetId);
762+
const operatorsXML = moveCategory('operators') || operators(isInitialSetup, isStage, targetId);
763+
const variablesXML = moveCategory('data') || variables(isInitialSetup, isStage, targetId);
764+
const myBlocksXML = moveCategory('procedures') || myBlocks(isInitialSetup, isStage, targetId);
755765

756766
const everything = [
757767
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');
@@ -62,4 +63,15 @@ describe('Localization', () => {
6263
const logs = await getLogs();
6364
await expect(logs).toEqual([]);
6465
});
66+
67+
// test for #5445
68+
test('Loading with locale shows correct translation for string length block parameter', async () => {
69+
await loadUri(`${uri}?locale=ja`);
70+
await clickText('演算'); // Operators category in Japanese
71+
await new Promise(resolve => setTimeout(resolve, 1000)); // wait for blocks to scroll
72+
await clickText('の長さ', scope.blocksTab); // Click "length <apple>" block
73+
await findByText('3', scope.reportedValue); // Tooltip with result
74+
const logs = await getLogs();
75+
await expect(logs).toEqual([]);
76+
});
6577
});

0 commit comments

Comments
 (0)