Skip to content
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
38e066d
Add crowdin lang files
microbit-grace Jan 2, 2025
14ef95e
Add languages to settings
microbit-grace Jan 2, 2025
c0efc0d
Patch and compile languages
microbit-grace Jan 2, 2025
2d47c8f
Sync tool lang when MakeCode lang changes to a supported language
microbit-grace Jan 3, 2025
0b29750
Run prettier
microbit-grace Jan 3, 2025
ac4de2f
Add translate help link to lang dialog
microbit-grace Jan 3, 2025
9532a39
Upgrade ml-trainer-microbit to v0.2.0-dev.60
microbit-grace Jan 3, 2025
3cde3ee
Upgrade extension version to 1.0.5
microbit-grace Jan 3, 2025
278d259
WIP show icon text block width
microbit-grace Jan 3, 2025
9437131
Add update translations script
microbit-grace Jan 6, 2025
e5fe632
Calculate code view default block positions
microbit-grace Jan 6, 2025
1644297
Run prettier
microbit-grace Jan 6, 2025
8a75a09
Change alt text for CodeViewDefaultBlock to blocks
microbit-grace Jan 6, 2025
9b16d95
Debug: Log MakeCode lang
microbit-grace Jan 6, 2025
fe3bcb9
Run prettier
microbit-grace Jan 6, 2025
329e51f
Debug: Try removing lang from MakeCodeFrame
microbit-grace Jan 6, 2025
a8664ca
Revert "Debug: Try removing lang from MakeCodeFrame"
microbit-grace Jan 6, 2025
5d5f801
Debug: Log onWorkspaceSaveMakeCodeLang
microbit-grace Jan 6, 2025
32d02d2
Debug: Log onWorkspaceSync MakeCode lang
microbit-grace Jan 6, 2025
319784f
Run prettier
microbit-grace Jan 6, 2025
90f1b22
Fix lint
microbit-grace Jan 6, 2025
22eb83b
Remove debug console logs
microbit-grace Jan 6, 2025
5aed13e
Remove syncing language from MakeCode to tool
microbit-grace Jan 6, 2025
e3da73d
Update "ml.onStart|block" description
microbit-grace Jan 7, 2025
f2285f5
Remove no longer used makecode-block strings
microbit-grace Jan 7, 2025
a46efe6
Change from makecode-block-default-alt --> makecode-block-alt-prefix
microbit-grace Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: npm install --no-save @microbit-foundation/[email protected].58 @microbit-foundation/[email protected] @microbit-foundation/[email protected]
- run: npm install --no-save @microbit-foundation/[email protected].60 @microbit-foundation/[email protected] @microbit-foundation/[email protected]
if: github.repository_owner == 'microbit-foundation'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
89 changes: 89 additions & 0 deletions bin/update-translations.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* Update translations for CreateAI tool. To ensure translations for ML
* MakeCode blocks are consistent, translated strings are taken from
* pxt-microbit-ml machine-learning-strings.json. See CodeViewDefaultBlock.tsx
* to see where they are used.
*
* To update all translations, pass 2 arguments:
* 1. Path to CreateAI tool translation strings directory.
* 2. Path to machine-learning-strings.json translation strings directory.
*
* To only update MakeCode block translations, pass path to
* machine-learning-strings.json translation strings directory as an argument.
*
* Manually run `npm run i18n:compile` after.
*
* To add a language, add below and then update for all translations.
*/
const fs = require("fs");

const okExitStatus = 0;
const errExitStatus = 2;

const languages = ["en", "es-ES", "ja", "ko", "nl", "pl", "pt-br", "zh-tw"];
const enMessagesToAdd = {
"ml.onStart|block": {
defaultMessage: "on ML $event start",
description: "This string should be a Crowdin duplicate of the MakeCode extension block with the same text and use the same translation.",
},
};

const getMessagesToAdd = (mlStrings, langMessages) => {
return Object.keys(enMessagesToAdd).reduce((acc, k) => {
// Add or update with translated strings.
if (mlStrings[k]) {
return {
...acc,
[k]: { ...enMessagesToAdd[k], defaultMessage: mlStrings[k] },
};
}
// Fallback to en messages if no translation.
if (!langMessages[k]) {
return { ...acc, [k]: { ...enMessagesToAdd[k] } };
}
return { ...acc, [k]: { ...enMessagesToAdd[k], defaultMessage: acc[k].defaultMessage } };
}, {});
};
const getFileJSONContent = (filepath) => JSON.parse(fs.readFileSync(filepath));

const args = process.argv.slice(2);
if (args.length === 0 || args.length > 2) {
console.log(`Error: 2 arguments needed.
1. Path to CreateAI tool translation strings directory.
2. Path to machine-learning-strings.json translation strings directory. `);
process.exit(errExitStatus);
}

const [createAiTranslationsFilepath, mlTranslationsFilepath] =
args.length === 1 ? [null, args[0]] : args;

languages.forEach((language) => {
const lowerLang = language.toLowerCase();
const outputFilepath = `lang/ui.${lowerLang}.json`;

if (language === "en") {
// Assumes that lang/ui.en.json exists and directly adds enMessagesToAdd.
const langMessages = getFileJSONContent(outputFilepath);
fs.writeFileSync(
outputFilepath,
JSON.stringify({ ...langMessages, ...enMessagesToAdd })
);
return;
}

const srcLangFilepath = !createAiTranslationsFilepath
? `lang/ui.${lowerLang}.json`
: `${createAiTranslationsFilepath}/${language}/ui.en.json`;
const langMessages = getFileJSONContent(srcLangFilepath);

const mlFilepath = `${mlTranslationsFilepath}/${language}/machine-learning-strings.json`;
const mlStrings = getFileJSONContent(mlFilepath);

const messagesToAdd = getMessagesToAdd(mlStrings, langMessages);
fs.writeFileSync(
outputFilepath,
JSON.stringify({ ...langMessages, ...messagesToAdd })
);
});

process.exit(okExitStatus);
16 changes: 8 additions & 8 deletions lang/ui.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@
"defaultMessage": "Help & support",
"description": "Link or menu item link to support site"
},
"help-translate": {
"defaultMessage": "Help translate",
"description": "Help translate menu option text"
},
"home-action": {
"defaultMessage": "Home",
"description": "Home button text"
Expand Down Expand Up @@ -1059,18 +1063,10 @@
"defaultMessage": "MakeCode block: on ML {actionName} start, show icon {iconName}",
"description": "Makecode default block alt text"
Copy link
Author

@microbit-grace microbit-grace Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently I only use the translated "MakeCode block" portion of this string to compose the alt text (See CodeViewDefaultBlock.tsx line 56-65). Shall I manually trim the defaultMessages of all the "makecode-block-default-alt" in ui.xx.json so that only MakeCode block is being translated?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just have the prefix as a string.
So change to ID makecode-block-alt-prefix
text is just "MakeCode block:"
description is "Makecode block alt text prefix"

Then update the code to use that more straightforwardly.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code change looks good, thanks. Will try in a mo then merge.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use a46efe6 to reinstate these in Crowdin.

},
"makecode-block-on-ML": {
"defaultMessage": "on ML",
"description": "Makecode block text. The translation should match MakeCode translations."
},
"makecode-block-show-icon": {
"defaultMessage": "show icon",
"description": "Makecode block text. The translation should match MakeCode translations."
},
"makecode-block-start": {
"defaultMessage": "start",
"description": "Makecode block text. The translation should match MakeCode translations."
},
"makecode-load-error-dialog-body": {
"defaultMessage": "{appNameFull} has failed to load MakeCode. Please check your internet connection, reload the page then try again.",
"description": "Content of MakeCode load error dialog"
Expand All @@ -1083,6 +1079,10 @@
"defaultMessage": "Your micro:bit is not connected",
"description": "Live graph disconnected micro:bit status message"
},
"ml.onStart|block": {
"defaultMessage": "on ML $event start",
"description": "This string should be a Crowdin duplicate of the MakeCode extension block with the same text and use the same translation."
},
"more-edit-in-makecode-options": {
"defaultMessage": "More edit in MakeCode options",
"description": "Aria label for the additional actions menu to the right of the Edit in MakeCode button"
Expand Down
Loading
Loading