Skip to content
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

Merged
merged 16 commits into from
Dec 10, 2024

Conversation

thsparks
Copy link
Contributor

@thsparks thsparks commented Dec 10, 2024

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

@thsparks thsparks requested review from pelikhan, a team and Copilot December 10, 2024 01:29

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 {
@pelikhan
Copy link
Member

  • to validate these commands, should you be running them through the existing translations?

Copy link
Member

@pelikhan pelikhan left a 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!

@thsparks
Copy link
Contributor Author

  • to validate these commands, should you be running them through the existing translations?

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.
@thsparks thsparks merged commit 44afb89 into master Dec 10, 2024
6 checks passed
@thsparks thsparks deleted the thsparks/block_string_validation_simpler branch December 10, 2024 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants