Repository navigation
Localize generated variable and SpriteKind labels without changing identity - #11615
Christian BR (ChrisesDK) wants to merge 3 commits into
Conversation
|
@microsoft-github-policy-service agree |
2c99e5e to
dbe896c
Compare
dbe896c to
f9692d0
Compare
|
Rebased onto current Joey Wunderlich (@jwunderl), could you please take a look at the Blockly/localization design when you have capacity? The key invariant is that generated variables and built-in The new fork-PR Actions runs are currently at GitHub's |
There was a problem hiding this comment.
Looks good to me though i'll tag in richard too for a quick look over the pxtblocks changes. Only other thing that comes to mind would be e.g. tutorials where sprite kind is used and translation needs to match between tutorial md text and the code snippets -- I guess should be fine, as the blocks would be rendering out as the translated versions after decompile / just md need to be updated? Can't really get better than that for this sort of thing
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved localization defects mishandle numeric suffixes, opt-in settings, and implicit receivers, while causing stale labels, screen-reader mismatches, and custom-kind dropdown failures.
5 open issues
Use own-property lookup for custom kind display names · New Honor per-API variable localization opt-in flags · New Accept all canonical decimal suffixes from 2 onward · New Refresh localized variable fields when block connections move · New Use localized variable names for accessible field values · New
What changed in this PR
Adds framework support for translating generated Blockly variable labels and built-in SpriteKind labels separately from their stored and compiler-facing identities.
Changes:
- Introduces opt-in variable metadata, localization-key extraction, and translation caching.
- Adds localized field and dropdown rendering, including numbered default-variable names.
- Adds display, serialization, extraction, compilation, and Python round-trip coverage.
| File | Description |
|---|---|
tests/pydecompile-test/pydecompilerunner.ts |
Adds variable and SpriteKind identifier round-trip assertions. |
tests/blocklycompiler-test/test.spec.ts |
Registers the localized-field test suite. |
tests/blocklycompiler-test/test-library/spritekind.ts |
Adds built-in kind labels and block identity metadata. |
tests/blocklycompiler-test/localizedFields.spec.ts |
Tests localized display text and unchanged stored values. |
tests/blocklycompiler-test/commentparsing.spec.ts |
Tests variable-key extraction and translation caching. |
tests/blocklycompiler-test/cases/sprite_kind.blocks |
Expands compilation fixtures to cover all built-in kinds. |
tests/blocklycompiler-test/baselines/sprite_kind.ts |
Updates expected SpriteKind compilation output. |
pxtlib/service.ts |
Collects kind display names and caches variable translations. |
pxtlib/blocks.ts |
Adds helpers for localizable default-variable names. |
pxtcompiler/emitter/service.ts |
Extracts display-only variable localization keys. |
pxtblocks/plugins/newVariableField/fieldVariable.ts |
Adds localization hooks for field and dropdown labels. |
pxtblocks/loader.ts |
Resolves localization from API context and numeric suffixes. |
pxtblocks/fields/field_kind.ts |
Uses kind display labels while retaining raw values. |
localtypings/pxtarget.d.ts |
Declares the variable-label localization opt-in flag. |
libs/pxt-common/pxt-core.d.ts |
Annotates the Array.push receiver for localization. |
Review effort: Max
f9692d0 to
75cd0d1
Compare
|
Thanks Joey Wunderlich (@jwunderl). Rebasing this branch onto current For tutorials, the stored code-facing |
|
Follow-up on the remaining block-label review threads: all five are now addressed and resolved.
Added regression coverage for those cases. After a clean rebuild, the full Blockly/Karma suite passes: 190/190. Richard Knoll (@riknoll), Joey suggested a PXTBlocks look-over. This branch now includes the resolved follow-up fixes and is ready for that review. |
8d34347 to
091b5a7
Compare
|
Rebased onto current Fresh validation on the rebased branch passes:
Richard Knoll (@riknoll), the branch is mergeable again and ready for the requested PXTBlocks review. |
091b5a7 to
20a288a
Compare
|
Rebased again onto current Fresh validation passes:
Richard Knoll (@riknoll), the branch is mergeable and ready for the requested PXTBlocks review. |

PXT upstream pull request
Title
Localize generated variable and SpriteKind labels without changing identityBase and head
microsoft/pxt:masterChrisesDK:complete-rendered-label-localizationcomplete-rendered-label-localizationat95be24b3dffb214754245672cad28722397e7d40Description
Summary
Some pupil-visible generated/default Blockly variable labels and built-in
SpriteKindlabels currently render raw identifiers, so they cannot belocalized through the normal MakeCode localization pipeline. This change
separates localized display text from stored and compiler-facing identity.
It adds opt-in, display-only localization for generated/default variable labels
and localized display labels for built-in
SpriteKinddropdown members.When MakeCode automatically uniquifies a generated default variable name,
numbered variants reuse the localized display of the base concept. For example,
generated
mySprite2andmySprite3display as the localized form ofmySpritefollowed by the raw suffixes2and3, without creating separatelocalization keys.
Compatibility
SpriteKinddropdown values remain raw (Player,Projectile,Food, andEnemy).behavior; a matching standalone user variable is not globally aliased.
production hardcoding.
Localization surface
This exposes 14 localization concepts:
{id:var}anim{id:var}location{id:var}myTile{id:var}tile list{id:var}projectile{id:var}otherSprite{id:var}myEnemy{id:var}picture{id:var}mySprite{id:var}listSpriteKind.PlayerSpriteKind.ProjectileSpriteKind.FoodSpriteKind.EnemyThe localization gaps addressed by this change were validated against the
rendered block-label mechanisms observed during a Danish Arcade localization
review. This is implementation-validation context, not formal exhaustive QA.
Validation
original verified implementation.
The final branch does not have a fresh complete Karma run: Puppeteer's cached
Chrome executable is unavailable locally. This is an environment block, not an
observed implementation test failure. A final combined rerun stopped after 427
passing tests at that browser-launch step and was not a complete combined run.
No implementation failure has been observed; normal upstream CI is still
expected.
Follow-up
pxt-common-packageshas a dependent follow-up that opts the relevant Arcadelibrary surfaces into this generic PXT capability. PXT must land and be
synchronized before that follow-up is merged.
Out of scope
This source PR deliberately does not include ordinary Crowdin wording fixes,
Crowdin-to-Arcade publication lag, Danish terminology decisions, or enabling
the
dalocale. Those are separate localization-content and deployment work.