Skip to content

Commit

Permalink
L10N - Part 2 of many (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Nov 16, 2023
1 parent 363da74 commit 4fe7475
Show file tree
Hide file tree
Showing 21 changed files with 403 additions and 256 deletions.
12 changes: 10 additions & 2 deletions development/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,16 @@ class Build {
generateL10N() {
const allStrings = {};

for (const file of Object.values(this.files)) {
const fileStrings = file.getStrings();
for (const [filePath, file] of Object.entries(this.files)) {
let fileStrings;
try {
fileStrings = file.getStrings();
} catch (error) {
console.error(error);
throw new Error(
`Error getting translations from ${filePath}: ${error}, see above`
);
}
if (!fileStrings) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions development/parse-extension-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const parseTranslations = (js) => {
const result = {};
for (const match of matches) {
const args = match.arguments;
if (args.length !== 1) {
throw new Error(`Scratch.translate() must have exactly 1 argument`);
if (args.length === 0) {
throw new Error(`Scratch.translate() needs at least 1 argument`);
}

const evaluated = evaluateAST(args[0]);
Expand Down
2 changes: 1 addition & 1 deletion extensions/-SIPC-/consoles.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Name: Consoles
// ID: sipcconsole
// Description: Blocks that interact the JavaScript console built in to your browser's developer tools.
// Description: Blocks that interact with the JavaScript console built in to your browser's developer tools.
// By: -SIPC-

(function (Scratch) {
Expand Down
12 changes: 12 additions & 0 deletions extensions/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ module.exports = {
{
selector: 'CallExpression[callee.object.object.name=Scratch][callee.object.property.name=translate][callee.property.name=setup]',
message: 'Do not call Scratch.translate.setup() yourself. Just use Scratch.translate() and let the build script handle it.'
},
{
selector: 'MethodDefinition[key.name=getInfo] Property[key.name=id][value.callee.property.name=translate]',
message: 'Do not translate extension ID'
},
{
selector: 'MethodDefinition[key.name=docsURI] Property[key.name=id][value.callee.property.name=translate]',
message: 'Do not translate docsURI'
},
{
selector: 'MethodDefinition[key.name=getInfo] Property[key.name=opcode][value.callee.property.name=translate]',
message: 'Do not translate block opcode'
}
]
}
Expand Down
18 changes: 9 additions & 9 deletions extensions/battery.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,51 +61,51 @@
class BatteryExtension {
getInfo() {
return {
name: "Battery",
name: Scratch.translate("Battery"),
id: "battery",
blocks: [
{
opcode: "charging",
blockType: Scratch.BlockType.BOOLEAN,
text: "charging?",
text: Scratch.translate("charging?"),
},
{
opcode: "level",
blockType: Scratch.BlockType.REPORTER,
text: "battery level",
text: Scratch.translate("battery level"),
},
{
opcode: "chargeTime",
blockType: Scratch.BlockType.REPORTER,
text: "seconds until charged",
text: Scratch.translate("seconds until charged"),
},
{
opcode: "dischargeTime",
blockType: Scratch.BlockType.REPORTER,
text: "seconds until empty",
text: Scratch.translate("seconds until empty"),
},
{
opcode: "chargingChanged",
blockType: Scratch.BlockType.EVENT,
text: "when charging changed",
text: Scratch.translate("when charging changed"),
isEdgeActivated: false,
},
{
opcode: "levelChanged",
blockType: Scratch.BlockType.EVENT,
text: "when battery level changed",
text: Scratch.translate("when battery level changed"),
isEdgeActivated: false,
},
{
opcode: "chargeTimeChanged",
blockType: Scratch.BlockType.EVENT,
text: "when time until charged changed",
text: Scratch.translate("when time until charged changed"),
isEdgeActivated: false,
},
{
opcode: "dischargeTimeChanged",
blockType: Scratch.BlockType.EVENT,
text: "when time until empty changed",
text: Scratch.translate("when time until empty changed"),
isEdgeActivated: false,
},
],
Expand Down
Loading

0 comments on commit 4fe7475

Please sign in to comment.