Adopt ui-core's localization system#1
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adopts the ui-core localization runtime across ui-controls so that user-visible captions and default fonts are resolved through loc(...) / locFont() at render/measure time, and ships locale catalogs plus extraction tooling to maintain them.
Changes:
- Localizes text-entry and numeric-entry key captions via
loc(...)and routes relevant draw paths throughlocFont(). - Updates measurement logic (e.g., picker title/choices) to use the active localized default font metrics rather than hardcoded
font8metrics. - Adds locale catalogs + documentation and introduces a
loc:stringsscript to regeneratelocales/en.json, plus a localization smoke test.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| text-entry.ts | Localizes key captions and switches rendering to locFont(); removes module-scope font capture from key styles. |
| numeric-entry.ts | Localizes key captions and switches rendering to locFont(). |
| modal-grid.ts | Uses locFont() for picker title rendering and width calculations. |
| label.ts | Updates label default font selection to use locFont() instead of a module constant. |
| test.ts | Adds a localization smoke test covering caption substitution and default-font-driven measurement. |
| scripts/locstrings.mjs | Adds extractor to regenerate locales/en.json from loc* callsites in source files. |
| scripts/sync-local-pxt-deps.js | Adds helper script for syncing local PXT dependency cache blobs. |
| package.json | Adds npm run loc:strings script entry. |
| locales/README.md | Documents catalog rules and workflow (including key-cap length constraint). |
| locales/en.json | Adds generated English catalog for library captions. |
| locales/ca.json | Adds Catalan caption catalog. |
| locales/cs.json | Adds Czech caption catalog. |
| locales/cy.json | Adds Welsh caption catalog. |
| locales/de.json | Adds German caption catalog. |
| locales/es-ES.json | Adds Spanish (Spain) caption catalog. |
| locales/es-MX.json | Adds Spanish (Mexico) caption catalog. |
| locales/eu.json | Adds Basque caption catalog. |
| locales/fil.json | Adds Filipino caption catalog. |
| locales/fr.json | Adds French caption catalog. |
| locales/fr-CA.json | Adds French (Canada) caption catalog. |
| locales/hr.json | Adds Croatian caption catalog. |
| locales/hu.json | Adds Hungarian caption catalog. |
| locales/it.json | Adds Italian caption catalog. |
| locales/nl.json | Adds Dutch caption catalog. |
| locales/pl.json | Adds Polish caption catalog. |
| locales/pt-BR.json | Adds Portuguese (Brazil) caption catalog. |
| locales/pt-PT.json | Adds Portuguese (Portugal) caption catalog. |
| locales/ru.json | Adds Russian caption catalog. |
| locales/tr.json | Adds Turkish caption catalog. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
humanapp
marked this pull request as ready for review
July 23, 2026 02:54
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adopt the ui-core localization runtime
Routes every user-visible string and every default font choice in the library
through ui-core's loc runtime, and ships translation catalogs for the
library's own captions. English rendering is bit-identical: with no
translation table assigned,
ui.locFont()returns the samebitmaps.font8object the removed constants held, so the renderer receives the identical
font object it always did.
What changed
loc(...): text entry'sabc,ABC,OK,123,#+=,spaceandnumeric entry's
+/-,DEL,OK. Glyph-like captions (<-, digits,.) stay literal.BUTTON_DEFAULT_FONT,LABEL_DEFAULT_FONT,NUMERIC_ENTRY_FONT,TEXT_ENTRY_FONT) are removed;every use site resolves
style.font || locFont()at render/measure time.Two module-level text-entry styles and the constructor styles no longer
bake a
fontfield (a comment explains the constraint: a module-scopecapture would run before the app assigns a per-language font). Per-control
font overrides still win.
UiLabelmeasures with its own resolved font; the picker title drawpasses an explicit
font: locFont()(previously font-less auto-select)and both title/choice width calculations use
locFont().charWidthinsteadof hardcoded
bitmaps.font8.charWidth.runLocalizationSmokeTest()renders a realUiTextEntryModaland asserts drawn captions flip from
OK/spaceto table-supplied valuesand back, and that label measurement follows an assigned default font and
reverts to font8 metrics when cleared.
locales/en.json(generated, 8 keys), 19 language catalogsfor the captions, and
locales/README.mddocumenting the catalog rules,the key-cap length constraint, and the caption workflow. Apps can override
any library translation because app catalog layers win at merge.
scripts/locstrings.mjs(shared extractor) andnpm run loc:strings.Verification
mkc buildgreen, including test files; assertions executed in thesimulator.
resolves to the identical
bitmaps.font8object as before this change.language builds (fr, pl, es-ES).
Release note
Parked as draft until ui-core bump, pending microbit-apps/ui-core#1