-
Notifications
You must be signed in to change notification settings - Fork 587
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
Pxt Cli Command for Validating Block Translations #10313
Conversation
…ode in localizeApisAsync that actually applies localized strings. Might not work well for the extension scenario since it relies on the original block string to be correct.
…ks/block_string_validation
…ll be matched to something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.
Comments skipped due to low confidence (3)
pxtlib/package.ts:924
- The word 'qName' should be 'QName'.
* Returns localized strings qName (+ some additional identification data) -> translation
cli/cli.ts:5167
- Consider using constants or an enum for key types to avoid potential typos and inconsistencies.
function getKeyType(key: string): "category" | "subcategory" | "group" | "block" | "unknown" {
cli/cli.ts:5084
- Consider adding more test cases for edge cases, such as empty strings and mismatched parameters.
function validateBlockString(original: string, toValidate: string): BlockStringValidationResult {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start!
I did some of that, and I made some test-case files (just added them to the PR description). But yes, I'll run it through a few more real ones tomorrow just to make sure I'm not missing anything. Would be nice to callout any live broken ones, too :) |
… keys as the original. I think partial translations are still okay and worth validating.
Overview
This creates a pxt cli command (
validatetranslatedblocks
) which takes a baseline file and a translated file and checks the syntax of translated block strings to ensure they won't break the block.I wanted to re-use
pxtc.parseBlockDefinition
which is why this is in the pxt cli and not mkc. If we want to expose it in mkc, we could implement it as a service operation in pxtcompiler/emitter/service.ts, which mkc can call into, but it felt out of place in that file, and the user would have needed to run the command from inside a makecode project to work, which felt weird.My initial approach was to actually run a build, apply the translated string to the block api info, and then check for differences from the original, but doing so added a lot of complexity with little benefit. As such, I've gone with this approach instead, which parses the strings and just manually checks parameters against the original.
Testing
We don't have a unit test project for the pxt cli (I may try to add one in the future...) but for now, my test cases are attached as files:
Baseline.json
Output.json
Translate.json