forked from microbit-foundation/cctd-ml-machine
-
Notifications
You must be signed in to change notification settings - Fork 4
First translation sync #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
38e066d
Add crowdin lang files
microbit-grace 14ef95e
Add languages to settings
microbit-grace c0efc0d
Patch and compile languages
microbit-grace 2d47c8f
Sync tool lang when MakeCode lang changes to a supported language
microbit-grace 0b29750
Run prettier
microbit-grace ac4de2f
Add translate help link to lang dialog
microbit-grace 9532a39
Upgrade ml-trainer-microbit to v0.2.0-dev.60
microbit-grace 3cde3ee
Upgrade extension version to 1.0.5
microbit-grace 278d259
WIP show icon text block width
microbit-grace 9437131
Add update translations script
microbit-grace e5fe632
Calculate code view default block positions
microbit-grace 1644297
Run prettier
microbit-grace 8a75a09
Change alt text for CodeViewDefaultBlock to blocks
microbit-grace 9b16d95
Debug: Log MakeCode lang
microbit-grace fe3bcb9
Run prettier
microbit-grace 329e51f
Debug: Try removing lang from MakeCodeFrame
microbit-grace a8664ca
Revert "Debug: Try removing lang from MakeCodeFrame"
microbit-grace 5d5f801
Debug: Log onWorkspaceSaveMakeCodeLang
microbit-grace 32d02d2
Debug: Log onWorkspaceSync MakeCode lang
microbit-grace 319784f
Run prettier
microbit-grace 90f1b22
Fix lint
microbit-grace 22eb83b
Remove debug console logs
microbit-grace 5aed13e
Remove syncing language from MakeCode to tool
microbit-grace e3da73d
Update "ml.onStart|block" description
microbit-grace f2285f5
Remove no longer used makecode-block strings
microbit-grace a46efe6
Change from makecode-block-default-alt --> makecode-block-alt-prefix
microbit-grace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 }} | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.