Skip to content
Open
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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad

## [Unreleased]

### Added

- **German without du or Sie (`de-x-neutral`).** An opt-in wording variant of the German
booker catalogue that addresses nobody: "Tag auswählen" rather than "Wählen Sie einen
Tag". It is for operators whose own site is informal, where the formal widget stands out
and an informal one would be wrong for everyone else. `de` is unchanged and stays formal.
The variant is never offered in the language switcher or matched from `Accept-Language`;
select it with `?lang=de-x-neutral` or `<calnode-booking lang="de-x-neutral">`.

### Fixed

- **Buttons and inputs in the booking UI now use the surrounding font.** Form controls
take their font family from the browser stylesheet, so day cells, time slots and the
confirm button rendered in the system font beside text in the page font. An embedder who
set `calnode-booking { font-family: … }` got the brand font everywhere except on the
controls. Sizes, weights and control heights are unchanged.
- **The embed widget's `lang` attribute accepts hyphenated locales.** The widget trimmed
the attribute to its primary subtag before sending it, so `lang="fr-CA"` loaded France
French. The attribute is now sent whole and the server falls back to the primary
language when there is no exact match, so `lang="de-DE"` still selects German.

## [0.14.0] - 2026-11-08

### Added
Expand Down
7 changes: 5 additions & 2 deletions cmd/i18n-coverage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func report(root string, c catalogue) error {
sort.Slice(rows, func(i, j int) bool { return rows[i].code < rows[j].code })

fmt.Printf("%s\n %s (source %s.json, %d keys)\n\n", c.name, c.dir, sourceCode, len(source))
fmt.Printf(" %-7s %6s %8s %10s %8s\n", "code", "keys", "coverage", "status", "unknown")
fmt.Printf(" %-12s %6s %8s %10s %8s\n", "code", "keys", "coverage", "status", "unknown")
for _, r := range rows {
status := "source"
switch {
Expand All @@ -108,10 +108,13 @@ func report(root string, c catalogue) error {
status = "has unknown keys"
case c.floor > 0 && r.cover < c.floor:
status = "withheld"
case i18n.IsOptInVariant(r.code):
// Complete, but a wording variant: reachable by code only, never offered.
status = "opt-in"
default:
status = "offered"
}
fmt.Printf(" %-7s %6d %7.0f%% %10s %8d\n", r.code, r.keys, r.cover*100, status, r.unknown)
fmt.Printf(" %-12s %6d %7.0f%% %10s %8d\n", r.code, r.keys, r.cover*100, status, r.unknown)
}
if c.floor > 0 {
fmt.Printf("\n floor: %.0f%% (below it a language is not offered; ?lang=<code> still works)\n", c.floor*100)
Expand Down
6 changes: 6 additions & 0 deletions docs/i18n-glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ not have to invent terminology that is already decided.
The existing booker locales are deliberately split by market: `fr`/`de`/`it`/`pt` formal,
`es`/`nl`/`sv` informal. Match the language, not the English.

`de-x-neutral` is the one exception, and it is a third option rather than a change of side:
German with no address at all (infinitive and nominal style, "Tag auswählen"), for
operators whose own site does not say *Sie*. It is opt-in and never offered to visitors, so
`de` remains the formal default. When a string changes in `de.json`, change it in
`de-x-neutral.json` too, without the pronoun.

## Things that are not translated

Brand names, URLs, protocol tokens (`STARTTLS`, `RSVP`, `PII`), third-party console labels
Expand Down
7 changes: 5 additions & 2 deletions internal/handler/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@
// the /public call, matching the ?lang= override semantics on book.html/manage.html.
// /public returns the resolved {locale, i18n} once; cached on the instance and reused
// by every subsequent render, not refetched per-request.
// The attribute is sent whole: the server tries the exact code first and then the
// primary language (i18n.getOverride), so lang="de-DE" still selects de while
// lang="fr-CA" and lang="de-x-neutral" select their own catalogues. Trimming to the
// primary subtag here made those two unreachable from the widget.
function langOverride(el) {
var v = el.getAttribute('lang');
return v ? v.split('-')[0] : '';
return el.getAttribute('lang') || '';
}
// t: pure lookup, not a method — mirrors internal/i18n.Locale.T (falls back to the
// key itself if the string table hasn't loaded yet or the key is missing).
Expand Down
9 changes: 9 additions & 0 deletions internal/handler/embed_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@ func TestBookingCSS_cacheModes(t *testing.T) {
t.Errorf("versioned Cache-Control = %q, want immutable", cc)
}
}

// Form controls take their font family from the UA stylesheet unless told otherwise, so
// without this rule every button in the widget ignores the font the embedding page set
// on <calnode-booking>. Nothing else in the suite renders CSS, so pin the rule itself.
func TestBookingCSS_controlsInheritFontFamily(t *testing.T) {
if !strings.Contains(string(bookingCSS), "button, input, select, textarea { font-family: inherit; }") {
t.Error("booking.css no longer makes form controls inherit font-family; buttons fall back to the UA font inside the embed widget")
}
}
9 changes: 9 additions & 0 deletions internal/handler/templates/booking.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
* padding removes default <ul>/<h1>/<p> spacing (component rules below set their own). */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Form controls do not inherit the font family: the UA stylesheet gives <button>,
* <input>, <select> and <textarea> their own, so day cells, time slots and the
* confirm button rendered in the system UI font next to text in the page font. It
* shows most in the widget, where an embedder who sets `calnode-booking { font-family:
* … }` got the brand font on headings and labels but not on a single control. Only
* the family is inherited on purpose: every control below sets its own font-size and
* weight, and `font: inherit` would also pull in line-height and change their height. */
button, input, select, textarea { font-family: inherit; }

/* ── Brand banner ────────────────────────────────── */
/* Full-width operator banner, shown above .card (below the logo, if any). Not
* used by the embed widget — the widget carries no operator branding. */
Expand Down
43 changes: 39 additions & 4 deletions internal/i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"log"
"sort"
"strings"

"golang.org/x/text/language"
"golang.org/x/text/language/display"
Expand Down Expand Up @@ -99,6 +100,10 @@ func init() {
supportedCodes = append(supportedCodes, DefaultCode)
supported = append(supported, language.Make(DefaultCode))
for _, code := range otherCodes {
// An opt-in variant is complete but deliberately not offered; nothing to log.
if IsOptInVariant(code) {
continue
}
// A partial catalogue is allowed to exist and to be merged (see MinCoverage),
// but it is not offered to visitors until it is substantially translated.
if !offeredToVisitors(locales[code]) {
Expand All @@ -124,8 +129,23 @@ func Coverage(l *Locale) float64 {
}

// offeredToVisitors is the single place the floor is applied, so init and the tests
// cannot disagree about what "offered" means.
func offeredToVisitors(l *Locale) bool { return Coverage(l) >= MinCoverage }
// cannot disagree about what "offered" means. Opt-in variants are never offered,
// however complete (see IsOptInVariant).
func offeredToVisitors(l *Locale) bool {
return !IsOptInVariant(l.Code) && Coverage(l) >= MinCoverage
}

// IsOptInVariant reports whether code names a wording variant of a language rather than
// a language or a region: a BCP-47 private-use tag such as "de-x-neutral" (German with
// no du/Sie address).
//
// A variant is the operator's choice, not the visitor's. Listing it would put "Deutsch"
// in the switcher twice (display names ignore private-use subtags), and a browser never
// asks for one in Accept-Language. So it stays out of `supported` entirely and is
// reached only by an explicit code: ?lang=, the widget's lang attribute, or the
// fallback-language setting through the API. The base language is unaffected by its
// existence, which is the half that would otherwise break silently.
func IsOptInVariant(code string) bool { return strings.Contains(code, "-x-") }

// Default returns the fallback (English) locale.
func Default() *Locale { return locales[DefaultCode] }
Expand Down Expand Up @@ -157,7 +177,8 @@ func SupportedLocales() []LocaleOption {

// Resolve picks the best-supported locale for a request, given the raw Accept-Language
// header value and an optional override (from a manual language-switcher cookie/param —
// pass "" when there isn't one). An override wins outright if it's a supported code;
// pass "" when there isn't one). An override wins outright if it's a supported code,
// or a longer tag whose primary language is one ("de-DE" selects de);
// otherwise falls back to Accept-Language matching, then English. Equivalent to
// ResolveWithFallback with fallbackCode DefaultCode.
func Resolve(acceptLanguage, override string) *Locale {
Expand All @@ -175,7 +196,7 @@ func Resolve(acceptLanguage, override string) *Locale {
// fails outright, it just returns supported[0] (English, by construction — see the
// ordering note in init()) at low/no confidence when nothing lines up.
func ResolveWithFallback(acceptLanguage, override, fallbackCode string) *Locale {
if l := Get(override); l != nil {
if l := getOverride(override); l != nil {
return l
}
fallback := Get(fallbackCode)
Expand All @@ -196,6 +217,20 @@ func ResolveWithFallback(acceptLanguage, override, fallbackCode string) *Locale
return fallback // defensive: should be unreachable, but never return a nil Locale
}

// getOverride resolves an explicit language choice: the exact code first, so "fr-CA" and
// "de-x-neutral" select their own files, then the primary language subtag, so a host
// page's lang="de-DE" still selects de. The embed widget used to do that trimming
// itself before sending ?lang=, which made every hyphenated locale unselectable there.
func getOverride(code string) *Locale {
if l := Get(code); l != nil {
return l
}
if i := strings.IndexByte(code, '-'); i > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

getOverride widens what an explicit override accepts, but persistLangOverride (internal/handler/i18n.go:52) still requires an exact i18n.Get(code), so the new half of the contract is not sticky: ?lang=de-DE now renders German and then flips back on the next navigation, because no cookie was written. Either share this lookup with the persister, or say in the doc comment that regional overrides are deliberately not persisted.

Technical details
# Regional/private-use overrides do not persist

## Affected sites
- `internal/i18n/i18n.go:228` — the new primary-subtag fallback.
- `internal/handler/i18n.go:52` — `if code == "" || i18n.Get(code) == nil { return }` still gates persistence on an exact file.

## Required outcome
- A `?lang=` value that renders a language is the value persisted to `calnode_lang`, or the asymmetry is documented as intentional.

## Suggested approach (optional)
- Export the resolver (e.g. `i18n.LookupOverride`) and use it from both call sites; persist the resolved code (`Resolve("", code).Code`) so `de-DE` stores `de` rather than a tag with no file.

return Get(code[:i])
}
return nil
}

// T looks up key in this locale, falling back to English, then to the key itself so a
// missing translation degrades to something visible rather than an empty string.
func (l *Locale) T(key string) string {
Expand Down
69 changes: 69 additions & 0 deletions internal/i18n/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package i18n

import (
"fmt"
"regexp"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -48,6 +49,14 @@ func TestResolve(t *testing.T) {
{"empty header falls back to English", "", "", "en"},
{"garbage header falls back to English", "not a real header ;;;", "", "en"},
{"override wins over Accept-Language", "en", "es", "es"},
// The embed widget forwards a host page's lang attribute verbatim, and that is
// usually a regional tag Calnode has no file for.
{"regional override falls back to its primary language", "en", "de-DE", "de"},
{"regional override of an unsupported language is ignored", "es", "ja-JP", "es"},
// de-x-neutral is opt-in: selectable by code, never picked for a German browser.
{"neutral German can be selected by the ?lang override", "en", "de-x-neutral", "de-x-neutral"},
{"plain de is unaffected by de-x-neutral", "de", "", "de"},
{"de-DE is unaffected by de-x-neutral", "de-DE,de;q=0.9", "", "de"},
{"unsupported override is ignored", "es", "ja", "es"},
// ja isn't supported, but es (an acceptable lower-preference language) is — falling
// through to it beats giving up to the site default, per Accept-Language semantics.
Expand Down Expand Up @@ -467,3 +476,63 @@ func TestAllLocalesHaveMatchingFormatVerbs_allowsLegitimateReordering(t *testing
})
}
}

// TestOptInVariantIsNotOffered pins what "opt-in" means for a wording variant: it loads
// and resolves by code, and it is absent from everything a visitor is offered. If it
// leaked into `supported`, the switcher would list "Deutsch" twice.
func TestOptInVariantIsNotOffered(t *testing.T) {
const code = "de-x-neutral"
if Get(code) == nil {
t.Fatalf("%s.json is not loaded", code)
}
for _, o := range SupportedLocales() {
if o.Code == code {
t.Errorf("%s must not be offered in the language switcher", code)
}
}
seen := map[string]string{}
for _, o := range SupportedLocales() {
if prev, dup := seen[o.Name]; dup {
t.Errorf("locales %q and %q share the switcher name %q", prev, o.Code, o.Name)
}
seen[o.Name] = o.Code
}
}

// germanAddress matches a German pronoun of address in either register: formal
// Sie/Ihnen/Ihr-, informal du/dir/dich/dein-. Case matters for the formal set, which is
// what tells "Sie" (you) from "sie" (they, the cookies). \b is ASCII-only in RE2, which is
// enough here: none of these words starts or ends with an umlaut.
var germanAddress = regexp.MustCompile(`\b(Sie|Ihnen|Ihr[a-z]*|[Dd]u|[Dd]ir|[Dd]ich|[Dd]ein[a-z]*)\b`)

// TestGermanNeutralVariant guards the one property de-x-neutral exists for: no string
// addresses the booker as du or Sie. It also has to stay complete, because a key it
// lacks falls back to English rather than to de.
func TestGermanNeutralVariant(t *testing.T) {
de, neutral := Get("de"), Get("de-x-neutral")
if de == nil || neutral == nil {
t.Fatal("de and de-x-neutral must both ship")
}
for k := range de.strings {
if _, ok := neutral.strings[k]; !ok {
t.Errorf("de-x-neutral.json is missing %q, which de.json has; it would render in English", k)
}
}
for k, v := range neutral.strings {
if m := germanAddress.FindString(v); m != "" {
t.Errorf("de-x-neutral.json: %s addresses the booker (%q): %q", k, m, v)
}
}
// The guard has teeth: the formal catalogue it was derived from must trip it.
if !germanAddress.MatchString(de.strings["select_day_hint"]) {
t.Errorf("germanAddress no longer matches the formal de.json wording %q", de.strings["select_day_hint"])
}
// Dates are data, not register: the variant must format exactly as de does.
for k, v := range de.strings {
if strings.HasPrefix(k, "dow_short_") || strings.HasPrefix(k, "month_short_") || k == "date_format" || k == "clock_format" {
if neutral.strings[k] != v {
t.Errorf("de-x-neutral.json: %s = %q, de.json has %q", k, neutral.strings[k], v)
}
}
}
}
Loading
Loading