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
11 changes: 5 additions & 6 deletions button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace ui {
const BUTTON_FOCUS_LABEL_OFFSET = 1
const BUTTON_FOCUS_LABEL_PADDING = 1
const BUTTON_CONTENT_GAP = 3
const BUTTON_DEFAULT_FONT = bitmaps.font8
const BUTTON_CONTROL_HORIZONTAL_PADDING = 16
const BUTTON_CONTROL_VERTICAL_PADDING = 8
const BUTTON_CONTROL_MIN_WIDTH = 24
Expand Down Expand Up @@ -132,7 +131,7 @@ namespace ui {
content: UiControlContent,
style?: UiButtonStyle,
): number {
const font = (style && style.font) || BUTTON_DEFAULT_FONT
const font = (style && style.font) || locFont()
const text = content.text || ""
const textWidth = text.length ? font.charWidth * text.length : 0
const bitmapWidth = content.bitmap ? content.bitmap.width : 0
Expand All @@ -151,7 +150,7 @@ namespace ui {
content: UiControlContent,
style?: UiButtonStyle,
): number {
const font = (style && style.font) || BUTTON_DEFAULT_FONT
const font = (style && style.font) || locFont()
const text = content.text || ""
const textHeight = text.length ? font.charHeight : 0
const bitmapHeight = content.bitmap ? content.bitmap.height : 0
Expand Down Expand Up @@ -263,7 +262,7 @@ namespace ui {
this.contentRect(rect, content, style, contentRect)
const bitmap = content.bitmap
const text = this.contentText(content, style)
const font = style.font || BUTTON_DEFAULT_FONT
const font = style.font || locFont()
const color = style.color !== undefined ? style.color : 15
const graphicWidth = bitmap ? bitmap.width : 0

Expand Down Expand Up @@ -365,7 +364,7 @@ namespace ui {
}
const text = this.focusLabelText(content, style, focusLabelText)
if (text.length == 0) return
const font = style.font || BUTTON_DEFAULT_FONT
const font = style.font || locFont()
const textWidth = font.charWidth * text.length
const textHeight = font.charHeight
const padding = BUTTON_FOCUS_LABEL_PADDING
Expand Down Expand Up @@ -410,7 +409,7 @@ namespace ui {
style: UiButtonStyle,
output: Rect,
): void {
const font = style.font || BUTTON_DEFAULT_FONT
const font = style.font || locFont()
const text = this.contentText(content, style)
const textWidth = text.length > 0 ? font.charWidth * text.length : 0
const textHeight = text.length > 0 ? font.charHeight : 0
Expand Down
5 changes: 2 additions & 3 deletions label.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace ui {
const LABEL_DEFAULT_FONT = bitmaps.font8
const LABEL_CONTENT_GAP = 3

/**
Expand Down Expand Up @@ -63,7 +62,7 @@ namespace ui {
this.content_ = undefined
this.color_ = color !== undefined ? color : 1
this.backgroundColor_ = undefined
this.font_ = LABEL_DEFAULT_FONT
this.font_ = locFont()
this.width_ = 0
this.height_ = 0
} else {
Expand All @@ -72,7 +71,7 @@ namespace ui {
this.content_ = options
this.color_ = options.color !== undefined ? options.color : 1
this.backgroundColor_ = options.backgroundColor
this.font_ = options.font || LABEL_DEFAULT_FONT
this.font_ = options.font || locFont()
this.width_ = _uiControls.sizeWidth(options.size, 0)
this.height_ = _uiControls.sizeHeight(options.size, 0)
}
Expand Down
25 changes: 25 additions & 0 deletions locales/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Locale catalogs

Each catalog is a flat JSON object keyed by the English source string that
appears inside a `ui.loc(...)` / `ui.locc(...)` / `ui.locf(...)` call, mapping
that key to its translation for one language.

- `en.json` is generated -- run `npm run loc:strings` to regenerate it
from the `files` listed in `pxt.json`; do not edit it by hand.
- Every other file (`fr.json`, ...) is the translation catalog for one
language, keyed by the same English strings. A key missing from a catalog
falls back to the English string at runtime, so partial catalogs are safe.

Key-cap translations render on fixed-width keys, so keep them at most one
character longer than the English source (for example `space` -> `espace`,
`DEL` -> `SUP`).

## Adding a new caption

Wrap the caption literal in `ui.loc(...)` where the control renders it, then run
`npm run loc:strings` to regenerate `en.json`. Add translations to the
`<lang>.json` catalogs, keyed by the source string.

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.
10 changes: 10 additions & 0 deletions locales/ca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "SUP",
"OK": "OK",
"abc": "abc",
"space": "espai"
}
10 changes: 10 additions & 0 deletions locales/cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "SMAŽ",
"OK": "OK",
"abc": "abc",
"space": "mezera"
}
10 changes: 10 additions & 0 deletions locales/cy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "DIL",
"OK": "OK",
"abc": "abc",
"space": "bwlch"
}
10 changes: 10 additions & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "ENTF",
"OK": "OK",
"abc": "abc",
"space": "Leer"
}
10 changes: 10 additions & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "DEL",
"OK": "OK",
"abc": "abc",
"space": "space"
}
10 changes: 10 additions & 0 deletions locales/es-ES.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "SUP",
"OK": "OK",
"abc": "abc",
"space": "espacio"
}
Comment thread
humanapp marked this conversation as resolved.
10 changes: 10 additions & 0 deletions locales/es-MX.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "SUP",
"OK": "OK",
"abc": "abc",
"space": "espacio"
}
Comment thread
humanapp marked this conversation as resolved.
10 changes: 10 additions & 0 deletions locales/eu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "EZAB",
"OK": "OK",
"abc": "abc",
"space": "tartea"
}
10 changes: 10 additions & 0 deletions locales/fil.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "BURA",
"OK": "OK",
"abc": "abc",
"space": "puwang"
}
10 changes: 10 additions & 0 deletions locales/fr-CA.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "SUP",
"OK": "OK",
"abc": "abc",
"space": "espace"
}
10 changes: 10 additions & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "SUP",
"OK": "OK",
"abc": "abc",
"space": "espace"
}
10 changes: 10 additions & 0 deletions locales/hr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "DEL",
"OK": "OK",
"abc": "abc",
"space": "razmak"
}
10 changes: 10 additions & 0 deletions locales/hu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "TÖRL",
"OK": "OK",
"abc": "abc",
"space": "szóköz"
}
10 changes: 10 additions & 0 deletions locales/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "CANC",
"OK": "OK",
"abc": "abc",
"space": "spazio"
}
10 changes: 10 additions & 0 deletions locales/nl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "WIS",
"OK": "OK",
"abc": "abc",
"space": "spatie"
}
10 changes: 10 additions & 0 deletions locales/pl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "USUŃ",
"OK": "OK",
"abc": "abc",
"space": "spacja"
}
10 changes: 10 additions & 0 deletions locales/pt-BR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "APAG",
"OK": "OK",
"abc": "abc",
"space": "espaço"
}
10 changes: 10 additions & 0 deletions locales/pt-PT.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"#+=": "#+=",
"+/-": "+/-",
"123": "123",
"ABC": "ABC",
"DEL": "APAG",
"OK": "OK",
"abc": "abc",
"space": "espaço"
}
10 changes: 10 additions & 0 deletions locales/ru.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "СТЕР",
"OK": "OK",
"abc": "abc",
"space": "пробел"
}
10 changes: 10 additions & 0 deletions locales/tr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"123": "123",
"#+=": "#+=",
"+/-": "+/-",
"ABC": "ABC",
"DEL": "SİL",
"OK": "OK",
"abc": "abc",
"space": "boşluk"
}
5 changes: 3 additions & 2 deletions modal-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ namespace ui {
this.style_ && this.style_.color !== undefined
? this.style_.color
: 1,
font: locFont(),
})
this.renderControls(
surface,
Expand Down Expand Up @@ -502,7 +503,7 @@ namespace ui {
const text = controls[i].text || ""
textLength = Math.max(textLength, text.length)
}
return Math.max(24, textLength * bitmaps.font8.charWidth + 16)
return Math.max(24, textLength * locFont().charWidth + 16)
}

private titleHeight(): number {
Expand Down Expand Up @@ -779,7 +780,7 @@ namespace ui {
? this.title_
: this.title_.text
let width = titleText
? titleText.length * bitmaps.font8.charWidth
? titleText.length * locFont().charWidth
: 0
const bitmap =
this.title_ !== undefined && typeof this.title_ != "string"
Expand Down
9 changes: 4 additions & 5 deletions numeric-entry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace ui {
const NUMERIC_ENTRY_FONT = bitmaps.font8
const UI_NUMERIC_ENTRY_FLAG_DELETE_ENABLED = 1
const UI_NUMERIC_ENTRY_FLAG_CANCEL_ENABLED = 2

Expand Down Expand Up @@ -190,7 +189,7 @@ namespace ui {
surface,
rect,
this.text_,
NUMERIC_ENTRY_FONT,
locFont(),
)
}

Expand Down Expand Up @@ -967,10 +966,10 @@ namespace ui {
private keyTextForKey(key: UiNumericEntryModalKeyValue): string {
if (key >= 0 && key <= 9) return "" + key
if (key == UI_NUMERIC_ENTRY_KEY_DECIMAL_POINT) return "."
if (key == UI_NUMERIC_ENTRY_KEY_TOGGLE_SIGN) return "+/-"
if (key == UI_NUMERIC_ENTRY_KEY_TOGGLE_SIGN) return loc("+/-")
if (key == UI_NUMERIC_ENTRY_KEY_BACKSPACE) return "<-"
if (key == UI_NUMERIC_ENTRY_KEY_DELETE) return "DEL"
return "OK"
if (key == UI_NUMERIC_ENTRY_KEY_DELETE) return loc("DEL")
return loc("OK")
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"scripts": {
"format": "prettier --write \"**/*.ts\""
"format": "prettier --write \"**/*.ts\"",
"loc:strings": "node scripts/locstrings.mjs"
},
"devDependencies": {
"prettier": "^3.8.3"
Expand Down
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.4"
"ui-core": "github:microbit-apps/ui-core#v0.0.5"
},
"testDependencies": {}
}
Loading
Loading