From cec16cb77c5f9330909fcbc35beb5aa54d36171b Mon Sep 17 00:00:00 2001 From: GarboMuffin Date: Fri, 17 Nov 2023 09:55:49 -0600 Subject: [PATCH] L10N - Part 3 of many (#1156) --- extensions/-SIPC-/consoles.js | 50 ++--- extensions/-SIPC-/recording.js | 18 +- extensions/-SIPC-/time.js | 39 +++- extensions/Alestore/nfcwarp.js | 9 +- extensions/CST1229/images.js | 69 ++++--- extensions/CST1229/zip.js | 216 ++++++++++++++++++---- extensions/Clay/htmlEncode.js | 6 +- extensions/CubesterYT/TurboHook.js | 21 ++- extensions/CubesterYT/WindowControls.js | 127 ++++++++----- extensions/DNin/wake-lock.js | 13 +- extensions/DT/cameracontrols.js | 42 ++--- extensions/NexusKitten/controlcontrols.js | 29 ++- extensions/NexusKitten/moremotion.js | 57 ++++-- extensions/NexusKitten/sgrab.js | 101 ++++++++-- extensions/cs2627883/numericalencoding.js | 98 +++++----- 15 files changed, 633 insertions(+), 262 deletions(-) diff --git a/extensions/-SIPC-/consoles.js b/extensions/-SIPC-/consoles.js index 9fca8f1d85..e47a061681 100644 --- a/extensions/-SIPC-/consoles.js +++ b/extensions/-SIPC-/consoles.js @@ -14,7 +14,7 @@ getInfo() { return { id: "sipcconsole", - name: "Consoles", + name: Scratch.translate("Consoles"), color1: "#808080", color2: "#8c8c8c", color3: "#999999", @@ -24,61 +24,61 @@ { opcode: "Emptying", blockType: Scratch.BlockType.COMMAND, - text: "Clear Console", + text: Scratch.translate("Clear Console"), arguments: {}, }, { opcode: "Information", blockType: Scratch.BlockType.COMMAND, - text: "Information [string]", + text: Scratch.translate("Information [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Information", + defaultValue: Scratch.translate("Information"), }, }, }, { opcode: "Journal", blockType: Scratch.BlockType.COMMAND, - text: "Journal [string]", + text: Scratch.translate("Journal [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Journal", + defaultValue: Scratch.translate("Journal"), }, }, }, { opcode: "Warning", blockType: Scratch.BlockType.COMMAND, - text: "Warning [string]", + text: Scratch.translate("Warning [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Warning", + defaultValue: Scratch.translate("Warning"), }, }, }, { opcode: "Error", blockType: Scratch.BlockType.COMMAND, - text: "Error [string]", + text: Scratch.translate("Error [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Error", + defaultValue: Scratch.translate("Error"), }, }, }, { opcode: "debug", blockType: Scratch.BlockType.COMMAND, - text: "Debug [string]", + text: Scratch.translate("Debug [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Debug", + defaultValue: Scratch.translate("Debug"), }, }, }, @@ -87,62 +87,66 @@ { opcode: "group", blockType: Scratch.BlockType.COMMAND, - text: "Create a group named [string]", + text: Scratch.translate("Create a group named [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "group", + defaultValue: Scratch.translate("group"), }, }, }, { opcode: "groupCollapsed", blockType: Scratch.BlockType.COMMAND, - text: "Create a collapsed group named [string]", + text: Scratch.translate("Create a collapsed group named [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "group", + defaultValue: Scratch.translate("group"), }, }, }, { opcode: "groupEnd", blockType: Scratch.BlockType.COMMAND, - text: "Exit the current group", + text: Scratch.translate("Exit the current group"), arguments: {}, }, "---", { opcode: "Timeron", blockType: Scratch.BlockType.COMMAND, - text: "Start a timer named [string]", + text: Scratch.translate("Start a timer named [string]"), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Time", + defaultValue: Scratch.translate("Time"), }, }, }, { opcode: "Timerlog", blockType: Scratch.BlockType.COMMAND, - text: "Print the time run by the timer named [string]", + text: Scratch.translate( + "Print the time run by the timer named [string]" + ), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Time", + defaultValue: Scratch.translate("Time"), }, }, }, { opcode: "Timeroff", blockType: Scratch.BlockType.COMMAND, - text: "End the timer named [string] and print the time elapsed from start to end", + text: Scratch.translate( + "End the timer named [string] and print the time elapsed from start to end" + ), arguments: { string: { type: Scratch.ArgumentType.STRING, - defaultValue: "Time", + defaultValue: Scratch.translate("Time"), }, }, }, diff --git a/extensions/-SIPC-/recording.js b/extensions/-SIPC-/recording.js index 2265654c94..b4bc74f081 100644 --- a/extensions/-SIPC-/recording.js +++ b/extensions/-SIPC-/recording.js @@ -12,39 +12,45 @@ getInfo() { return { id: "sipcrecording", - name: "Recording", + name: Scratch.translate("Recording"), color1: "#696969", blocks: [ { opcode: "startRecording", blockType: Scratch.BlockType.COMMAND, - text: "Start recording", + text: Scratch.translate("Start recording"), blockIconURI: icon, arguments: {}, }, { opcode: "stopRecording", blockType: Scratch.BlockType.COMMAND, - text: "Stop recording", + text: Scratch.translate("Stop recording"), blockIconURI: icon, arguments: {}, }, { opcode: "stopRecordingAndDownload", blockType: Scratch.BlockType.COMMAND, - text: "Stop recording and download with [name] as filename", + text: Scratch.translate( + "Stop recording and download with [name] as filename" + ), blockIconURI: icon, arguments: { name: { type: Scratch.ArgumentType.STRING, - defaultValue: "recording.wav", + defaultValue: + Scratch.translate({ + default: "recording", + description: "Default file name", + }) + ".wav", }, }, }, { opcode: "isRecording", blockType: Scratch.BlockType.BOOLEAN, - text: "Recording?", + text: Scratch.translate("Recording?"), blockIconURI: icon, arguments: {}, }, diff --git a/extensions/-SIPC-/time.js b/extensions/-SIPC-/time.js index 6a8413c821..5690f799b9 100644 --- a/extensions/-SIPC-/time.js +++ b/extensions/-SIPC-/time.js @@ -13,7 +13,7 @@ getInfo() { return { id: "sipctime", - name: "Time", + name: Scratch.translate("Time"), color1: "#ff8000", color2: "#804000", color3: "#804000", @@ -23,19 +23,19 @@ { opcode: "Timestamp", blockType: Scratch.BlockType.REPORTER, - text: "current timestamp", + text: Scratch.translate("current timestamp"), arguments: {}, }, { opcode: "timezone", blockType: Scratch.BlockType.REPORTER, - text: "current time zone", + text: Scratch.translate("current time zone"), arguments: {}, }, { opcode: "Timedata", blockType: Scratch.BlockType.REPORTER, - text: "get [Timedata] from [timestamp]", + text: Scratch.translate("get [Timedata] from [timestamp]"), arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, @@ -51,7 +51,7 @@ { opcode: "TimestampToTime", blockType: Scratch.BlockType.REPORTER, - text: "convert [timestamp] to datetime", + text: Scratch.translate("convert [timestamp] to datetime"), arguments: { timestamp: { type: Scratch.ArgumentType.NUMBER, @@ -62,7 +62,7 @@ { opcode: "TimeToTimestamp", blockType: Scratch.BlockType.REPORTER, - text: "convert [time] to timestamp", + text: Scratch.translate("convert [time] to timestamp"), arguments: { time: { type: Scratch.ArgumentType.STRING, @@ -74,7 +74,32 @@ menus: { Time: { acceptReporters: true, - items: ["year", "month", "day", "hour", "minute", "second"], + items: [ + { + text: Scratch.translate("year"), + value: "year", + }, + { + text: Scratch.translate("month"), + value: "month", + }, + { + text: Scratch.translate("day"), + value: "day", + }, + { + text: Scratch.translate("hour"), + value: "hour", + }, + { + text: Scratch.translate("minute"), + value: "minute", + }, + { + text: Scratch.translate("second"), + value: "second", + }, + ], }, }, }; diff --git a/extensions/Alestore/nfcwarp.js b/extensions/Alestore/nfcwarp.js index 6e1face62c..e2d29b21b7 100644 --- a/extensions/Alestore/nfcwarp.js +++ b/extensions/Alestore/nfcwarp.js @@ -2,6 +2,7 @@ // ID: alestorenfc // Description: Allows reading data from NFC (NDEF) devices. Only works in Chrome on Android. // By: Alestore Games +// Context: NFC stands for "Near-field communication". Ideally check a real phone in your language to see how they translated it. (function (Scratch) { "use strict"; @@ -17,7 +18,7 @@ getInfo() { return { id: "alestorenfc", - name: "NFCWarp", + name: Scratch.translate("NFCWarp"), color1: "#FF4646", color2: "#FF0000", color3: "#990033", @@ -26,17 +27,17 @@ blocks: [ { blockType: Scratch.BlockType.LABEL, - text: "Only works in Chrome on Android", + text: Scratch.translate("Only works in Chrome on Android"), }, { opcode: "supported", blockType: Scratch.BlockType.BOOLEAN, - text: "NFC supported?", + text: Scratch.translate("NFC supported?"), }, { opcode: "nfcRead", blockType: Scratch.BlockType.REPORTER, - text: "read NFC tag", + text: Scratch.translate("read NFC tag"), disableMonitor: true, }, ], diff --git a/extensions/CST1229/images.js b/extensions/CST1229/images.js index 4f1691ba86..43b33ccd0a 100644 --- a/extensions/CST1229/images.js +++ b/extensions/CST1229/images.js @@ -33,7 +33,7 @@ { opcode: "getImage", blockType: Scratch.BlockType.REPORTER, - text: "new image from URL [IMAGEURL]", + text: Scratch.translate("new image from URL [IMAGEURL]"), arguments: { IMAGEURL: { type: Scratch.ArgumentType.STRING, @@ -47,7 +47,7 @@ { opcode: "penTrailsImage", blockType: Scratch.BlockType.REPORTER, - text: "pen trails as image", + text: Scratch.translate("pen trails as image"), arguments: {}, hideFromPalette: true, }, @@ -55,7 +55,7 @@ { opcode: "queryImage", blockType: Scratch.BlockType.REPORTER, - text: "[QUERY] of image [IMG]", + text: Scratch.translate("[QUERY] of image [IMG]"), arguments: { QUERY: { type: Scratch.ArgumentType.STRING, @@ -75,7 +75,9 @@ { opcode: "drawImage", blockType: Scratch.BlockType.COMMAND, - text: "stamp image [IMG] at x: [X] y: [Y] x scale: [XSCALE] y scale: [YSCALE]", + text: Scratch.translate( + "stamp image [IMG] at x: [X] y: [Y] x scale: [XSCALE] y scale: [YSCALE]" + ), arguments: { IMG: { // Intentional null input to require dropping a block in @@ -104,7 +106,7 @@ { opcode: "switchToImage", blockType: Scratch.BlockType.COMMAND, - text: "switch costume to image [IMG]", + text: Scratch.translate("switch costume to image [IMG]"), arguments: { IMG: { // Intentional null input to require dropping a block in @@ -116,20 +118,20 @@ { opcode: "imageID", blockType: Scratch.BlockType.REPORTER, - text: "current image ID", + text: Scratch.translate("current image ID"), arguments: {}, disableMonitor: true, }, { opcode: "resetCostume", blockType: Scratch.BlockType.COMMAND, - text: "switch back to costume", + text: Scratch.translate("switch back to costume"), arguments: {}, }, { opcode: "deleteImage", blockType: Scratch.BlockType.COMMAND, - text: "delete image [IMG]", + text: Scratch.translate("delete image [IMG]"), arguments: { IMG: { type: null, @@ -140,33 +142,52 @@ { opcode: "deleteAllImages", blockType: Scratch.BlockType.COMMAND, - text: "delete all images", + text: Scratch.translate("delete all images"), arguments: {}, }, ], menus: { queryImage: { acceptReporters: false, - items: this._queryImageMenu(), + items: [ + { + text: Scratch.translate("width"), + value: QueryImage.WIDTH, + }, + { + text: Scratch.translate("height"), + value: QueryImage.HEIGHT, + }, + { + text: Scratch.translate("top"), + value: QueryImage.TOP, + }, + { + text: Scratch.translate("bottom"), + value: QueryImage.BOTTOM, + }, + { + text: Scratch.translate("left"), + value: QueryImage.LEFT, + }, + { + text: Scratch.translate("right"), + value: QueryImage.RIGHT, + }, + { + text: Scratch.translate("rotation center x"), + value: QueryImage.ROTATION_CENTER_X, + }, + { + text: Scratch.translate("rotation center y"), + value: QueryImage.ROTATION_CENTER_Y, + }, + ], }, }, }; } - _queryImageMenu() { - const get = (param) => QueryImage[param]; - return [ - get("WIDTH"), - get("HEIGHT"), - get("TOP"), - get("BOTTOM"), - get("LEFT"), - get("RIGHT"), - get("ROTATION_CENTER_X"), - get("ROTATION_CENTER_Y"), - ]; - } - _createdImage(id) { if (!this.render || id === undefined || !this.render._allSkins[id]) return ""; diff --git a/extensions/CST1229/zip.js b/extensions/CST1229/zip.js index a80062b1ac..a8827db750 100644 --- a/extensions/CST1229/zip.js +++ b/extensions/CST1229/zip.js @@ -27,7 +27,7 @@ getInfo() { return { id: "cst1229zip", - name: "Zip", + name: Scratch.translate("Zip"), docsURI: "https://extensions.turbowarp.org/CST1229/zip", blockIconURI: extIcon, @@ -40,13 +40,13 @@ { opcode: "createEmpty", blockType: Scratch.BlockType.COMMAND, - text: "create empty archive", + text: Scratch.translate("create empty archive"), arguments: {}, }, { opcode: "open", blockType: Scratch.BlockType.COMMAND, - text: "open zip from [TYPE] [DATA]", + text: Scratch.translate("open zip from [TYPE] [DATA]"), arguments: { TYPE: { type: Scratch.ArgumentType.STRING, @@ -63,7 +63,9 @@ { opcode: "getZip", blockType: Scratch.BlockType.REPORTER, - text: "output zip type [TYPE] compression level [COMPRESSION]", + text: Scratch.translate( + "output zip type [TYPE] compression level [COMPRESSION]" + ), arguments: { TYPE: { type: Scratch.ArgumentType.STRING, @@ -80,13 +82,13 @@ { opcode: "close", blockType: Scratch.BlockType.COMMAND, - text: "close archive", + text: Scratch.translate("close archive"), arguments: {}, }, { opcode: "isOpen", blockType: Scratch.BlockType.BOOLEAN, - text: "archive is open?", + text: Scratch.translate("archive is open?"), arguments: {}, }, @@ -95,10 +97,11 @@ { opcode: "exists", blockType: Scratch.BlockType.BOOLEAN, - text: "[OBJECT] exists?", + text: Scratch.translate("[OBJECT] exists?"), arguments: { OBJECT: { type: Scratch.ArgumentType.STRING, + // Don't translate so this matches the default zip defaultValue: "folder/", }, }, @@ -106,11 +109,16 @@ { opcode: "writeFile", blockType: Scratch.BlockType.COMMAND, - text: "write file [FILE] content [CONTENT] type [TYPE]", + text: Scratch.translate( + "write file [FILE] content [CONTENT] type [TYPE]" + ), arguments: { FILE: { type: Scratch.ArgumentType.STRING, - defaultValue: "new file.txt", + defaultValue: `${Scratch.translate({ + default: "new file", + description: "Default file name", + })}.txt`, }, TYPE: { type: Scratch.ArgumentType.STRING, @@ -119,7 +127,7 @@ }, CONTENT: { type: Scratch.ArgumentType.STRING, - defaultValue: "Hello, world?", + defaultValue: Scratch.translate("Hello, world?"), }, }, }, @@ -130,10 +138,12 @@ arguments: { FROM: { type: Scratch.ArgumentType.STRING, + // Don't translate so matches default zip defaultValue: "hello.txt", }, TO: { type: Scratch.ArgumentType.STRING, + // Don't translate so matches default zip defaultValue: "hello renamed.txt", }, }, @@ -141,10 +151,11 @@ { opcode: "deleteFile", blockType: Scratch.BlockType.COMMAND, - text: "delete [FILE]", + text: Scratch.translate("delete [FILE]"), arguments: { FILE: { type: Scratch.ArgumentType.STRING, + // Don't translate so matches default zip defaultValue: "hello.txt", }, }, @@ -152,10 +163,11 @@ { opcode: "getFile", blockType: Scratch.BlockType.REPORTER, - text: "file [FILE] as [TYPE]", + text: Scratch.translate("file [FILE] as [TYPE]"), arguments: { FILE: { type: Scratch.ArgumentType.STRING, + // Don't translate so matches default zip defaultValue: "hello.txt", }, TYPE: { @@ -171,7 +183,7 @@ { opcode: "setFileMeta", blockType: Scratch.BlockType.COMMAND, - text: "set [META] of [FILE] to [VALUE]", + text: Scratch.translate("set [META] of [FILE] to [VALUE]"), arguments: { META: { type: Scratch.ArgumentType.STRING, @@ -180,6 +192,7 @@ }, FILE: { type: Scratch.ArgumentType.STRING, + // Don't translate so matches default zip defaultValue: "folder/dango.png", }, VALUE: { @@ -191,7 +204,7 @@ { opcode: "getFileMeta", blockType: Scratch.BlockType.REPORTER, - text: "[META] of [FILE]", + text: Scratch.translate("[META] of [FILE]"), arguments: { META: { type: Scratch.ArgumentType.STRING, @@ -200,6 +213,7 @@ }, FILE: { type: Scratch.ArgumentType.STRING, + // Don't translate so matches default zip defaultValue: "folder/dango.png", }, }, @@ -210,18 +224,18 @@ { opcode: "createDir", blockType: Scratch.BlockType.COMMAND, - text: "create directory [DIR]", + text: Scratch.translate("create directory [DIR]"), arguments: { DIR: { type: Scratch.ArgumentType.STRING, - defaultValue: "new folder", + defaultValue: Scratch.translate("new folder"), }, }, }, { opcode: "goToDir", blockType: Scratch.BlockType.COMMAND, - text: "go to directory [DIR]", + text: Scratch.translate("go to directory [DIR]"), arguments: { DIR: { type: Scratch.ArgumentType.STRING, @@ -232,7 +246,7 @@ { opcode: "getDir", blockType: Scratch.BlockType.REPORTER, - text: "contents of directory [DIR]", + text: Scratch.translate("contents of directory [DIR]"), arguments: { DIR: { type: Scratch.ArgumentType.STRING, @@ -243,7 +257,7 @@ { opcode: "currentDir", blockType: Scratch.BlockType.REPORTER, - text: "current directory path", + text: Scratch.translate("current directory path"), }, "---", @@ -251,18 +265,18 @@ { opcode: "setComment", blockType: Scratch.BlockType.COMMAND, - text: "set archive comment to [COMMENT]", + text: Scratch.translate("set archive comment to [COMMENT]"), arguments: { COMMENT: { type: Scratch.ArgumentType.STRING, - defaultValue: "any text", + defaultValue: Scratch.translate("any text"), }, }, }, { opcode: "getComment", blockType: Scratch.BlockType.REPORTER, - text: "archive comment", + text: Scratch.translate("archive comment"), arguments: {}, }, @@ -271,7 +285,7 @@ { opcode: "normalizePath", blockType: Scratch.BlockType.REPORTER, - text: "path [PATH] from [ORIGIN]", + text: Scratch.translate("path [PATH] from [ORIGIN]"), arguments: { PATH: { type: Scratch.ArgumentType.STRING, @@ -288,28 +302,115 @@ fileType: { // used in the open zip block acceptReporters: true, - items: ["URL", "base64", "hex", "binary", "string"], + items: [ + { + text: Scratch.translate("URL"), + value: "URL", + }, + { + text: Scratch.translate("base64"), + value: "base64", + }, + { + text: Scratch.translate("hex"), + value: "hex", + }, + { + text: Scratch.translate("binary"), + value: "binary", + }, + { + text: Scratch.translate("string"), + value: "string", + }, + ], }, zipFileType: { // used in the output zip block acceptReporters: true, - items: ["data: URL", "base64", "hex", "binary", "string"], + items: [ + { + text: Scratch.translate("data: URL"), + value: "data: URL", + }, + { + text: Scratch.translate("base64"), + value: "base64", + }, + { + text: Scratch.translate("hex"), + value: "hex", + }, + { + text: Scratch.translate("binary"), + value: "binary", + }, + { + text: Scratch.translate("string"), + value: "string", + }, + ], }, getFileType: { // used in the get file block acceptReporters: true, - items: ["text", "data: URL", "base64", "hex", "binary"], + items: [ + { + text: Scratch.translate("text"), + value: "text", + }, + { + text: Scratch.translate("data: URL"), + value: "data: URL", + }, + { + text: Scratch.translate("base64"), + value: "base64", + }, + { + text: Scratch.translate("hex"), + value: "hex", + }, + { + text: Scratch.translate("binary"), + value: "binary", + }, + ], }, writeFileType: { // used in the write file block acceptReporters: true, - items: ["text", "URL", "base64", "hex", "binary"], + items: [ + { + text: Scratch.translate("text"), + value: "text", + }, + { + text: Scratch.translate("URL"), + value: "URL", + }, + { + text: Scratch.translate("base64"), + value: "base64", + }, + { + text: Scratch.translate("hex"), + value: "hex", + }, + { + text: Scratch.translate("binary"), + value: "binary", + }, + ], }, compressionLevel: { acceptReporters: true, items: [ - { text: "no compression (fastest)", value: "0" }, - { text: "1 (fast, large)", value: "1" }, + { + text: Scratch.translate("no compression (fastest)"), + value: "0", + }, + { text: Scratch.translate("1 (fast, large)"), value: "1" }, { text: "2", value: "2" }, { text: "3", value: "3" }, { text: "4", value: "4" }, @@ -317,28 +418,61 @@ { text: "6", value: "6" }, { text: "7", value: "7" }, { text: "8", value: "8" }, - { text: "9 (slowest, smallest)", value: "9" }, + { text: Scratch.translate("9 (slowest, smallest)"), value: "9" }, ], }, fileMeta: { acceptReporters: true, items: [ - "name", - "path", - "folder", - "modification date", - "long modification date", - "modified days since 2000", - "unix modified timestamp", - "comment", + { + text: Scratch.translate("name"), + value: "name", + }, + { + text: Scratch.translate("path"), + value: "path", + }, + { + text: Scratch.translate("folder"), + value: "folder", + }, + { + text: Scratch.translate("modification date"), + value: "modification date", + }, + { + text: Scratch.translate("long modification date"), + value: "long modification date", + }, + { + text: Scratch.translate("modified days since 2000"), + value: "modified days since 2000", + }, + { + text: Scratch.translate("unix modified timestamp"), + value: "unix modified timestamp", + }, + { + text: Scratch.translate("comment"), + value: "comment", + }, ], }, setFileMeta: { acceptReporters: true, items: [ - "modified days since 2000", - "unix modified timestamp", - "comment", + { + text: Scratch.translate("modified days since 2000"), + value: "modified days since 2000", + }, + { + text: Scratch.translate("unix modified timestamp"), + value: "unix modified timestamp", + }, + { + text: Scratch.translate("comment"), + value: "comment", + }, ], }, }, diff --git a/extensions/Clay/htmlEncode.js b/extensions/Clay/htmlEncode.js index 37ee534e50..ba93b6c902 100644 --- a/extensions/Clay/htmlEncode.js +++ b/extensions/Clay/htmlEncode.js @@ -10,19 +10,19 @@ getInfo() { return { id: "claytonhtmlencode", - name: "HTML Encode", + name: Scratch.translate("HTML Encode"), blocks: [ { opcode: "encode", blockType: Scratch.BlockType.REPORTER, - text: "encode [text] as HTML-safe", + text: Scratch.translate("encode [text] as HTML-safe"), arguments: { text: { type: Scratch.ArgumentType.STRING, // don't use a script tag as the example here as the closing script // tag might break things when this extension gets inlined in packed // projects - defaultValue: "

Hello!

", + defaultValue: `

${Scratch.translate("Hello!")}

`, }, }, }, diff --git a/extensions/CubesterYT/TurboHook.js b/extensions/CubesterYT/TurboHook.js index a87d1192a4..7230166881 100644 --- a/extensions/CubesterYT/TurboHook.js +++ b/extensions/CubesterYT/TurboHook.js @@ -22,7 +22,7 @@ getInfo() { return { id: "cubesterTurboHook", - name: "TurboHook", + name: Scratch.translate("TurboHook"), color1: "#3c48c2", color2: "#2f39a1", color3: "#28318f", @@ -32,7 +32,9 @@ blocks: [ { opcode: "webhook", - text: "webhook data: [hookDATA] webhook url: [hookURL]", + text: Scratch.translate( + "webhook data: [hookDATA] webhook url: [hookURL]" + ), blockType: Scratch.BlockType.COMMAND, arguments: { hookURL: { @@ -63,7 +65,20 @@ menus: { PARAMS: { acceptReporters: true, - items: ["content", "name", "icon"], + items: [ + { + text: Scratch.translate("content"), + value: "content", + }, + { + text: Scratch.translate("name"), + value: "name", + }, + { + text: Scratch.translate("icon"), + value: "icon", + }, + ], }, }, }; diff --git a/extensions/CubesterYT/WindowControls.js b/extensions/CubesterYT/WindowControls.js index 92b0abb25c..08d85d27e2 100644 --- a/extensions/CubesterYT/WindowControls.js +++ b/extensions/CubesterYT/WindowControls.js @@ -22,7 +22,7 @@ getInfo() { return { id: "cubesterWindowControls", - name: "Window Controls", + name: Scratch.translate("Window Controls"), color1: "#359ed4", color2: "#298ec2", color3: "#2081b3", @@ -31,17 +31,17 @@ blocks: [ { - blockType: "label", - text: "May not work in normal browser tabs", + blockType: Scratch.BlockType.LABEL, + text: Scratch.translate("May not work in normal browser tabs"), }, { - blockType: "label", - text: "Refer to Documentation for details", + blockType: Scratch.BlockType.LABEL, + text: Scratch.translate("Refer to Documentation for details"), }, { opcode: "moveTo", blockType: Scratch.BlockType.COMMAND, - text: "move window to x: [X] y: [Y]", + text: Scratch.translate("move window to x: [X] y: [Y]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -56,7 +56,7 @@ { opcode: "moveToPresets", blockType: Scratch.BlockType.COMMAND, - text: "move window to the [PRESETS]", + text: Scratch.translate("move window to the [PRESETS]"), arguments: { PRESETS: { type: Scratch.ArgumentType.STRING, @@ -67,7 +67,7 @@ { opcode: "changeX", blockType: Scratch.BlockType.COMMAND, - text: "change window x by [X]", + text: Scratch.translate("change window x by [X]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -78,7 +78,7 @@ { opcode: "setX", blockType: Scratch.BlockType.COMMAND, - text: "set window x to [X]", + text: Scratch.translate("set window x to [X]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -89,7 +89,7 @@ { opcode: "changeY", blockType: Scratch.BlockType.COMMAND, - text: "change window y by [Y]", + text: Scratch.translate("change window y by [Y]"), arguments: { Y: { type: Scratch.ArgumentType.NUMBER, @@ -100,7 +100,7 @@ { opcode: "setY", blockType: Scratch.BlockType.COMMAND, - text: "set window y to [Y]", + text: Scratch.translate("set window y to [Y]"), arguments: { Y: { type: Scratch.ArgumentType.NUMBER, @@ -111,12 +111,12 @@ { opcode: "windowX", blockType: Scratch.BlockType.REPORTER, - text: "window x", + text: Scratch.translate("window x"), }, { opcode: "windowY", blockType: Scratch.BlockType.REPORTER, - text: "window y", + text: Scratch.translate("window y"), }, "---", @@ -124,7 +124,7 @@ { opcode: "resizeTo", blockType: Scratch.BlockType.COMMAND, - text: "resize window to width: [W] height: [H]", + text: Scratch.translate("resize window to width: [W] height: [H]"), arguments: { W: { type: Scratch.ArgumentType.NUMBER, @@ -139,7 +139,7 @@ { opcode: "resizeToPresets", blockType: Scratch.BlockType.COMMAND, - text: "resize window to [PRESETS]", + text: Scratch.translate("resize window to [PRESETS]"), arguments: { PRESETS: { type: Scratch.ArgumentType.STRING, @@ -150,7 +150,7 @@ { opcode: "changeW", blockType: Scratch.BlockType.COMMAND, - text: "change window width by [W]", + text: Scratch.translate("change window width by [W]"), arguments: { W: { type: Scratch.ArgumentType.NUMBER, @@ -161,7 +161,7 @@ { opcode: "setW", blockType: Scratch.BlockType.COMMAND, - text: "set window width to [W]", + text: Scratch.translate("set window width to [W]"), arguments: { W: { type: Scratch.ArgumentType.NUMBER, @@ -172,7 +172,7 @@ { opcode: "changeH", blockType: Scratch.BlockType.COMMAND, - text: "change window height by [H]", + text: Scratch.translate("change window height by [H]"), arguments: { H: { type: Scratch.ArgumentType.NUMBER, @@ -183,7 +183,7 @@ { opcode: "setH", blockType: Scratch.BlockType.COMMAND, - text: "set window height to [H]", + text: Scratch.translate("set window height to [H]"), arguments: { H: { type: Scratch.ArgumentType.NUMBER, @@ -194,17 +194,17 @@ { opcode: "matchStageSize", blockType: Scratch.BlockType.COMMAND, - text: "match stage size", + text: Scratch.translate("match stage size"), }, { opcode: "windowW", blockType: Scratch.BlockType.REPORTER, - text: "window width", + text: Scratch.translate("window width"), }, { opcode: "windowH", blockType: Scratch.BlockType.REPORTER, - text: "window height", + text: Scratch.translate("window height"), }, "---", @@ -212,17 +212,17 @@ { opcode: "isTouchingEdge", blockType: Scratch.BlockType.BOOLEAN, - text: "is window touching screen edge?", + text: Scratch.translate("is window touching screen edge?"), }, { opcode: "screenW", blockType: Scratch.BlockType.REPORTER, - text: "screen width", + text: Scratch.translate("screen width"), }, { opcode: "screenH", blockType: Scratch.BlockType.REPORTER, - text: "screen height", + text: Scratch.translate("screen height"), }, "---", @@ -230,7 +230,7 @@ { opcode: "isFocused", blockType: Scratch.BlockType.BOOLEAN, - text: "is window focused?", + text: Scratch.translate("is window focused?"), }, "---", @@ -238,18 +238,18 @@ { opcode: "changeTitleTo", blockType: Scratch.BlockType.COMMAND, - text: "set window title to [TITLE]", + text: Scratch.translate("set window title to [TITLE]"), arguments: { TITLE: { type: Scratch.ArgumentType.STRING, - defaultValue: "Hello World!", + defaultValue: Scratch.translate("Hello World!"), }, }, }, { opcode: "windowTitle", blockType: Scratch.BlockType.REPORTER, - text: "window title", + text: Scratch.translate("window title"), }, "---", @@ -257,17 +257,17 @@ { opcode: "enterFullscreen", blockType: Scratch.BlockType.COMMAND, - text: "enter fullscreen", + text: Scratch.translate("enter fullscreen"), }, { opcode: "exitFullscreen", blockType: Scratch.BlockType.COMMAND, - text: "exit fullscreen", + text: Scratch.translate("exit fullscreen"), }, { opcode: "isFullscreen", blockType: Scratch.BlockType.BOOLEAN, - text: "is window fullscreen?", + text: Scratch.translate("is window fullscreen?"), }, "---", @@ -276,23 +276,53 @@ opcode: "closeWindow", blockType: Scratch.BlockType.COMMAND, isTerminal: true, - text: "close window", + text: Scratch.translate("close window"), }, ], menus: { MOVE: { acceptReporters: true, items: [ - "center", - "right", - "left", - "top", - "bottom", - "top right", - "top left", - "bottom right", - "bottom left", - "random position", + { + text: Scratch.translate("center"), + value: "center", + }, + { + text: Scratch.translate("right"), + value: "right", + }, + { + text: Scratch.translate("left"), + value: "left", + }, + { + text: Scratch.translate("top"), + value: "top", + }, + { + text: Scratch.translate("bottom"), + value: "bottom", + }, + { + text: Scratch.translate("top right"), + value: "top right", + }, + { + text: Scratch.translate("top left"), + value: "top left", + }, + { + text: Scratch.translate("bottom right"), + value: "bottom right", + }, + { + text: Scratch.translate("bottom left"), + value: "bottom left", + }, + { + text: Scratch.translate("random position"), + value: "random position", + }, ], }, RESIZE: { @@ -497,11 +527,12 @@ return document.fullscreenElement !== null; } closeWindow() { - const editorConfirmation = [ - "Are you sure you want to close this window?", - "", - "(This message will not appear when the project is packaged)", - ].join("\n"); + const editorConfirmation = Scratch.translate({ + id: "editorConfirmation", + default: + "Are you sure you want to close this window?\n\n(This message will not appear when the project is packaged)", + }); + // @ts-expect-error if (typeof ScratchBlocks === "undefined" || confirm(editorConfirmation)) { window.close(); } diff --git a/extensions/DNin/wake-lock.js b/extensions/DNin/wake-lock.js index 41b98c8aa2..d3a9d4f56a 100644 --- a/extensions/DNin/wake-lock.js +++ b/extensions/DNin/wake-lock.js @@ -24,13 +24,16 @@ getInfo() { return { id: "dninwakelock", - name: "Wake Lock", + name: Scratch.translate("Wake Lock"), docsURI: "https://extensions.turbowarp.org/DNin/wake-lock", blocks: [ { opcode: "setWakeLock", blockType: Scratch.BlockType.COMMAND, - text: "turn wake lock [enabled]", + text: Scratch.translate({ + default: "turn wake lock [enabled]", + description: "[enabled] is a drop down with items 'on' and 'off'", + }), arguments: { enabled: { type: Scratch.ArgumentType.STRING, @@ -42,7 +45,7 @@ { opcode: "isLocked", blockType: Scratch.BlockType.BOOLEAN, - text: "is wake lock active?", + text: Scratch.translate("is wake lock active?"), }, ], menus: { @@ -50,11 +53,11 @@ acceptReporters: true, items: [ { - text: "on", + text: Scratch.translate("on"), value: "true", }, { - text: "off", + text: Scratch.translate("off"), value: "false", }, ], diff --git a/extensions/DT/cameracontrols.js b/extensions/DT/cameracontrols.js index 6d577b51d8..c3eca35460 100644 --- a/extensions/DT/cameracontrols.js +++ b/extensions/DT/cameracontrols.js @@ -234,7 +234,7 @@ getInfo() { return { id: "DTcameracontrols", - name: "Camera (Very Buggy)", + name: Scratch.translate("Camera (Very Buggy)"), color1: "#ff4da7", color2: "#de4391", @@ -246,7 +246,7 @@ { opcode: "moveSteps", blockType: Scratch.BlockType.COMMAND, - text: "move camera [val] steps", + text: Scratch.translate("move camera [val] steps"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -257,7 +257,7 @@ { opcode: "rotateCW", blockType: Scratch.BlockType.COMMAND, - text: "turn camera [image] [val] degrees", + text: Scratch.translate("turn camera [image] [val] degrees"), arguments: { image: { type: Scratch.ArgumentType.IMAGE, @@ -272,7 +272,7 @@ { opcode: "rotateCCW", blockType: Scratch.BlockType.COMMAND, - text: "turn camera [image] [val] degrees", + text: Scratch.translate("turn camera [image] [val] degrees"), arguments: { image: { type: Scratch.ArgumentType.IMAGE, @@ -288,7 +288,7 @@ { opcode: "goTo", blockType: Scratch.BlockType.COMMAND, - text: "move camera to [sprite]", + text: Scratch.translate("move camera to [sprite]"), arguments: { sprite: { type: Scratch.ArgumentType.STRING, @@ -299,7 +299,7 @@ { opcode: "setBoth", blockType: Scratch.BlockType.COMMAND, - text: "set camera to x: [x] y: [y]", + text: Scratch.translate("set camera to x: [x] y: [y]"), arguments: { x: { type: Scratch.ArgumentType.NUMBER, @@ -315,7 +315,7 @@ { opcode: "setDirection", blockType: Scratch.BlockType.COMMAND, - text: "set camera direction to [val]", + text: Scratch.translate("set camera direction to [val]"), arguments: { val: { type: Scratch.ArgumentType.ANGLE, @@ -326,7 +326,7 @@ { opcode: "pointTowards", blockType: Scratch.BlockType.COMMAND, - text: "point camera towards [sprite]", + text: Scratch.translate("point camera towards [sprite]"), arguments: { sprite: { type: Scratch.ArgumentType.STRING, @@ -338,7 +338,7 @@ { opcode: "changeX", blockType: Scratch.BlockType.COMMAND, - text: "change camera x by [val]", + text: Scratch.translate("change camera x by [val]"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -349,7 +349,7 @@ { opcode: "setX", blockType: Scratch.BlockType.COMMAND, - text: "set camera x to [val]", + text: Scratch.translate("set camera x to [val]"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -360,7 +360,7 @@ { opcode: "changeY", blockType: Scratch.BlockType.COMMAND, - text: "change camera y by [val]", + text: Scratch.translate("change camera y by [val]"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -371,7 +371,7 @@ { opcode: "setY", blockType: Scratch.BlockType.COMMAND, - text: "set camera y to [val]", + text: Scratch.translate("set camera y to [val]"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -383,17 +383,17 @@ { opcode: "getX", blockType: Scratch.BlockType.REPORTER, - text: "camera x", + text: Scratch.translate("camera x"), }, { opcode: "getY", blockType: Scratch.BlockType.REPORTER, - text: "camera y", + text: Scratch.translate("camera y"), }, { opcode: "getDirection", blockType: Scratch.BlockType.REPORTER, - text: "camera direction", + text: Scratch.translate("camera direction"), }, /* // debugging blocks @@ -412,7 +412,7 @@ { opcode: "changeZoom", blockType: Scratch.BlockType.COMMAND, - text: "change camera zoom by [val]", + text: Scratch.translate("change camera zoom by [val]"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -423,7 +423,7 @@ { opcode: "setZoom", blockType: Scratch.BlockType.COMMAND, - text: "set camera zoom to [val] %", + text: Scratch.translate("set camera zoom to [val] %"), arguments: { val: { type: Scratch.ArgumentType.NUMBER, @@ -434,13 +434,13 @@ { opcode: "getZoom", blockType: Scratch.BlockType.REPORTER, - text: "camera zoom", + text: Scratch.translate("camera zoom"), }, "---", { opcode: "setCol", blockType: Scratch.BlockType.COMMAND, - text: "set background color to [val]", + text: Scratch.translate("set background color to [val]"), arguments: { val: { type: Scratch.ArgumentType.COLOR, @@ -450,7 +450,7 @@ { opcode: "getCol", blockType: Scratch.BlockType.REPORTER, - text: "background color", + text: Scratch.translate("background color"), }, ], menus: { @@ -475,7 +475,7 @@ if (e.isOriginal && !e.isStage) sprites.push(e.sprite.name); }); if (sprites.length === 0) { - sprites.push("no sprites exist"); + sprites.push(Scratch.translate("no sprites exist")); } return sprites; } diff --git a/extensions/NexusKitten/controlcontrols.js b/extensions/NexusKitten/controlcontrols.js index e4d7351e0b..f0a152450f 100644 --- a/extensions/NexusKitten/controlcontrols.js +++ b/extensions/NexusKitten/controlcontrols.js @@ -56,7 +56,7 @@ getInfo() { return { id: "nkcontrols", - name: "Control Controls", + name: Scratch.translate("Control Controls"), color1: "#ffab19", color2: "#ec9c13", color3: "#b87d17", @@ -64,7 +64,7 @@ { opcode: "showOption", blockType: Scratch.BlockType.COMMAND, - text: "show [OPTION]", + text: Scratch.translate("show [OPTION]"), arguments: { OPTION: { type: Scratch.ArgumentType.STRING, @@ -75,7 +75,7 @@ { opcode: "hideOption", blockType: Scratch.BlockType.COMMAND, - text: "hide [OPTION]", + text: Scratch.translate("hide [OPTION]"), arguments: { OPTION: { type: Scratch.ArgumentType.STRING, @@ -87,7 +87,7 @@ { opcode: "optionShown", blockType: Scratch.BlockType.BOOLEAN, - text: "[OPTION] shown?", + text: Scratch.translate("[OPTION] shown?"), arguments: { OPTION: { type: Scratch.ArgumentType.STRING, @@ -99,7 +99,7 @@ { opcode: "optionExists", blockType: Scratch.BlockType.BOOLEAN, - text: "[OPTION] exists?", + text: Scratch.translate("[OPTION] exists?"), arguments: { OPTION: { type: Scratch.ArgumentType.STRING, @@ -111,7 +111,24 @@ menus: { OPTION: { acceptReporters: true, - items: ["green flag", "pause", "stop", "fullscreen"], + items: [ + { + text: Scratch.translate("green flag"), + value: "green flag", + }, + { + text: Scratch.translate("pause"), + value: "pause", + }, + { + text: Scratch.translate("stop"), + value: "stop", + }, + { + text: Scratch.translate("fullscreen"), + value: "fullscreen", + }, + ], }, }, }; diff --git a/extensions/NexusKitten/moremotion.js b/extensions/NexusKitten/moremotion.js index d3aee71d53..dcaca41096 100644 --- a/extensions/NexusKitten/moremotion.js +++ b/extensions/NexusKitten/moremotion.js @@ -17,20 +17,24 @@ getInfo() { return { id: "nkmoremotion", - name: "More Motion", + name: Scratch.translate("More Motion"), color1: "#4c97ff", color2: "#3373cc", blocks: [ { filter: [Scratch.TargetType.STAGE], blockType: Scratch.BlockType.LABEL, - text: "Stage selected: no motion blocks", + // We can copy this translation from scratch-blocks + text: + typeof ScratchBlocks !== "undefined" + ? ScratchBlocks.Msg["MOTION_STAGE_SELECTED"] + : "Stage selected: no motion blocks", }, { filter: [Scratch.TargetType.SPRITE], opcode: "changexy", blockType: Scratch.BlockType.COMMAND, - text: "change x: [X] y: [Y]", + text: Scratch.translate("change x: [X] y: [Y]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -46,7 +50,7 @@ filter: [Scratch.TargetType.SPRITE], opcode: "pointto", blockType: Scratch.BlockType.COMMAND, - text: "point towards x: [X] y: [Y]", + text: Scratch.translate("point towards x: [X] y: [Y]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -62,7 +66,7 @@ filter: [Scratch.TargetType.SPRITE], opcode: "rotationStyle", blockType: Scratch.BlockType.REPORTER, - text: "rotation style", + text: Scratch.translate("rotation style"), disableMonitor: true, }, "---", @@ -70,14 +74,18 @@ filter: [Scratch.TargetType.SPRITE], opcode: "fence", blockType: Scratch.BlockType.COMMAND, - text: "manually fence", + text: Scratch.translate({ + default: "manually fence", + description: + "This blocks forces the sprite to be onscreen if it moved offscreen.", + }), }, "---", { filter: [Scratch.TargetType.SPRITE], opcode: "steptowards", blockType: Scratch.BlockType.COMMAND, - text: "move [STEPS] steps towards x: [X] y: [Y]", + text: Scratch.translate("move [STEPS] steps towards x: [X] y: [Y]"), arguments: { STEPS: { type: Scratch.ArgumentType.NUMBER, @@ -97,7 +105,9 @@ filter: [Scratch.TargetType.SPRITE], opcode: "tweentowards", blockType: Scratch.BlockType.COMMAND, - text: "move [PERCENT]% of the way to x: [X] y: [Y]", + text: Scratch.translate( + "move [PERCENT]% of the way to x: [X] y: [Y]" + ), arguments: { PERCENT: { type: Scratch.ArgumentType.NUMBER, @@ -118,7 +128,7 @@ filter: [Scratch.TargetType.SPRITE], opcode: "directionto", blockType: Scratch.BlockType.REPORTER, - text: "direction to x: [X] y: [Y]", + text: Scratch.translate("direction to x: [X] y: [Y]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -134,7 +144,7 @@ filter: [Scratch.TargetType.SPRITE], opcode: "distanceto", blockType: Scratch.BlockType.REPORTER, - text: "distance from x: [X] y: [Y]", + text: Scratch.translate("distance from x: [X] y: [Y]"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -150,7 +160,7 @@ filter: [Scratch.TargetType.SPRITE], opcode: "spritewh", blockType: Scratch.BlockType.REPORTER, - text: "sprite [WHAT]", + text: Scratch.translate("sprite [WHAT]"), disableMonitor: true, arguments: { WHAT: { @@ -164,7 +174,7 @@ filter: [Scratch.TargetType.SPRITE], opcode: "touchingxy", blockType: Scratch.BlockType.BOOLEAN, - text: "touching x: [X] y: [Y]?", + text: Scratch.translate("touching x: [X] y: [Y]?"), arguments: { X: { type: Scratch.ArgumentType.NUMBER, @@ -180,7 +190,9 @@ filter: [Scratch.TargetType.SPRITE], opcode: "touchingrect", blockType: Scratch.BlockType.BOOLEAN, - text: "touching rectangle x1: [X1] y1: [Y1] x2: [X2] y2: [Y2]?", + text: Scratch.translate( + "touching rectangle x1: [X1] y1: [Y1] x2: [X2] y2: [Y2]?" + ), arguments: { X1: { type: Scratch.ArgumentType.NUMBER, @@ -204,7 +216,24 @@ menus: { WHAT: { acceptreporters: true, - items: ["width", "height", "costume width", "costume height"], + items: [ + { + text: Scratch.translate("width"), + value: "width", + }, + { + text: Scratch.translate("height"), + value: "height", + }, + { + text: Scratch.translate("costume width"), + value: "costume width", + }, + { + text: Scratch.translate("costume height"), + value: "costume height", + }, + ], }, }, }; diff --git a/extensions/NexusKitten/sgrab.js b/extensions/NexusKitten/sgrab.js index 6066bea0d2..c948cb1e40 100644 --- a/extensions/NexusKitten/sgrab.js +++ b/extensions/NexusKitten/sgrab.js @@ -17,7 +17,7 @@ getInfo() { return { id: "nexuskittensgrab", - name: "S-Grab", + name: Scratch.translate("S-Grab"), menuIconURI: icon, color1: "#ECA90B", color2: "#EBAF00", @@ -25,7 +25,7 @@ { opcode: "usergrab", blockType: Scratch.BlockType.REPORTER, - text: "grab [WHAT] count of user [WHO]", + text: Scratch.translate("grab [WHAT] count of user [WHO]"), arguments: { WHAT: { type: Scratch.ArgumentType.STRING, @@ -40,7 +40,7 @@ { opcode: "rankusergrab", blockType: Scratch.BlockType.REPORTER, - text: "global [WHAT] ranking for [WHO]", + text: Scratch.translate("global [WHAT] ranking for [WHO]"), arguments: { WHAT: { type: Scratch.ArgumentType.STRING, @@ -55,7 +55,7 @@ { opcode: "usergrab2", blockType: Scratch.BlockType.REPORTER, - text: "[WHAT] of user [WHO]", + text: Scratch.translate("[WHAT] of user [WHO]"), arguments: { WHAT: { type: Scratch.ArgumentType.STRING, @@ -71,7 +71,7 @@ { opcode: "projectgrab", blockType: Scratch.BlockType.REPORTER, - text: "grab [WHAT] count of project id [WHO]", + text: Scratch.translate("grab [WHAT] count of project id [WHO]"), arguments: { WHAT: { type: Scratch.ArgumentType.STRING, @@ -86,7 +86,9 @@ { opcode: "rankprojectgrab", blockType: Scratch.BlockType.REPORTER, - text: "global [WHAT] ranking for project id [WHO]", + text: Scratch.translate( + "global [WHAT] ranking for project id [WHO]" + ), arguments: { WHAT: { type: Scratch.ArgumentType.STRING, @@ -101,7 +103,7 @@ { opcode: "idtoname", blockType: Scratch.BlockType.REPORTER, - text: "name of project id [WHO]", + text: Scratch.translate("name of project id [WHO]"), arguments: { WHO: { type: Scratch.ArgumentType.STRING, @@ -112,7 +114,7 @@ { opcode: "idtoowner", blockType: Scratch.BlockType.REPORTER, - text: "creator of project id [WHO]", + text: Scratch.translate("creator of project id [WHO]"), arguments: { WHO: { type: Scratch.ArgumentType.STRING, @@ -124,23 +126,96 @@ menus: { WHAT: { acceptReporters: true, - items: ["follower", "following"], + items: [ + { + text: Scratch.translate("follower"), + value: "follower", + }, + { + text: Scratch.translate("following"), + value: "following", + }, + ], }, WHAT2: { acceptReporters: true, - items: ["follower", "love", "favorite", "view"], + items: [ + { + text: Scratch.translate("follower"), + value: "follower", + }, + { + text: Scratch.translate("love"), + value: "love", + }, + { + text: Scratch.translate("favorite"), + value: "favorite", + }, + { + text: Scratch.translate("view"), + value: "view", + }, + ], }, WHAT3: { acceptReporters: true, - items: ["love", "favorite", "view"], + items: [ + { + text: Scratch.translate("love"), + value: "love", + }, + { + text: Scratch.translate("favorite"), + value: "favorite", + }, + { + text: Scratch.translate("view"), + value: "view", + }, + ], }, WHAT4: { acceptReporters: true, - items: ["love", "favorite", "view"], + items: [ + { + text: Scratch.translate("love"), + value: "love", + }, + { + text: Scratch.translate("favorite"), + value: "favorite", + }, + { + text: Scratch.translate("view"), + value: "view", + }, + ], }, WHAT5: { acceptReporters: true, - items: ["about me", "wiwo", "location", "status"], + items: [ + { + text: Scratch.translate("about me"), + value: "about me", + }, + { + text: Scratch.translate({ + default: "wiwo", + description: + "WIWO stands for 'What I'm Working On', part of the Scratch profile page.", + }), + value: "wiwo", + }, + { + text: Scratch.translate("location"), + value: "location", + }, + { + text: Scratch.translate("status"), + value: "status", + }, + ], }, }, }; diff --git a/extensions/cs2627883/numericalencoding.js b/extensions/cs2627883/numericalencoding.js index 5212283722..57b44c2dd2 100644 --- a/extensions/cs2627883/numericalencoding.js +++ b/extensions/cs2627883/numericalencoding.js @@ -7,80 +7,99 @@ (function (Scratch) { "use strict"; + + // There are 149,186 unicode characters, so the maximum character code length is 6 + const MAX_CHAR_LEN = 6; + + /** + * @param {string} str + * @returns {string} + */ + const encode = (str) => { + let encoded = ""; + for (let i = 0; i < str.length; ++i) { + // Get character + const char = String(str.charCodeAt(i)); + // Pad encodedChar with 0s to ensure all encodedchars are the same length + const encodedChar = "0".repeat(MAX_CHAR_LEN - char.length) + char; + encoded += encodedChar; + } + return encoded; + }; + + /** + * @param {string} str + * @returns {string} + */ + const decode = (str) => { + if (str === "") { + return ""; + } + let decoded = ""; + // Create regex to split by char length + const regex = new RegExp(".{1," + MAX_CHAR_LEN + "}", "g"); + // Split into array of characters + const split = str.match(regex); + for (let i = 0; i < split.length; i++) { + // Get character from char code + const decodedChar = String.fromCharCode(+split[i]); + decoded += decodedChar; + } + return decoded; + }; + class NumericalEncodingExtension { - maxcharlength = 6; // There are 149,186 unicode characters, so the maximum character code length is 6 + /** @type {string|number} */ encoded = 0; + + /** @type {string|number} */ decoded = 0; + getInfo() { return { id: "cs2627883NumericalEncoding", - name: "Numerical Encoding", + name: Scratch.translate("Numerical Encoding"), blocks: [ { opcode: "NumericalEncode", blockType: Scratch.BlockType.COMMAND, - text: "Encode [DATA] to numbers", + text: Scratch.translate("Encode [DATA] to numbers"), arguments: { DATA: { type: Scratch.ArgumentType.STRING, - defaultValue: "Hello!", + defaultValue: Scratch.translate("Hello!"), }, }, }, { opcode: "NumericalDecode", blockType: Scratch.BlockType.COMMAND, - text: "Decode [ENCODED] back to text", + text: Scratch.translate("Decode [ENCODED] back to text"), arguments: { ENCODED: { type: Scratch.ArgumentType.STRING, - defaultValue: "000072000101000108000108000111000033", //Encoded "Hello!" + defaultValue: encode(Scratch.translate("Hello!")), }, }, }, { opcode: "GetNumericalEncoded", blockType: Scratch.BlockType.REPORTER, - text: "encoded", + text: Scratch.translate("encoded"), }, { opcode: "GetNumericalDecoded", blockType: Scratch.BlockType.REPORTER, - text: "decoded", + text: Scratch.translate("decoded"), }, ], }; } NumericalEncode(args) { - const toencode = String(args.DATA); - var encoded = ""; - for (let i = 0; i < toencode.length; ++i) { - // Get char code of character - var encodedchar = String(toencode.charCodeAt(i)); - // Pad encodedchar with 0s to ensure all encodedchars are the same length - encodedchar = - "0".repeat(this.maxcharlength - encodedchar.length) + encodedchar; - encoded += encodedchar; - } - this.encoded = encoded; + this.encoded = encode(Scratch.Cast.toString(args.DATA)); } NumericalDecode(args) { - const todecode = String(args.ENCODED); - if (todecode == "") { - this.decoded = ""; - return; - } - var decoded = ""; - // Create regex to split by char length - const regex = new RegExp(".{1," + this.maxcharlength + "}", "g"); - // Split into array of characters - var encodedchars = todecode.match(regex); - for (let i = 0; i < encodedchars.length; i++) { - // Get character from char code - var decodedchar = String.fromCharCode(encodedchars[i]); - decoded += decodedchar; - } - this.decoded = decoded; + this.decoded = decode(Scratch.Cast.toString(args.ENCODED)); } GetNumericalEncoded(args) { return this.encoded; @@ -90,14 +109,5 @@ } } - // Test Code - /* - encoding = new NumericalEncodingExtension(); - encodingNumericalEncode({"DATA": 'Hello!'}); - console.log(encoding.GetNumericalEncoded()) - encoding.NumericalDecode({"ENCODED": encoding.GetNumericalEncoded()}); - console.log(encoding.GetNumericalDecoded()); - */ - Scratch.extensions.register(new NumericalEncodingExtension()); })(Scratch);