Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions locales/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,34 @@ Wrap the caption literal in `ui.loc(...)` where the control renders it, then run
An application that consumes this library can override any of these translations
from its own catalogs: the app catalog layer wins over the library layers when
they are merged for a build.

## Keyboard character sets

`charsets.json` holds the per-language on-screen-keyboard character data. It is
consumed at build time into the text-entry `_loc` charset fields
(`alphabetLower`, `alphabetUpper`, `accentsLower`, `accentsUpper`, `symbols`),
which drive the letter, accent, and symbol pages of the text-entry keyboard.

The file is a JSON object keyed by language code. Each language maps to an
object whose fields are all optional; an omitted field inherits the module
default (ASCII `a-z` / `A-Z` for the alphabet, `-_.,!?@#` for symbols). Base
language keys serve their regional variants (`es` serves `es-ES` and `es-MX`,
`fr` serves `fr` and `fr-CA`, `pt` serves `pt-BR` and `pt-PT`); add a regional
key only where a region genuinely differs.

Field contracts:

- `alphabetLower` / `alphabetUpper` are the letter page. String order is key
order. The two strings are case-parallel: equal code-point length, with the
character at each index the lower and upper form of the same letter.
- `accentsLower` / `accentsUpper` are additional accented pairs, under the same
equal-length, positionally-paired contract. When the field is non-empty they
render on a dedicated accents page reached from the keyboard's page key; they
are also accepted by the input filter and case-normalized.
- `symbols` is the symbol page, in key order.

The letter page shows at most 39 letters (3 rows of 13); letters beyond that are
filter-accepted but not drawn. This bound drives the alphabet-vs-accents split:
an alphabet that fits within 39 places its diacritic letters in `alphabet*` at
their conventional positions, while a larger set keeps the base letters in
`alphabet*` and moves the overflow diacritic forms into `accents*`.
71 changes: 71 additions & 0 deletions locales/charsets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"fr": {
"accentsLower": "àâäçéèêëîïôöùûüÿœ",
"accentsUpper": "ÀÂÄÇÉÈÊËÎÏÔÖÙÛÜŸŒ"
},
"es": {
"alphabetLower": "abcdefghijklmnñopqrstuvwxyz",
"alphabetUpper": "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ",
"accentsLower": "áéíóúü",
"accentsUpper": "ÁÉÍÓÚÜ",
"symbols": "-_.,!?@#¡¿"
},
"ca": {
"accentsLower": "àçéèíïóòúü",
"accentsUpper": "ÀÇÉÈÍÏÓÒÚÜ"
},
"it": {
"accentsLower": "àèéìòù",
"accentsUpper": "ÀÈÉÌÒÙ"
},
"pt": {
"accentsLower": "áàâãçéêíóôõú",
"accentsUpper": "ÁÀÂÃÇÉÊÍÓÔÕÚ"
},
"de": {
"alphabetLower": "abcdefghijklmnopqrstuvwxyzäöü",
"alphabetUpper": "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ"
},
"nl": {
"accentsLower": "áéèëíïóöúü",
"accentsUpper": "ÁÉÈËÍÏÓÖÚÜ"
},
"pl": {
"alphabetLower": "aąbcćdeęfghijklłmnńoópqrsśtuvwxyzźż",
"alphabetUpper": "AĄBCĆDEĘFGHIJKLŁMNŃOÓPQRSŚTUVWXYZŹŻ"
},
"cs": {
"accentsLower": "áčďéěíňóřšťúůýž",
"accentsUpper": "ÁČĎÉĚÍŇÓŘŠŤÚŮÝŽ"
},
"ru": {
"alphabetLower": "абвгдеёжзийклмнопрстуфхцчшщъыьэюя",
"alphabetUpper": "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ"
},
"hr": {
"alphabetLower": "abcčćdđefghijklmnoprsštuvzž",
"alphabetUpper": "ABCČĆDĐEFGHIJKLMNOPRSŠTUVZŽ"
},
"hu": {
"alphabetLower": "aábcdeéfghiíjklmnoóöőpqrstuúüűvwxyz",
"alphabetUpper": "AÁBCDEÉFGHIÍJKLMNOÓÖŐPQRSTUÚÜŰVWXYZ"
},
"tr": {
"alphabetLower": "abcçdefgğhıijklmnoöprsştuüvyz",
"alphabetUpper": "ABCÇDEFGĞHIİJKLMNOÖPRSŞTUÜVYZ"
},
"eu": {
"alphabetLower": "abcdefghijklmnñopqrstuvwxyz",
"alphabetUpper": "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ",
"accentsLower": "çü",
"accentsUpper": "ÇÜ"
},
"cy": {
"accentsLower": "âêîôûŵŷ",
"accentsUpper": "ÂÊÎÔÛŴŶ"
},
"fil": {
"alphabetLower": "abcdefghijklmnñopqrstuvwxyz",
"alphabetUpper": "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"scripts": {
"format": "prettier --write \"**/*.ts\"",
"loc:strings": "node scripts/locstrings.mjs"
"loc:strings": "loc-strings"
Comment thread
humanapp marked this conversation as resolved.
},
"devDependencies": {
"prettier": "^3.8.3"
"prettier": "^3.8.3",
"@microbit-apps/ui-core": "github:microbit-apps/ui-core#v0.0.6"
}
}
2 changes: 1 addition & 1 deletion pxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"radio": "*",
"microphone": "*",
"display-shield": "github:microbit-apps/display-shield#v1.1.4",
"ui-core": "github:microbit-apps/ui-core#v0.0.5"
"ui-core": "github:microbit-apps/ui-core#v0.0.6"
},
"testDependencies": {}
}
33 changes: 32 additions & 1 deletion samples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace ui.controls.samples {
this.openModal(
new ui.UiTextEntryModal({
modalScopeId: "name-editor",
title: "Enter your name:",
title: loc("Enter your name:"),
initialText: this.name,
allowWhitespace: true,
allowSymbols: true,
Expand Down Expand Up @@ -169,6 +169,37 @@ namespace ui.controls.samples {
}
}

// Selects a locale by assigning the localization seams directly. A
// consuming app normally assigns these from its generated per-language
// file; any code that runs before the UI is constructed can do the same,
// which is how a sample or test drives a locale.
function applySpanishLocale(): void {
_loc.table = {
"space": "espacio",
"DEL": "SUP",
"Enter your name:": "Escribe tu nombre:",
}
_loc.alphabetLower = "abcdefghijklmnñopqrstuvwxyz"
_loc.alphabetUpper = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZ"
_loc.accentsLower = "áéíóúü"
_loc.accentsUpper = "ÁÉÍÓÚÜ"
_loc.symbols = "-_.,!?@#¡¿"
}

// French keeps the default alphabet and symbols and adds an accent set,
// so it exercises the accents keyboard page.
function applyFrenchLocale(): void {
_loc.table = {
"space": "espace",
"DEL": "SUP",
"Enter your name:": "Entre ton nom :",
}
_loc.accentsLower = "àâäçéèêëîïôöùûüÿœ"
_loc.accentsUpper = "ÀÂÄÇÉÈÊËÎÏÔÖÙÛÜŸŒ"
}

//applySpanishLocale()
applyFrenchLocale()
const runtime = new ui.UiRuntime(new ui.DisplayShieldFrameAdapter())
//runtime.push(new SettingsScreen(runtime))
runtime.push(new NameEntryScreen(runtime))
Expand Down
158 changes: 0 additions & 158 deletions scripts/locstrings.mjs

This file was deleted.

Loading
Loading