Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 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: "Translation not needed.",
},
};

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;
}, {});
};
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);
8 changes: 8 additions & 0 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 @@ -1083,6 +1087,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": "Translation not needed."
},
"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