From 5dddcf11408a6441707b4ceaa5257c6dd92a70ce Mon Sep 17 00:00:00 2001 From: chrisgarrity <chrisg@media.mit.edu> Date: Tue, 18 Sep 2018 14:35:51 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20hard=20code=20the=20number=20fo?= =?UTF-8?q?r=20the=20default=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/containers/costume-tab.jsx | 4 +- src/containers/stage-selector.jsx | 2 +- src/containers/target-pane.jsx | 6 +- src/lib/default-project/project-data.js | 38 +++------- src/lib/default-project/project.json | 96 ------------------------- src/lib/shared-messages.js | 8 +-- 6 files changed, 18 insertions(+), 136 deletions(-) delete mode 100755 src/lib/default-project/project.json diff --git a/src/containers/costume-tab.jsx b/src/containers/costume-tab.jsx index d4563a02c..92a3e65d8 100644 --- a/src/containers/costume-tab.jsx +++ b/src/containers/costume-tab.jsx @@ -155,8 +155,8 @@ class CostumeTab extends React.Component { } handleNewBlankCostume () { const name = this.props.vm.editingTarget.isStage ? - this.props.intl.formatMessage(messages.backdrop) : - this.props.intl.formatMessage(messages.costume); + this.props.intl.formatMessage(messages.backdrop, {index: 1}) : + this.props.intl.formatMessage(messages.costume, {index: 1}); this.handleNewCostume(emptyCostume(name)); } handleSurpriseCostume () { diff --git a/src/containers/stage-selector.jsx b/src/containers/stage-selector.jsx index 7520ae6d4..ad302d51d 100644 --- a/src/containers/stage-selector.jsx +++ b/src/containers/stage-selector.jsx @@ -68,7 +68,7 @@ class StageSelector extends React.Component { this.addBackdropFromLibraryItem(item); } handleEmptyBackdrop () { - this.handleNewBackdrop(emptyCostume(this.props.intl.formatMessage(sharedMessages.backdrop))); + this.handleNewBackdrop(emptyCostume(this.props.intl.formatMessage(sharedMessages.backdrop, {index: 1}))); } handleBackdropUpload (e) { const storage = this.props.vm.runtime.storage; diff --git a/src/containers/target-pane.jsx b/src/containers/target-pane.jsx index 5bccb7c33..a34fb8e39 100644 --- a/src/containers/target-pane.jsx +++ b/src/containers/target-pane.jsx @@ -114,9 +114,9 @@ class TargetPane extends React.Component { handlePaintSpriteClick () { const formatMessage = this.props.intl.formatMessage; const emptyItem = emptySprite( - formatMessage(sharedMessages.sprite), - formatMessage(sharedMessages.sound), - formatMessage(sharedMessages.costume) + formatMessage(sharedMessages.sprite, {index: 1}), + formatMessage(sharedMessages.pop), + formatMessage(sharedMessages.costume, {index: 1}) ); this.props.vm.addSprite(JSON.stringify(emptyItem)).then(() => { setTimeout(() => { // Wait for targets update to propagate before tab switching diff --git a/src/lib/default-project/project-data.js b/src/lib/default-project/project-data.js index c021303aa..2ca5ebfc1 100644 --- a/src/lib/default-project/project-data.js +++ b/src/lib/default-project/project-data.js @@ -1,31 +1,7 @@ import {defineMessages} from 'react-intl'; +import sharedMessages from '../shared-messages'; -const messages = defineMessages({ - backdrop: { - defaultMessage: 'backdrop1', - description: 'Default name for the first backdrop', - id: 'gui.defaultProject.backdrop' - }, - pop: { - defaultMessage: 'pop', - description: 'Default name for the pop sound', - id: 'gui.defaultProject.pop' - }, - sprite: { - defaultMessage: 'Sprite1', - description: 'Name for the default sprite', - id: 'gui.defaultProject.sprite' - }, - costume1: { - defaultMessage: 'costume1', - description: 'Name for the first default costume', - id: 'gui.defaultProject.costume1' - }, - costume2: { - defaultMessage: 'costume2', - description: 'Name for the second default costume', - id: 'gui.defaultProject.costume2' - }, +let messages = defineMessages({ meow: { defaultMessage: 'Meow', description: 'Name for the meow sound', @@ -38,6 +14,8 @@ const messages = defineMessages({ } }); +messages = {...messages, ...sharedMessages}; + // use the default message if a translation function is not passed const defaultTranslator = msgObj => msgObj.defaultMessage; @@ -66,7 +44,7 @@ const projectData = translateFunction => { costumes: [ { assetId: 'cd21514d0531fdffb22204e0ec5ed84a', - name: translator(messages.backdrop), + name: translator(messages.backdrop, {index: 1}), md5ext: 'cd21514d0531fdffb22204e0ec5ed84a.svg', dataFormat: 'svg', rotationCenterX: 240, @@ -91,7 +69,7 @@ const projectData = translateFunction => { }, { isStage: false, - name: translator(messages.sprite), + name: translator(messages.sprite, {index: 1}), variables: {}, lists: {}, broadcasts: {}, @@ -100,7 +78,7 @@ const projectData = translateFunction => { costumes: [ { assetId: '09dc888b0b7df19f70d81588ae73420e', - name: translator(messages.costume1), + name: translator(messages.costume, {index: 1}), bitmapResolution: 1, md5ext: '09dc888b0b7df19f70d81588ae73420e.svg', dataFormat: 'svg', @@ -109,7 +87,7 @@ const projectData = translateFunction => { }, { assetId: '3696356a03a8d938318876a593572843', - name: translator(messages.costume2), + name: translator(messages.costume, {index: 2}), bitmapResolution: 1, md5ext: '3696356a03a8d938318876a593572843.svg', dataFormat: 'svg', diff --git a/src/lib/default-project/project.json b/src/lib/default-project/project.json deleted file mode 100755 index 6ffa9fa3c..000000000 --- a/src/lib/default-project/project.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "targets": [ - { - "isStage": true, - "name": "Stage", - "variables": { - "`jEk@4|i[#Fk?(8x)AV.-my variable": [ - "my variable", - 0 - ] - }, - "lists": {}, - "broadcasts": {}, - "blocks": {}, - "currentCostume": 0, - "costumes": [ - { - "assetId": "cd21514d0531fdffb22204e0ec5ed84a", - "name": "backdrop1", - "md5ext": "cd21514d0531fdffb22204e0ec5ed84a.svg", - "dataFormat": "svg", - "rotationCenterX": 240, - "rotationCenterY": 180 - } - ], - "sounds": [ - { - "assetId": "83a9787d4cb6f3b7632b4ddfebf74367", - "name": "pop", - "dataFormat": "wav", - "format": "", - "rate": 11025, - "sampleCount": 258, - "md5ext": "83a9787d4cb6f3b7632b4ddfebf74367.wav" - } - ], - "volume": 100, - "tempo": 60, - "videoTransparency": 50, - "videoState": "off" - }, - { - "isStage": false, - "name": "Sprite1", - "variables": {}, - "lists": {}, - "broadcasts": {}, - "blocks": {}, - "currentCostume": 0, - "costumes": [ - { - "assetId": "09dc888b0b7df19f70d81588ae73420e", - "name": "costume1", - "bitmapResolution": 1, - "md5ext": "09dc888b0b7df19f70d81588ae73420e.svg", - "dataFormat": "svg", - "rotationCenterX": 47, - "rotationCenterY": 55 - }, - { - "assetId": "3696356a03a8d938318876a593572843", - "name": "costume2", - "bitmapResolution": 1, - "md5ext": "3696356a03a8d938318876a593572843.svg", - "dataFormat": "svg", - "rotationCenterX": 47, - "rotationCenterY": 55 - } - ], - "sounds": [ - { - "assetId": "83c36d806dc92327b9e7049a565c6bff", - "name": "Meow", - "dataFormat": "wav", - "format": "", - "rate": 22050, - "sampleCount": 18688, - "md5ext": "83c36d806dc92327b9e7049a565c6bff.wav" - } - ], - "volume": 100, - "visible": true, - "x": 0, - "y": 0, - "size": 100, - "direction": 90, - "draggable": false, - "rotationStyle": "all around" - } - ], - "meta": { - "semver": "3.0.0", - "vm": "0.1.0", - "agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36" - } -} diff --git a/src/lib/shared-messages.js b/src/lib/shared-messages.js index 85ebe1c40..0de3e342d 100644 --- a/src/lib/shared-messages.js +++ b/src/lib/shared-messages.js @@ -2,21 +2,21 @@ import {defineMessages} from 'react-intl'; export default defineMessages({ backdrop: { - defaultMessage: 'backdrop1', + defaultMessage: 'backdrop{index}', description: 'Default name for a new backdrop, scratch will automatically adjust the number if necessary', id: 'gui.sharedMessages.backdrop' }, costume: { - defaultMessage: 'costume1', + defaultMessage: 'costume{index}', description: 'Default name for a new costume, scratch will automatically adjust the number if necessary', id: 'gui.sharedMessages.costume' }, sprite: { - defaultMessage: 'sprite1', + defaultMessage: 'Sprite{index}', description: 'Default name for a new sprite, scratch will automatically adjust the number if necessary', id: 'gui.sharedMessages.sprite' }, - sound: { + pop: { defaultMessage: 'pop', description: 'Name of the pop sound, the default sound added to a sprite', id: 'gui.sharedMessages.pop' -- GitLab