Skip to content

Adopt ui-core's localization system#1

Merged
humanapp merged 3 commits into
mainfrom
humanapp/loc
Jul 23, 2026
Merged

Adopt ui-core's localization system#1
humanapp merged 3 commits into
mainfrom
humanapp/loc

Conversation

@humanapp

Copy link
Copy Markdown
Collaborator

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 same bitmaps.font8
object the removed constants held, so the renderer receives the identical
font object it always did.

What changed

  • Captions: the entry-widget key captions now resolve at render time via
    loc(...): text entry's abc, ABC, OK, 123, #+=, space and
    numeric entry's +/-, DEL, OK. Glyph-like captions (<-, digits,
    .) stay literal.
  • Default fonts: the module-level font constants (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 font field (a comment explains the constraint: a module-scope
    capture would run before the app assigns a per-language font). Per-control
    font overrides still win.
  • Measurement: width math now uses the font that actually renders.
    UiLabel measures with its own resolved font; the picker title draw
    passes an explicit font: locFont() (previously font-less auto-select)
    and both title/choice width calculations use locFont().charWidth instead
    of hardcoded bitmaps.font8.charWidth.
  • Tests: runLocalizationSmokeTest() renders a real UiTextEntryModal
    and asserts drawn captions flip from OK/space to table-supplied values
    and back, and that label measurement follows an assigned default font and
    reverts to font8 metrics when cleared.
  • Catalogs: locales/en.json (generated, 8 keys), 19 language catalogs
    for the captions, and locales/README.md documenting 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.
  • Tooling: scripts/locstrings.mjs (shared extractor) and
    npm run loc:strings.

Verification

  • mkc build green, including test files; assertions executed in the
    simulator.
  • English font resolution audited site-by-site: every draw/measure path
    resolves to the identical bitmaps.font8 object as before this change.
  • Localized captions exercised on hardware via downstream microcode-v2
    language builds (fr, pl, es-ES).

Release note

Parked as draft until ui-core bump, pending microbit-apps/ui-core#1

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 through locFont().
  • Updates measurement logic (e.g., picker title/choices) to use the active localized default font metrics rather than hardcoded font8 metrics.
  • Adds locale catalogs + documentation and introduces a loc:strings script to regenerate locales/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.

Comment thread locales/es-ES.json
Comment thread locales/es-MX.json

@thomasjball thomasjball left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

@humanapp
humanapp marked this pull request as ready for review July 23, 2026 02:54
@humanapp
humanapp merged commit 02d72fb into main Jul 23, 2026
1 check passed
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