From 7449ba65ee8465709767bb3014471196477a8d58 Mon Sep 17 00:00:00 2001 From: dido18 Date: Sun, 26 Oct 2025 22:57:08 +0100 Subject: [PATCH 1/3] feat: add localization support for Arduino extensions and update message formatting --- .../src/extensions/arduino_basics/index.js | 14 ++++++++++++-- .../src/extensions/arduino_modulino/index.js | 15 +++++++++++++-- .../scratch-l10n/locales/editor-msgs.json | 9 +++++++++ .../scripts/patch-gui.js | 19 +++++++++++++++++++ 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json diff --git a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js index c3085fd..e4230d9 100644 --- a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js +++ b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js @@ -1,6 +1,7 @@ // const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message'); const BlockType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type'); const ArgumentType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type'); +const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message'); const io = require('../socket.io.min.js'); /** @@ -34,14 +35,23 @@ class ArduinoBasics { ArduinoBasics.prototype.getInfo = function () { return { id: 'arduinobasics', - name: "Arduino Basics", + name: "Arduino Basics", + // formatMessage({ + // id: 'arduino.basics', + // defaultMessage: 'Arduino Basics', + // description: 'The name of the "Arduino Basics" extension' + // }), menuIconURI: menuIconURI, blockIconURI: iconURI, blocks: [ { opcode: 'matrixDraw', blockType: BlockType.COMMAND, - text: 'draw [FRAME] on matrix', + text: formatMessage({ + id: 'arduino.drawMatrix', + defaultMessage: 'show [FRAME] on matrix', + description: 'Draw the given frame on the LED matrix' + }), func: 'matrixDraw', arguments: { FRAME: { diff --git a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js index adb39e0..1f65a82 100644 --- a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js +++ b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js @@ -1,5 +1,7 @@ const BlockType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type'); const ArgumentType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type'); +const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message'); + const io = require('../socket.io.min.js'); @@ -40,14 +42,23 @@ class ArduinoModulino { ArduinoModulino.prototype.getInfo = function () { return { id: 'arduinomodulino', - name: "Arduino Modulino", + name: "Arduino Modulino", + // formatMessage({ + // id: 'arduino.modulino', + // defaultMessage: 'Arduino Modulino', + // description: 'The name of the "Arduino Modulino" extension' + // }), menuIconURI: menuIconURI, blockIconURI: iconURI, blocks: [ { opcode: 'whenModulinoButtonsPressed', blockType: BlockType.HAT, - text: 'when modulino button [BTN] pressed', + text: formatMessage({ + id: 'arduino.whenModulinoButtonsPressed', + defaultMessage: 'when modulino button [BTN] pressed', + description: 'When the specified modulino button is pressed' + }), func: 'whenModulinoButtonsPressed', arguments: { BTN: { diff --git a/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json b/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json new file mode 100644 index 0000000..b05763d --- /dev/null +++ b/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json @@ -0,0 +1,9 @@ +{ + "it": { + "arduino.basics": "Arduino Base", + "arduino.drawMatrix": "mostra led [FRAME]", + + "arduino.modulino": "Arduino Modulino", + "arduino.whenModulinoButtonsPressed": "quando premi il bottone [BTN]" + } +} \ No newline at end of file diff --git a/scratch-arduino-extensions/scripts/patch-gui.js b/scratch-arduino-extensions/scripts/patch-gui.js index 6da7d94..4a6ec24 100644 --- a/scratch-arduino-extensions/scripts/patch-gui.js +++ b/scratch-arduino-extensions/scripts/patch-gui.js @@ -46,8 +46,27 @@ extensions.forEach(extension => { fs.writeFileSync(scratchVmVirtualMachineFile, vmCode); process.stdout.write("done\n"); } else process.stdout.write("skip"); + }); +process.stdout.write("\nAdding translation: "); +const scratchl10nEditorMsgsFile = path.resolve(BaseDir,"../scratch-editor/node_modules/scratch-l10n/locales/editor-msgs.js"); +let fileContent = fs.readFileSync(scratchl10nEditorMsgsFile, "utf8"); +let match = fileContent.match(/export default (\{.*\});/s); +if (!match) { + throw new Error("Could not find object in file"); +} +let obj = eval("(" + match[1] + ")"); + +const patchedMessages = path.resolve(BaseDir,"./scratch-l10n/locales/editor-msgs.json"); +let messages = JSON.parse(fs.readFileSync(patchedMessages, "utf8")); +for (let lang in messages) { + process.stdout.write(`\n\t - ${lang}`); + obj[lang] = { ...obj[lang], ...messages[lang] }; +} +let updatedContent = "export default " + JSON.stringify(obj, null, 2) + ";"; +fs.writeFileSync(scratchl10nEditorMsgsFile, updatedContent); + From 8351c3c1b7da2d5ed96da8d95eb3116f1f095a6c Mon Sep 17 00:00:00 2001 From: dido18 Date: Sun, 26 Oct 2025 23:16:46 +0100 Subject: [PATCH 2/3] en or it --- .../src/extensions/arduino_basics/index.js | 11 +++++------ .../src/extensions/arduino_modulino/index.js | 13 ++++++------- .../scratch-l10n/locales/editor-msgs.json | 2 +- scratch-arduino-extensions/scripts/patch-gui.js | 1 + 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js index e4230d9..f7b79ab 100644 --- a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js +++ b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js @@ -35,12 +35,11 @@ class ArduinoBasics { ArduinoBasics.prototype.getInfo = function () { return { id: 'arduinobasics', - name: "Arduino Basics", - // formatMessage({ - // id: 'arduino.basics', - // defaultMessage: 'Arduino Basics', - // description: 'The name of the "Arduino Basics" extension' - // }), + name: formatMessage({ + id: 'arduino.basics', + defaultMessage: 'Arduino Basics', + description: 'The name of the "Arduino Basics" extension' + }), menuIconURI: menuIconURI, blockIconURI: iconURI, blocks: [ diff --git a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js index 1f65a82..f7300bb 100644 --- a/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js +++ b/scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js @@ -42,12 +42,11 @@ class ArduinoModulino { ArduinoModulino.prototype.getInfo = function () { return { id: 'arduinomodulino', - name: "Arduino Modulino", - // formatMessage({ - // id: 'arduino.modulino', - // defaultMessage: 'Arduino Modulino', - // description: 'The name of the "Arduino Modulino" extension' - // }), + name: formatMessage({ + id: 'arduino.modulino', + defaultMessage: 'Arduino Modulino', + description: 'The name of the "Arduino Modulino" extension' + }), menuIconURI: menuIconURI, blockIconURI: iconURI, blocks: [ @@ -55,7 +54,7 @@ ArduinoModulino.prototype.getInfo = function () { opcode: 'whenModulinoButtonsPressed', blockType: BlockType.HAT, text: formatMessage({ - id: 'arduino.whenModulinoButtonsPressed', + id: 'arduino.modulino.whenPressed', defaultMessage: 'when modulino button [BTN] pressed', description: 'When the specified modulino button is pressed' }), diff --git a/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json b/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json index b05763d..ac54247 100644 --- a/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json +++ b/scratch-arduino-extensions/scratch-l10n/locales/editor-msgs.json @@ -4,6 +4,6 @@ "arduino.drawMatrix": "mostra led [FRAME]", "arduino.modulino": "Arduino Modulino", - "arduino.whenModulinoButtonsPressed": "quando premi il bottone [BTN]" + "arduino.modulino.whenPressed": "quando premi il bottone [BTN]" } } \ No newline at end of file diff --git a/scratch-arduino-extensions/scripts/patch-gui.js b/scratch-arduino-extensions/scripts/patch-gui.js index 4a6ec24..444d6c5 100644 --- a/scratch-arduino-extensions/scripts/patch-gui.js +++ b/scratch-arduino-extensions/scripts/patch-gui.js @@ -57,6 +57,7 @@ if (!match) { throw new Error("Could not find object in file"); } let obj = eval("(" + match[1] + ")"); +fs.copyFileSync(scratchl10nEditorMsgsFile, `${scratchl10nEditorMsgsFile}.orig`); const patchedMessages = path.resolve(BaseDir,"./scratch-l10n/locales/editor-msgs.json"); let messages = JSON.parse(fs.readFileSync(patchedMessages, "utf8")); From b391eee9f00d4f8a414ba3816f8d05e1f6108352 Mon Sep 17 00:00:00 2001 From: dido18 Date: Sun, 26 Oct 2025 23:18:16 +0100 Subject: [PATCH 3/3] pre --- .github/workflows/release.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index bbd333c..1d1768b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -48,4 +48,5 @@ jobs: with: artifacts: "build/scratch-arduino-app*.zip" allowUpdates: true + prerelease: ${{ contains(github.ref_name, 'rc') }} token: ${{ github.token }}