Skip to content

Commit 0c181ff

Browse files
authored
Merge pull request #258 from portfoliomanufaktur/de-neutral-and-button-font
German without du/Sie as an opt-in variant, and inherited fonts on booking controls
2 parents f7c3695 + 3af5aa0 commit 0c181ff

9 files changed

Lines changed: 335 additions & 8 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad
1111

1212
## [Unreleased]
1313

14+
### Added
15+
16+
- **German without du or Sie (`de-x-neutral`).** An opt-in wording variant of the German
17+
booker catalogue that addresses nobody: "Tag auswählen" rather than "Wählen Sie einen
18+
Tag". It is for operators whose own site is informal, where the formal widget stands out
19+
and an informal one would be wrong for everyone else. `de` is unchanged and stays formal.
20+
The variant is never offered in the language switcher or matched from `Accept-Language`;
21+
select it with `?lang=de-x-neutral` or `<calnode-booking lang="de-x-neutral">`.
22+
23+
### Fixed
24+
25+
- **Buttons and inputs in the booking UI now use the surrounding font.** Form controls
26+
take their font family from the browser stylesheet, so day cells, time slots and the
27+
confirm button rendered in the system font beside text in the page font. An embedder who
28+
set `calnode-booking { font-family: … }` got the brand font everywhere except on the
29+
controls. Sizes, weights and control heights are unchanged.
30+
- **The embed widget's `lang` attribute accepts hyphenated locales.** The widget trimmed
31+
the attribute to its primary subtag before sending it, so `lang="fr-CA"` loaded France
32+
French. The attribute is now sent whole and the server falls back to the primary
33+
language when there is no exact match, so `lang="de-DE"` still selects German.
34+
1435
## [0.14.0] - 2026-11-08
1536

1637
### Added

‎cmd/i18n-coverage/main.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func report(root string, c catalogue) error {
9999
sort.Slice(rows, func(i, j int) bool { return rows[i].code < rows[j].code })
100100

101101
fmt.Printf("%s\n %s (source %s.json, %d keys)\n\n", c.name, c.dir, sourceCode, len(source))
102-
fmt.Printf(" %-7s %6s %8s %10s %8s\n", "code", "keys", "coverage", "status", "unknown")
102+
fmt.Printf(" %-12s %6s %8s %10s %8s\n", "code", "keys", "coverage", "status", "unknown")
103103
for _, r := range rows {
104104
status := "source"
105105
switch {
@@ -108,10 +108,13 @@ func report(root string, c catalogue) error {
108108
status = "has unknown keys"
109109
case c.floor > 0 && r.cover < c.floor:
110110
status = "withheld"
111+
case i18n.IsOptInVariant(r.code):
112+
// Complete, but a wording variant: reachable by code only, never offered.
113+
status = "opt-in"
111114
default:
112115
status = "offered"
113116
}
114-
fmt.Printf(" %-7s %6d %7.0f%% %10s %8d\n", r.code, r.keys, r.cover*100, status, r.unknown)
117+
fmt.Printf(" %-12s %6d %7.0f%% %10s %8d\n", r.code, r.keys, r.cover*100, status, r.unknown)
115118
}
116119
if c.floor > 0 {
117120
fmt.Printf("\n floor: %.0f%% (below it a language is not offered; ?lang=<code> still works)\n", c.floor*100)

‎docs/i18n-glossary.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ not have to invent terminology that is already decided.
4646
The existing booker locales are deliberately split by market: `fr`/`de`/`it`/`pt` formal,
4747
`es`/`nl`/`sv` informal. Match the language, not the English.
4848

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

5157
Brand names, URLs, protocol tokens (`STARTTLS`, `RSVP`, `PII`), third-party console labels

‎internal/handler/embed.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333
// the /public call, matching the ?lang= override semantics on book.html/manage.html.
3434
// /public returns the resolved {locale, i18n} once; cached on the instance and reused
3535
// by every subsequent render, not refetched per-request.
36+
// The attribute is sent whole: the server tries the exact code first and then the
37+
// primary language (i18n.getOverride), so lang="de-DE" still selects de while
38+
// lang="fr-CA" and lang="de-x-neutral" select their own catalogues. Trimming to the
39+
// primary subtag here made those two unreachable from the widget.
3640
function langOverride(el) {
37-
var v = el.getAttribute('lang');
38-
return v ? v.split('-')[0] : '';
41+
return el.getAttribute('lang') || '';
3942
}
4043
// t: pure lookup, not a method — mirrors internal/i18n.Locale.T (falls back to the
4144
// key itself if the string table hasn't loaded yet or the key is missing).

‎internal/handler/embed_handler_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ func TestBookingCSS_cacheModes(t *testing.T) {
8787
t.Errorf("versioned Cache-Control = %q, want immutable", cc)
8888
}
8989
}
90+
91+
// Form controls take their font family from the UA stylesheet unless told otherwise, so
92+
// without this rule every button in the widget ignores the font the embedding page set
93+
// on <calnode-booking>. Nothing else in the suite renders CSS, so pin the rule itself.
94+
func TestBookingCSS_controlsInheritFontFamily(t *testing.T) {
95+
if !strings.Contains(string(bookingCSS), "button, input, select, textarea { font-family: inherit; }") {
96+
t.Error("booking.css no longer makes form controls inherit font-family; buttons fall back to the UA font inside the embed widget")
97+
}
98+
}

‎internal/handler/templates/booking.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
* padding removes default <ul>/<h1>/<p> spacing (component rules below set their own). */
1111
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
1212

13+
/* Form controls do not inherit the font family: the UA stylesheet gives <button>,
14+
* <input>, <select> and <textarea> their own, so day cells, time slots and the
15+
* confirm button rendered in the system UI font next to text in the page font. It
16+
* shows most in the widget, where an embedder who sets `calnode-booking { font-family:
17+
* … }` got the brand font on headings and labels but not on a single control. Only
18+
* the family is inherited on purpose: every control below sets its own font-size and
19+
* weight, and `font: inherit` would also pull in line-height and change their height. */
20+
button, input, select, textarea { font-family: inherit; }
21+
1322
/* ── Brand banner ────────────────────────────────── */
1423
/* Full-width operator banner, shown above .card (below the logo, if any). Not
1524
* used by the embed widget — the widget carries no operator branding. */

‎internal/i18n/i18n.go‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"fmt"
1414
"log"
1515
"sort"
16+
"strings"
1617

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

126131
// offeredToVisitors is the single place the floor is applied, so init and the tests
127-
// cannot disagree about what "offered" means.
128-
func offeredToVisitors(l *Locale) bool { return Coverage(l) >= MinCoverage }
132+
// cannot disagree about what "offered" means. Opt-in variants are never offered,
133+
// however complete (see IsOptInVariant).
134+
func offeredToVisitors(l *Locale) bool {
135+
return !IsOptInVariant(l.Code) && Coverage(l) >= MinCoverage
136+
}
137+
138+
// IsOptInVariant reports whether code names a wording variant of a language rather than
139+
// a language or a region: a BCP-47 private-use tag such as "de-x-neutral" (German with
140+
// no du/Sie address).
141+
//
142+
// A variant is the operator's choice, not the visitor's. Listing it would put "Deutsch"
143+
// in the switcher twice (display names ignore private-use subtags), and a browser never
144+
// asks for one in Accept-Language. So it stays out of `supported` entirely and is
145+
// reached only by an explicit code: ?lang=, the widget's lang attribute, or the
146+
// fallback-language setting through the API. The base language is unaffected by its
147+
// existence, which is the half that would otherwise break silently.
148+
func IsOptInVariant(code string) bool { return strings.Contains(code, "-x-") }
129149

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

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

220+
// getOverride resolves an explicit language choice: the exact code first, so "fr-CA" and
221+
// "de-x-neutral" select their own files, then the primary language subtag, so a host
222+
// page's lang="de-DE" still selects de. The embed widget used to do that trimming
223+
// itself before sending ?lang=, which made every hyphenated locale unselectable there.
224+
func getOverride(code string) *Locale {
225+
if l := Get(code); l != nil {
226+
return l
227+
}
228+
if i := strings.IndexByte(code, '-'); i > 0 {
229+
return Get(code[:i])
230+
}
231+
return nil
232+
}
233+
199234
// T looks up key in this locale, falling back to English, then to the key itself so a
200235
// missing translation degrades to something visible rather than an empty string.
201236
func (l *Locale) T(key string) string {

‎internal/i18n/i18n_test.go‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package i18n
22

33
import (
44
"fmt"
5+
"regexp"
56
"strings"
67
"testing"
78
"time"
@@ -48,6 +49,14 @@ func TestResolve(t *testing.T) {
4849
{"empty header falls back to English", "", "", "en"},
4950
{"garbage header falls back to English", "not a real header ;;;", "", "en"},
5051
{"override wins over Accept-Language", "en", "es", "es"},
52+
// The embed widget forwards a host page's lang attribute verbatim, and that is
53+
// usually a regional tag Calnode has no file for.
54+
{"regional override falls back to its primary language", "en", "de-DE", "de"},
55+
{"regional override of an unsupported language is ignored", "es", "ja-JP", "es"},
56+
// de-x-neutral is opt-in: selectable by code, never picked for a German browser.
57+
{"neutral German can be selected by the ?lang override", "en", "de-x-neutral", "de-x-neutral"},
58+
{"plain de is unaffected by de-x-neutral", "de", "", "de"},
59+
{"de-DE is unaffected by de-x-neutral", "de-DE,de;q=0.9", "", "de"},
5160
{"unsupported override is ignored", "es", "ja", "es"},
5261
// ja isn't supported, but es (an acceptable lower-preference language) is — falling
5362
// through to it beats giving up to the site default, per Accept-Language semantics.
@@ -467,3 +476,63 @@ func TestAllLocalesHaveMatchingFormatVerbs_allowsLegitimateReordering(t *testing
467476
})
468477
}
469478
}
479+
480+
// TestOptInVariantIsNotOffered pins what "opt-in" means for a wording variant: it loads
481+
// and resolves by code, and it is absent from everything a visitor is offered. If it
482+
// leaked into `supported`, the switcher would list "Deutsch" twice.
483+
func TestOptInVariantIsNotOffered(t *testing.T) {
484+
const code = "de-x-neutral"
485+
if Get(code) == nil {
486+
t.Fatalf("%s.json is not loaded", code)
487+
}
488+
for _, o := range SupportedLocales() {
489+
if o.Code == code {
490+
t.Errorf("%s must not be offered in the language switcher", code)
491+
}
492+
}
493+
seen := map[string]string{}
494+
for _, o := range SupportedLocales() {
495+
if prev, dup := seen[o.Name]; dup {
496+
t.Errorf("locales %q and %q share the switcher name %q", prev, o.Code, o.Name)
497+
}
498+
seen[o.Name] = o.Code
499+
}
500+
}
501+
502+
// germanAddress matches a German pronoun of address in either register: formal
503+
// Sie/Ihnen/Ihr-, informal du/dir/dich/dein-. Case matters for the formal set, which is
504+
// what tells "Sie" (you) from "sie" (they, the cookies). \b is ASCII-only in RE2, which is
505+
// enough here: none of these words starts or ends with an umlaut.
506+
var germanAddress = regexp.MustCompile(`\b(Sie|Ihnen|Ihr[a-z]*|[Dd]u|[Dd]ir|[Dd]ich|[Dd]ein[a-z]*)\b`)
507+
508+
// TestGermanNeutralVariant guards the one property de-x-neutral exists for: no string
509+
// addresses the booker as du or Sie. It also has to stay complete, because a key it
510+
// lacks falls back to English rather than to de.
511+
func TestGermanNeutralVariant(t *testing.T) {
512+
de, neutral := Get("de"), Get("de-x-neutral")
513+
if de == nil || neutral == nil {
514+
t.Fatal("de and de-x-neutral must both ship")
515+
}
516+
for k := range de.strings {
517+
if _, ok := neutral.strings[k]; !ok {
518+
t.Errorf("de-x-neutral.json is missing %q, which de.json has; it would render in English", k)
519+
}
520+
}
521+
for k, v := range neutral.strings {
522+
if m := germanAddress.FindString(v); m != "" {
523+
t.Errorf("de-x-neutral.json: %s addresses the booker (%q): %q", k, m, v)
524+
}
525+
}
526+
// The guard has teeth: the formal catalogue it was derived from must trip it.
527+
if !germanAddress.MatchString(de.strings["select_day_hint"]) {
528+
t.Errorf("germanAddress no longer matches the formal de.json wording %q", de.strings["select_day_hint"])
529+
}
530+
// Dates are data, not register: the variant must format exactly as de does.
531+
for k, v := range de.strings {
532+
if strings.HasPrefix(k, "dow_short_") || strings.HasPrefix(k, "month_short_") || k == "date_format" || k == "clock_format" {
533+
if neutral.strings[k] != v {
534+
t.Errorf("de-x-neutral.json: %s = %q, de.json has %q", k, neutral.strings[k], v)
535+
}
536+
}
537+
}
538+
}

0 commit comments

Comments
 (0)