@kiosko/sdk 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/context.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * const ctx = { ...createBaseContext({ now, locale: 'es' }), options, signal, intervalMs: 60_000, timeoutMs: 20_000 };
7
7
  */
8
8
  import { createFormatters } from "./format.js";
9
- import { localize } from "./i18n.js";
9
+ import { localize, pickLocale, plural } from "./i18n.js";
10
10
  import { DEFAULT_WORKDAY } from "./workday.js";
11
11
  export function createBaseContext(o) {
12
12
  const locale = o.locale ?? 'en';
@@ -14,6 +14,8 @@ export function createBaseContext(o) {
14
14
  now: o.now,
15
15
  locale,
16
16
  t: (text) => localize(text, locale),
17
+ plural: (n, forms) => plural(n, forms, locale),
18
+ pickLanguage: (available) => pickLocale(available, locale) ?? (available.includes('en') ? 'en' : available[0] ?? 'en'),
17
19
  fmt: createFormatters({ locale, timeFormat: o.timeFormat ?? 'auto', now: o.now }),
18
20
  log: o.log ?? (() => undefined),
19
21
  dataDir: o.dataDir ?? '',
package/dist/format.d.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  * Times and lengths of time, written the same way by every widget:
3
3
  * `ctx.fmt.time(at)`, `ctx.fmt.ago(at)` and `ctx.fmt.duration(ms)`.
4
4
  *
5
- * They follow the panel's language (English and Spanish words; any other
6
- * language gets the English ones) and the config's `timeFormat`. Hand-written
5
+ * They follow the panel's language (English, Spanish, German, Traditional and
6
+ * Simplified Chinese words; any other language gets the English ones) and the config's `timeFormat`. Hand-written
7
7
  * rather than `Intl.RelativeTimeFormat`: its short forms differ between ICU
8
8
  * versions (Node, Chromium, WebKit), and a panel must paint the same thing in
9
9
  * the editor, the browser demo and on the glass.
@@ -16,13 +16,20 @@ export interface Formatters {
16
16
  readonly hour12: boolean;
17
17
  /**
18
18
  * A clock time: `"09:05"` on a 24-hour clock, `"9:05 AM"` (`"9:05 a. m."`)
19
- * on a 12-hour one. `seconds` adds `":07"`; `ampm: false` leaves out
19
+ * on a 12-hour one (`"上午 9:05"` in Chinese). `seconds` adds `":07"`; `ampm: false` leaves out
20
20
  * AM/PM (a big clock that paints it apart).
21
21
  */
22
22
  time(at: number | Date, o?: {
23
23
  seconds?: boolean;
24
24
  ampm?: boolean;
25
25
  }): string;
26
+ /**
27
+ * From one clock time to another: `"14:00–15:30"`, `"3:30–4:00 PM"`,
28
+ * `"下午 3:30–4:00"` (AM/PM once when both are in the same half of the day).
29
+ */
30
+ range(from: number | Date, to: number | Date, o?: {
31
+ seconds?: boolean;
32
+ }): string;
26
33
  /**
27
34
  * How long ago `at` (epoch ms, a Date or an ISO string) was, from `ctx.now`:
28
35
  * `"just now"`, `"5 min ago"`, `"3 h ago"`, `"4 d ago"`, `"2 wk ago"`,
@@ -46,6 +53,8 @@ export interface Formatters {
46
53
  compact?: boolean;
47
54
  }): string;
48
55
  }
56
+ /** The languages ctx.fmt has words for (a test checks every language Kiosko speaks is here). */
57
+ export declare const FORMAT_LANGUAGES: string[];
49
58
  /** Whether `locale` writes times on a 12-hour clock, per `timeFormat`. */
50
59
  export declare function usesHour12(locale: string, timeFormat?: TimeFormat): boolean;
51
60
  /**
package/dist/format.js CHANGED
@@ -2,19 +2,57 @@
2
2
  * Times and lengths of time, written the same way by every widget:
3
3
  * `ctx.fmt.time(at)`, `ctx.fmt.ago(at)` and `ctx.fmt.duration(ms)`.
4
4
  *
5
- * They follow the panel's language (English and Spanish words; any other
6
- * language gets the English ones) and the config's `timeFormat`. Hand-written
5
+ * They follow the panel's language (English, Spanish, German, Traditional and
6
+ * Simplified Chinese words; any other language gets the English ones) and the config's `timeFormat`. Hand-written
7
7
  * rather than `Intl.RelativeTimeFormat`: its short forms differ between ICU
8
8
  * versions (Node, Chromium, WebKit), and a panel must paint the same thing in
9
9
  * the editor, the browser demo and on the glass.
10
10
  */
11
+ import { pickLocale } from "./i18n.js";
11
12
  export const TIME_FORMATS = ['auto', '24h', '12h'];
13
+ const latin = (wk, yr) => ({
14
+ s: (n) => `${n} s`,
15
+ min: (n) => `${n} min`,
16
+ h: (n) => `${n} h`,
17
+ d: (n) => `${n} d`,
18
+ wk: (n) => `${n} ${wk}`,
19
+ yr: (n) => `${n} ${yr(n)}`,
20
+ hm: (h, m) => `${h} h ${pad2(m)}`,
21
+ dh: (d, h) => `${d} d ${h} h`,
22
+ });
23
+ // German: abbreviations with a full stop (5 Min., 3 Std.), which also spare the dative after "vor" (vor 2 Tagen); a running length as 1:05 h.
24
+ const german = {
25
+ s: (n) => `${n} s`,
26
+ min: (n) => `${n} Min.`,
27
+ h: (n) => `${n} Std.`,
28
+ d: (n) => `${n} T.`,
29
+ wk: (n) => `${n} Wo.`,
30
+ yr: (n) => `${n} J.`,
31
+ hm: (h, m) => `${h}:${pad2(m)} h`,
32
+ dh: (d, h) => `${d} T. ${h} Std.`,
33
+ };
34
+ const chinese = (u) => ({
35
+ s: (n) => `${n} 秒`,
36
+ min: (n) => `${n} ${u.min}`,
37
+ h: (n) => `${n} ${u.h}`,
38
+ d: (n) => `${n} 天`,
39
+ wk: (n) => `${n} ${u.wk}`,
40
+ yr: (n) => `${n} 年`,
41
+ // No leading zero in Chinese: 1 小時 5 分.
42
+ hm: (h, m) => `${h} ${u.h} ${m} 分`,
43
+ dh: (d, h) => `${d} 天 ${h} ${u.h}`,
44
+ });
12
45
  const WORDS = {
13
- en: { now: 'now', justNow: 'just now', ago: (v) => `${v} ago`, wk: 'wk', yr: () => 'yr', am: 'AM', pm: 'PM' },
14
- es: { now: 'ahora', justNow: 'ahora mismo', ago: (v) => `hace ${v}`, wk: 'sem', yr: (n) => (n === 1 ? 'año' : 'años'), am: 'a. m.', pm: 'p. m.' },
46
+ en: { now: 'now', justNow: 'just now', ago: (v) => `${v} ago`, am: 'AM', pm: 'PM', ...latin('wk', () => 'yr') },
47
+ es: { now: 'ahora', justNow: 'ahora mismo', ago: (v) => `hace ${v}`, am: 'a. m.', pm: 'p. m.', ...latin('sem', (n) => (n === 1 ? 'año' : 'años')) },
48
+ de: { now: 'jetzt', justNow: 'gerade eben', ago: (v) => `vor ${v}`, am: 'AM', pm: 'PM', ...german },
49
+ 'zh-Hant': { now: '現在', justNow: '剛剛', ago: (v) => `${v}前`, am: '上午', pm: '下午', ampmFirst: true, ...chinese({ min: '分鐘', h: '小時', wk: '週' }) },
50
+ 'zh-Hans': { now: '现在', justNow: '刚刚', ago: (v) => `${v}前`, am: '上午', pm: '下午', ampmFirst: true, ...chinese({ min: '分钟', h: '小时', wk: '周' }) },
15
51
  };
16
- const langOf = (locale) => locale.toLowerCase().split(/[-_]/)[0] ?? 'en';
17
- const wordsFor = (locale) => WORDS[langOf(locale)] ?? WORDS.en;
52
+ /** The languages ctx.fmt has words for (a test checks every language Kiosko speaks is here). */
53
+ export const FORMAT_LANGUAGES = Object.keys(WORDS);
54
+ const LANGS = Object.keys(WORDS);
55
+ const wordsFor = (locale) => WORDS[pickLocale(LANGS, locale) ?? 'en'] ?? WORDS.en;
18
56
  const pad2 = (n) => String(n).padStart(2, '0');
19
57
  const cycles = new Map();
20
58
  /** Whether `locale` writes times on a 12-hour clock, per `timeFormat`. */
@@ -48,7 +86,7 @@ function toMs(at) {
48
86
  export function createFormatters(o) {
49
87
  const w = wordsFor(o.locale);
50
88
  const hour12 = usesHour12(o.locale, o.timeFormat);
51
- return {
89
+ const fmt = {
52
90
  hour12,
53
91
  time(at, opts = {}) {
54
92
  const d = new Date(toMs(at));
@@ -57,7 +95,18 @@ export function createFormatters(o) {
57
95
  if (!hour12)
58
96
  return `${pad2(h)}${rest}`;
59
97
  const base = `${h % 12 || 12}${rest}`;
60
- return opts.ampm === false ? base : `${base} ${h < 12 ? w.am : w.pm}`;
98
+ if (opts.ampm === false)
99
+ return base;
100
+ const mark = h < 12 ? w.am : w.pm;
101
+ return w.ampmFirst ? `${mark} ${base}` : `${base} ${mark}`;
102
+ },
103
+ range(from, to, opts = {}) {
104
+ const a = new Date(toMs(from));
105
+ const b = new Date(toMs(to));
106
+ if (!hour12 || (a.getHours() < 12) !== (b.getHours() < 12))
107
+ return `${fmt.time(a, opts)}–${fmt.time(b, opts)}`;
108
+ // The same half of the day: AM/PM once, where the language puts it.
109
+ return w.ampmFirst ? `${fmt.time(a, opts)}–${fmt.time(b, { ...opts, ampm: false })}` : `${fmt.time(a, { ...opts, ampm: false })}–${fmt.time(b, opts)}`;
61
110
  },
62
111
  ago(at, opts = {}) {
63
112
  const suffix = opts.suffix !== false;
@@ -67,21 +116,22 @@ export function createFormatters(o) {
67
116
  return suffix ? w.justNow : w.now;
68
117
  const h = Math.floor(min / 60);
69
118
  const d = Math.floor(h / 24);
70
- const v = min < 60 ? `${min} min` : h < 24 ? `${h} h` : d < 14 ? `${d} d` : d < 365 ? `${Math.floor(d / 7)} ${w.wk}` : `${Math.floor(d / 365)} ${w.yr(Math.floor(d / 365))}`;
71
- return suffix ? w.ago(v) : v;
119
+ const [v, n] = min < 60 ? [w.min(min), min] : h < 24 ? [w.h(h), h] : d < 14 ? [w.d(d), d] : d < 365 ? [w.wk(Math.floor(d / 7)), Math.floor(d / 7)] : [w.yr(Math.floor(d / 365)), Math.floor(d / 365)];
120
+ return suffix ? w.ago(v, n) : v;
72
121
  },
73
122
  duration(ms, opts = {}) {
74
123
  const round = opts.round === 'up' ? Math.ceil : opts.round === 'nearest' ? Math.round : Math.floor;
75
124
  const safe = Number.isFinite(ms) ? Math.max(0, ms) : 0;
76
125
  if (opts.seconds && safe < 60_000)
77
- return `${round(safe / 1000)} s`;
126
+ return w.s(round(safe / 1000));
78
127
  const min = round(safe / 60_000);
79
128
  if (min < 60)
80
- return `${min} min`;
129
+ return w.min(min);
81
130
  const h = Math.floor(min / 60);
82
131
  if (h < 24)
83
- return opts.compact && min % 60 === 0 ? `${h} h` : `${h} h ${pad2(min % 60)}`;
84
- return opts.compact && h % 24 === 0 ? `${h / 24} d` : `${Math.floor(h / 24)} d ${h % 24} h`;
132
+ return opts.compact && min % 60 === 0 ? w.h(h) : w.hm(h, min % 60);
133
+ return opts.compact && h % 24 === 0 ? w.d(h / 24) : w.dh(Math.floor(h / 24), h % 24);
85
134
  },
86
135
  };
136
+ return fmt;
87
137
  }
package/dist/i18n.d.ts CHANGED
@@ -1,9 +1,67 @@
1
1
  /**
2
2
  * Plugin texts can be a plain string (shown as is) or a map by language.
3
- * The editor and the panel pick the user's locale, then English, then the
4
- * first one available.
3
+ * The editor and the panel pick the user's locale (see `pickLocale`), then
4
+ * English, then the first one available.
5
+ *
6
+ * Chinese goes by script: write `zh-Hant` (Taiwan, Hong Kong) and `zh-Hans`
7
+ * (mainland China). `zh-TW` and `zh-CN` work too; a bare `zh` is read as
8
+ * Simplified and never shown to someone who reads Traditional. The same
9
+ * holds for any language written in two scripts (`sr-Latn`, `sr-Cyrl`).
5
10
  */
6
11
  export type Localized = string | ({
7
12
  en: string;
8
13
  } & Partial<Record<string, string>>);
14
+ /**
15
+ * A language tag as Intl understands it, or null: POSIX forms cleaned
16
+ * (`zh_TW.UTF-8` → `zh-TW`, `sr_RS@latin` → `sr-Latn-RS`), old codes mapped
17
+ * (`iw` → `he`), case fixed.
18
+ */
19
+ export declare function parseLocale(tag: string | undefined): Intl.Locale | null;
20
+ /**
21
+ * The best of `available` (language tags, any case) for someone reading in
22
+ * `locale`, or undefined if none fits (the caller falls back to English).
23
+ *
24
+ * The same language and the same script, never another script: a reader
25
+ * of Traditional Chinese never gets Simplified (a bare `zh` is
26
+ * Simplified), nor a reader of Serbian in Latin letters Cyrillic. Among
27
+ * those: the exact tag, then the same region, then the region's usual
28
+ * variant (`es-419`/`es-MX` for Latin America, `pt-PT` outside Brazil),
29
+ * then the least specific one (`es` for `es-CL`), then any.
30
+ */
31
+ export declare function pickLocale(available: readonly string[], locale: string | undefined): string | undefined;
32
+ /** Plural forms of a text, as Intl.PluralRules names them; `other` is required. */
33
+ export type PluralForms = Partial<Record<Intl.LDMLPluralRule, string>> & {
34
+ other: string;
35
+ };
36
+ /**
37
+ * `{n} files` in the user's language, with the plural form its rules ask
38
+ * for (Polish has four, Chinese one): `forms` by language, `{n}` filled in
39
+ * with the number written the language's way.
40
+ */
41
+ export declare function plural(n: number, forms: Record<string, PluralForms>, locale?: string): string;
9
42
  export declare function localize(text: Localized | undefined, locale?: string): string;
43
+ /**
44
+ * The Han writing a locale reads in, for picking glyphs: the same character
45
+ * is drawn differently in Taiwan (`Hant`), Hong Kong (`Hant-HK`), mainland
46
+ * China (`Hans`), Japan (`Jpan`) and Korea (`Kore`). `null` for locales
47
+ * that do not write with Han characters.
48
+ *
49
+ * Goes by script, not by region code: `zh-TW`, `zh-Hant` and `zh-MO` are
50
+ * Traditional, `zh`, `zh-CN` and `zh-SG` Simplified.
51
+ */
52
+ export type HanScript = 'Hant' | 'Hant-HK' | 'Hans' | 'Jpan' | 'Kore';
53
+ export declare function hanScript(locale: string | undefined): HanScript | null;
54
+ /**
55
+ * An error to show the user, in their language: `throw new PluginError({
56
+ * en: 'Set your place in Settings', 'zh-Hant': '請在設定中設定位置', … })`.
57
+ * Its `message` is the English one (logs); Kiosko shows `text` in the
58
+ * user's language in the editor and on the tile.
59
+ */
60
+ export declare class PluginError extends Error {
61
+ readonly text: Localized;
62
+ constructor(text: Localized, options?: {
63
+ cause?: unknown;
64
+ });
65
+ }
66
+ /** What to show for an error: a PluginError's text in `locale`, else the message. */
67
+ export declare function errorMessage(err: unknown, locale?: string): string;
package/dist/i18n.js CHANGED
@@ -1,8 +1,151 @@
1
+ /** Old or other codes for the same language, as Intl leaves them. */
2
+ const ALIASES = { iw: 'he', in: 'id', ji: 'yi', tl: 'fil', no: 'nb', cmn: 'zh' };
3
+ /** Languages that read texts written for another one: Cantonese reads Chinese. */
4
+ const READS = { yue: 'zh', nn: 'nb' };
5
+ /**
6
+ * A language tag as Intl understands it, or null: POSIX forms cleaned
7
+ * (`zh_TW.UTF-8` → `zh-TW`, `sr_RS@latin` → `sr-Latn-RS`), old codes mapped
8
+ * (`iw` → `he`), case fixed.
9
+ */
10
+ export function parseLocale(tag) {
11
+ if (!tag)
12
+ return null;
13
+ let t = tag.trim();
14
+ const latin = /@latin\b/i.test(t);
15
+ t = t.replace(/[.@].*$/, '').replace(/_/g, '-');
16
+ if (!t || t === 'C' || t === 'POSIX')
17
+ return null;
18
+ try {
19
+ let l = new Intl.Locale(Intl.getCanonicalLocales(t)[0]);
20
+ const alias = ALIASES[l.language];
21
+ if (alias)
22
+ l = new Intl.Locale(alias, { ...(l.script ? { script: l.script } : {}), ...(l.region ? { region: l.region } : {}) });
23
+ if (latin && !l.script)
24
+ l = new Intl.Locale(l.language, { script: 'Latn', ...(l.region ? { region: l.region } : {}) });
25
+ return l;
26
+ }
27
+ catch {
28
+ return null;
29
+ }
30
+ }
31
+ /** Latin American regions: they read `es-419` (or the Mexican variant) before Spain's. */
32
+ const LATAM = new Set(['419', 'AR', 'BO', 'CL', 'CO', 'CR', 'CU', 'DO', 'EC', 'GT', 'HN', 'MX', 'NI', 'PA', 'PE', 'PR', 'PY', 'SV', 'US', 'UY', 'VE']);
33
+ /** Portuguese outside Brazil reads Portugal's before Brazil's. */
34
+ const PT_PT = new Set(['PT', 'AO', 'MZ', 'CV', 'GW', 'ST', 'TL', 'MO', 'GQ', 'LU', 'CH']);
35
+ /**
36
+ * The best of `available` (language tags, any case) for someone reading in
37
+ * `locale`, or undefined if none fits (the caller falls back to English).
38
+ *
39
+ * The same language and the same script, never another script: a reader
40
+ * of Traditional Chinese never gets Simplified (a bare `zh` is
41
+ * Simplified), nor a reader of Serbian in Latin letters Cyrillic. Among
42
+ * those: the exact tag, then the same region, then the region's usual
43
+ * variant (`es-419`/`es-MX` for Latin America, `pt-PT` outside Brazil),
44
+ * then the least specific one (`es` for `es-CL`), then any.
45
+ */
46
+ export function pickLocale(available, locale) {
47
+ if (!locale || !available.length)
48
+ return undefined;
49
+ const exact = available.find((k) => k.toLowerCase() === locale.replace(/_/g, '-').toLowerCase());
50
+ if (exact)
51
+ return exact;
52
+ const want = parseLocale(locale);
53
+ if (!want)
54
+ return undefined;
55
+ const w = want.maximize();
56
+ const lang = READS[w.language] ?? w.language;
57
+ const fits = available
58
+ .map((k) => ({ k, l: parseLocale(k) }))
59
+ .filter((c) => !!c.l)
60
+ .map((c) => ({ ...c, m: c.l.maximize() }))
61
+ .filter((c) => (READS[c.m.language] ?? c.m.language) === lang && c.m.script === w.script);
62
+ if (!fits.length)
63
+ return undefined;
64
+ const same = (a, b) => a.baseName === b.baseName;
65
+ const byTag = fits.find((c) => same(c.l, want));
66
+ if (byTag)
67
+ return byTag.k;
68
+ if (w.region) {
69
+ const byRegion = fits.find((c) => c.m.region === w.region && c.l.region);
70
+ if (byRegion)
71
+ return byRegion.k;
72
+ const usual = (r) => (lang === 'es' && LATAM.has(w.region) ? ['419', 'MX'].includes(r) : lang === 'pt' && PT_PT.has(w.region) ? r === 'PT' : false);
73
+ const variant = fits.find((c) => c.l.region && usual(c.l.region));
74
+ if (variant)
75
+ return variant.k;
76
+ }
77
+ // The least specific: `es` before `es-ES`, `zh-Hant` before `zh-TW`.
78
+ const plain = [...fits].sort((a, b) => a.l.baseName.split('-').length - b.l.baseName.split('-').length);
79
+ return plain[0].k;
80
+ }
81
+ /**
82
+ * `{n} files` in the user's language, with the plural form its rules ask
83
+ * for (Polish has four, Chinese one): `forms` by language, `{n}` filled in
84
+ * with the number written the language's way.
85
+ */
86
+ export function plural(n, forms, locale = 'en') {
87
+ const key = pickLocale(Object.keys(forms), locale) ?? (forms.en ? 'en' : Object.keys(forms)[0]);
88
+ const f = forms[key];
89
+ let rule = 'other';
90
+ try {
91
+ rule = new Intl.PluralRules(key).select(n);
92
+ }
93
+ catch {
94
+ /* an odd tag: other */
95
+ }
96
+ const text = f[rule] ?? f.other;
97
+ let num = String(n);
98
+ try {
99
+ num = new Intl.NumberFormat(key).format(n);
100
+ }
101
+ catch {
102
+ /* as is */
103
+ }
104
+ return text.replaceAll('{n}', num);
105
+ }
1
106
  export function localize(text, locale = 'en') {
2
107
  if (text === undefined)
3
108
  return '';
4
109
  if (typeof text === 'string')
5
110
  return text;
6
- const lang = locale.toLowerCase().split(/[-_]/)[0];
7
- return text[locale] ?? text[lang] ?? text.en ?? Object.values(text).find((v) => typeof v === 'string') ?? '';
111
+ const key = pickLocale(Object.keys(text), locale);
112
+ return (key ? text[key] : undefined) ?? text.en ?? Object.values(text).find((v) => typeof v === 'string') ?? '';
113
+ }
114
+ export function hanScript(locale) {
115
+ const l = parseLocale(locale || 'en');
116
+ if (!l)
117
+ return null;
118
+ const full = l.maximize();
119
+ switch (READS[full.language] ?? full.language) {
120
+ case 'zh':
121
+ if (full.script === 'Hant')
122
+ return full.region === 'HK' || full.region === 'MO' ? 'Hant-HK' : 'Hant';
123
+ return 'Hans';
124
+ case 'ja':
125
+ return 'Jpan';
126
+ case 'ko':
127
+ return 'Kore';
128
+ default:
129
+ return null;
130
+ }
131
+ }
132
+ /**
133
+ * An error to show the user, in their language: `throw new PluginError({
134
+ * en: 'Set your place in Settings', 'zh-Hant': '請在設定中設定位置', … })`.
135
+ * Its `message` is the English one (logs); Kiosko shows `text` in the
136
+ * user's language in the editor and on the tile.
137
+ */
138
+ export class PluginError extends Error {
139
+ text;
140
+ constructor(text, options) {
141
+ super(localize(text, 'en'), options);
142
+ this.name = 'PluginError';
143
+ this.text = text;
144
+ }
145
+ }
146
+ /** What to show for an error: a PluginError's text in `locale`, else the message. */
147
+ export function errorMessage(err, locale = 'en') {
148
+ if (err instanceof Error && 'text' in err && err.text !== undefined)
149
+ return localize(err.text, locale);
150
+ return err instanceof Error ? err.message : String(err);
8
151
  }
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './plugin.ts';
2
2
  export * from './schema.ts';
3
3
  export * from './theme.ts';
4
4
  export * from './i18n.ts';
5
+ export * from './languages.ts';
5
6
  export * from './format.ts';
6
7
  export * from './workday.ts';
7
8
  export * from './list.ts';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export * from "./plugin.js";
2
2
  export * from "./schema.js";
3
3
  export * from "./theme.js";
4
4
  export * from "./i18n.js";
5
+ export * from "./languages.js";
5
6
  export * from "./format.js";
6
7
  export * from "./workday.js";
7
8
  export * from "./list.js";
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The languages Kiosko speaks: the editor, the site, the panel's words for
3
+ * times (ctx.fmt) and the official plugins. One list, read by all of them;
4
+ * a test (packages/web/landing/languages.test.ts) checks that each has its
5
+ * dictionary, site page, time words and plugin texts. Adding a language
6
+ * starts here (CONTRIBUTING.md, "Translations").
7
+ */
8
+ export interface Language {
9
+ /** BCP 47 tag, as the texts are keyed (`es`, `zh-Hant`). */
10
+ id: string;
11
+ /** Its name in itself, for the language pickers. */
12
+ name: string;
13
+ /** The locale the panel paints the site's samples in (dates, times): `zh-TW` for `zh-Hant`. */
14
+ panel: string;
15
+ /** Open Graph locale of its site page (`zh_TW`). */
16
+ ogLocale: string;
17
+ /** What its site page is declared to be for (`hreflang`); English is also `x-default`. */
18
+ hreflang: string[];
19
+ /** Writing direction. Right-to-left is not drawn right on the panel yet. */
20
+ dir: 'ltr' | 'rtl';
21
+ /**
22
+ * Where this language's readers live, the services some plugins need may not
23
+ * be offered. The site, the sample config and the editor's tour leave those
24
+ * plugins out for it (`without`), lead with others (`first`) and paint these
25
+ * widgets in place of the missing ones (`instead`, type by type).
26
+ */
27
+ plugins?: {
28
+ without: readonly string[];
29
+ first: readonly string[];
30
+ instead: Readonly<Record<string, string>>;
31
+ };
32
+ }
33
+ export declare const LANGUAGES: readonly Language[];
34
+ export declare const LANGUAGE_IDS: readonly string[];
35
+ /** The language with this id (`zh-Hant`), if Kiosko speaks it. */
36
+ export declare function languageById(id: string): Language | undefined;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Simplified Chinese is read in mainland China, where Claude (and Gemini) are
3
+ * not offered: no AI-agent, cats-room nor Claude-usage plugins there, and local
4
+ * models (Qwen, DeepSeek… on your own GPU) in their place.
5
+ */
6
+ const MAINLAND_CHINA = {
7
+ without: ['agents', 'cats', 'usage'],
8
+ first: ['llm', 'gpu'],
9
+ instead: { 'agents/summary': 'llm/status', 'agents/sessions': 'llm/models', 'usage/rail': 'gpu/cards', 'cats/room': 'gpu/history' },
10
+ };
11
+ export const LANGUAGES = [
12
+ { id: 'en', name: 'English', panel: 'en', ogLocale: 'en_US', hreflang: ['en', 'x-default'], dir: 'ltr' },
13
+ { id: 'es', name: 'Español', panel: 'es', ogLocale: 'es_ES', hreflang: ['es'], dir: 'ltr' },
14
+ { id: 'de', name: 'Deutsch', panel: 'de', ogLocale: 'de_DE', hreflang: ['de'], dir: 'ltr' },
15
+ { id: 'zh-Hant', name: '繁體中文', panel: 'zh-TW', ogLocale: 'zh_TW', hreflang: ['zh-Hant', 'zh-TW', 'zh-HK'], dir: 'ltr' },
16
+ { id: 'zh-Hans', name: '简体中文', panel: 'zh-CN', ogLocale: 'zh_CN', hreflang: ['zh-Hans', 'zh-CN'], dir: 'ltr', plugins: MAINLAND_CHINA },
17
+ ];
18
+ export const LANGUAGE_IDS = LANGUAGES.map((l) => l.id);
19
+ /** The language with this id (`zh-Hant`), if Kiosko speaks it. */
20
+ export function languageById(id) {
21
+ return LANGUAGES.find((l) => l.id === id);
22
+ }
package/dist/list.js CHANGED
@@ -1,17 +1,20 @@
1
1
  import { t } from "./schema.js";
2
2
  const LAYOUT_LABELS = {
3
- auto: { en: 'Automatic', es: 'Automático' },
4
- 'one-line': { en: 'One line', es: 'Una línea' },
5
- detailed: { en: 'Detailed', es: 'Detallado' },
3
+ auto: { en: 'Automatic', es: 'Automático', de: 'Automatisch', 'zh-Hant': '自動', 'zh-Hans': '自动' },
4
+ 'one-line': { en: 'One line', es: 'Una línea', de: 'Eine Zeile', 'zh-Hant': '單行', 'zh-Hans': '单行' },
5
+ detailed: { en: 'Detailed', es: 'Detallado', de: 'Ausführlich', 'zh-Hant': '詳細', 'zh-Hans': '详细' },
6
6
  };
7
7
  const rowsField = (def) => t.integer({
8
8
  default: def,
9
9
  min: 0,
10
10
  max: 30,
11
- label: { en: 'Rows', es: 'Filas' },
11
+ label: { en: 'Rows', es: 'Filas', de: 'Zeilen', 'zh-Hant': '列數', 'zh-Hans': '行数' },
12
12
  help: {
13
13
  en: '0 = as many as fit. A number shows that many, in rows of a readable size (fewer when the tile is too small for them); the rest are counted in "+N more".',
14
14
  es: '0 = las que quepan. Con un número se ven esas, en filas de un tamaño legible (menos si la tesela no da para ellas); el resto se cuenta en «+N más».',
15
+ de: '0 = so viele, wie passen. Eine Zahl zeigt so viele, in Zeilen lesbarer Größe (weniger, wenn die Kachel dafür zu klein ist); der Rest wird als „+N weitere“ gezählt.',
16
+ 'zh-Hant': '0 = 盡量放滿。填數字則顯示該數量,並以易讀的大小排列(方格太小時會減少);其餘的計入「還有 N 個」。',
17
+ 'zh-Hans': '0 = 尽量放满。填数字则显示该数量,并以易读的大小排列(格子太小时会减少);其余的计入“还有 N 个”。',
15
18
  },
16
19
  });
17
20
  export function listOptions(o = {}) {
@@ -23,9 +26,9 @@ export function listOptions(o = {}) {
23
26
  rows,
24
27
  layout: t.enum(values, {
25
28
  default: o.layout ?? 'auto',
26
- label: { en: 'Row layout', es: 'Formato de fila' },
29
+ label: { en: 'Row layout', es: 'Formato de fila', de: 'Zeilenlayout', 'zh-Hant': '列版面', 'zh-Hans': '行布局' },
27
30
  labels: Object.fromEntries(values.map((v) => [v, LAYOUT_LABELS[v]])),
28
- help: { en: 'Automatic: the widget picks by the tile\'s shape.', es: 'Automático: el widget elige según la forma de la tesela.' },
31
+ help: { en: 'Automatic: the widget picks by the tile\'s shape.', es: 'Automático: el widget elige según la forma de la tesela.', de: 'Automatisch: Das Widget wählt nach der Form der Kachel.', 'zh-Hant': '自動:小工具依方格形狀選擇。', 'zh-Hans': '自动:小组件根据格子形状选择。' },
29
32
  }),
30
33
  };
31
34
  }
@@ -92,7 +95,7 @@ export function listLayout(box, count, options, spec) {
92
95
  }
93
96
  /** `"+3 more"` / `"+3 más"`. */
94
97
  export function moreLabel(n, tr) {
95
- return tr({ en: `+${n} more`, es: `+${n} más` });
98
+ return tr({ en: `+${n} more`, es: `+${n} más`, de: `+${n} weitere`, 'zh-Hant': `還有 ${n} 個`, 'zh-Hans': `还有 ${n} 个` });
96
99
  }
97
100
  /**
98
101
  * Paints "+N more" in the plan's `more` box, dim, the same in every list.
package/dist/location.js CHANGED
@@ -9,11 +9,11 @@ export function locationOptions() {
9
9
  step: 0.0001,
10
10
  unit: '°',
11
11
  advanced: true,
12
- label: { en: 'Latitude', es: 'Latitud' },
13
- help: { en: 'Leave latitude and longitude at 0 to use the place in Settings.', es: 'Con latitud y longitud a 0 se usa el lugar de los ajustes.' },
12
+ label: { en: 'Latitude', es: 'Latitud', de: 'Breitengrad', 'zh-Hant': '緯度', 'zh-Hans': '纬度' },
13
+ help: { en: 'Leave latitude and longitude at 0 to use the place in Settings.', es: 'Con latitud y longitud a 0 se usa el lugar de los ajustes.', de: 'Breiten- und Längengrad auf 0 lassen, um den Ort aus den Einstellungen zu verwenden.', 'zh-Hant': '緯度和經度保持 0 即使用設定中的地點。', 'zh-Hans': '纬度和经度保持为 0 时使用设置中的地点。' },
14
14
  }),
15
- longitude: t.number({ default: 0, min: -180, max: 180, step: 0.0001, unit: '°', advanced: true, label: { en: 'Longitude', es: 'Longitud' } }),
16
- placeName: t.string({ advanced: true, placeholder: 'Madrid', label: { en: 'Place name', es: 'Nombre del lugar' }, help: { en: 'Empty: the one in Settings.', es: 'Vacío: el de los ajustes.' } }),
15
+ longitude: t.number({ default: 0, min: -180, max: 180, step: 0.0001, unit: '°', advanced: true, label: { en: 'Longitude', es: 'Longitud', de: 'Längengrad', 'zh-Hant': '經度', 'zh-Hans': '经度' } }),
16
+ placeName: t.string({ advanced: true, placeholder: 'Madrid', label: { en: 'Place name', es: 'Nombre del lugar', de: 'Ortsname', 'zh-Hant': '地點名稱', 'zh-Hans': '地点名称' }, help: { en: 'Empty: the one in Settings.', es: 'Vacío: el de los ajustes.', de: 'Leer: der aus den Einstellungen.', 'zh-Hant': '留空:使用設定中的地點。', 'zh-Hans': '留空:使用设置中的地点。' } }),
17
17
  };
18
18
  }
19
19
  /**
package/dist/plugin.d.ts CHANGED
@@ -20,7 +20,7 @@
20
20
  import type { Canvas, Image, SKRSContext2D, createCanvas, loadImage } from '@napi-rs/canvas';
21
21
  import type * as Kit from '@loksly/lcd-canvas-kit';
22
22
  import type { Formatters } from './format.ts';
23
- import type { Localized } from './i18n.ts';
23
+ import type { Localized, PluralForms } from './i18n.ts';
24
24
  import type { Field, Infer, ObjectField } from './schema.ts';
25
25
  import type { Theme } from './theme.ts';
26
26
  import type { Workday } from './workday.ts';
@@ -80,6 +80,18 @@ export interface BaseContext {
80
80
  locale: string;
81
81
  /** Picks the user's language from a `Localized` text. */
82
82
  t: (text: Localized) => string;
83
+ /**
84
+ * `{n} files` with the plural form the user's language asks for:
85
+ * `ctx.plural(n, { en: { one: '{n} file', other: '{n} files' }, 'zh-Hant': { other: '{n} 個檔案' } })`.
86
+ * Use it for any text with a count in it, rather than `n === 1 ? … : …`.
87
+ */
88
+ plural: (n: number, forms: Record<string, PluralForms>) => string;
89
+ /**
90
+ * Which of `available` (language tags) to use for this user: for tables
91
+ * kept one per language (`TABLES[ctx.pickLanguage(Object.keys(TABLES))]`).
92
+ * English when none fits, else the first.
93
+ */
94
+ pickLanguage: (available: readonly string[]) => string;
83
95
  /**
84
96
  * Times and lengths of time in the user's language and clock (Settings →
85
97
  * time format): `fmt.time(at)` "14:05" / "2:05 PM", `fmt.ago(at)`
@@ -438,7 +450,7 @@ export interface InterludeDefinition<OF extends ObjectField<any> = ObjectField<a
438
450
  * package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
439
451
  * it runs); the registry compares them with `satisfies`.
440
452
  */
441
- export declare const SDK_VERSION = "0.2.5";
453
+ export declare const SDK_VERSION = "0.2.6";
442
454
  /**
443
455
  * What a plugin does on the machine, declared for the person who installs
444
456
  * it: the Plugins page and the plugin store show it next to the plugin. It
@@ -522,6 +534,15 @@ export interface PluginDefinition {
522
534
  optional?: string[];
523
535
  /** The operating systems it works on. Omitted: all. Also npm's `os` in package.json. */
524
536
  platforms?: Platform[];
537
+ /**
538
+ * The languages its texts come in, as BCP 47 tags, English first:
539
+ * `['en', 'es', 'zh-Hant', 'zh-Hans']`. Chinese goes by script (`zh-Hant`
540
+ * for Taiwan and Hong Kong, `zh-Hans` for mainland China), never a bare
541
+ * `zh`. Every `Localized` text of the plugin has them all (the linter
542
+ * says which lack one). Also `kiosko.languages` in package.json, so a
543
+ * catalogue knows without running it. Omitted: the ones its texts use.
544
+ */
545
+ languages?: string[];
525
546
  widgets?: WidgetDefinition<any, any>[];
526
547
  sources?: SourceDefinition<any, any>[];
527
548
  interludes?: InterludeDefinition<any>[];
package/dist/plugin.js CHANGED
@@ -1,13 +1,13 @@
1
1
  export const CATEGORIES = [
2
- { id: 'agents', label: { en: 'AI agents', es: 'Agentes IA' } },
3
- { id: 'system', label: { en: 'System', es: 'Sistema' } },
4
- { id: 'time', label: { en: 'Time & calendar', es: 'Tiempo y agenda' } },
5
- { id: 'productivity', label: { en: 'Productivity', es: 'Productividad' } },
6
- { id: 'dev', label: { en: 'Development', es: 'Desarrollo' } },
7
- { id: 'info', label: { en: 'News & world', es: 'Noticias y mundo' } },
8
- { id: 'media', label: { en: 'Media', es: 'Multimedia' } },
9
- { id: 'scene', label: { en: 'Scenes', es: 'Escenas' } },
10
- { id: 'fun', label: { en: 'Fun', es: 'Diversión' } },
2
+ { id: 'agents', label: { en: 'AI agents', es: 'Agentes IA', de: 'KI-Agenten', 'zh-Hant': 'AI 代理', 'zh-Hans': 'AI 智能体' } },
3
+ { id: 'system', label: { en: 'System', es: 'Sistema', de: 'System', 'zh-Hant': '系統', 'zh-Hans': '系统' } },
4
+ { id: 'time', label: { en: 'Time & calendar', es: 'Tiempo y agenda', de: 'Zeit & Kalender', 'zh-Hant': '時間與行事曆', 'zh-Hans': '时间与日历' } },
5
+ { id: 'productivity', label: { en: 'Productivity', es: 'Productividad', de: 'Produktivität', 'zh-Hant': '生產力', 'zh-Hans': '效率' } },
6
+ { id: 'dev', label: { en: 'Development', es: 'Desarrollo', de: 'Entwicklung', 'zh-Hant': '開發', 'zh-Hans': '开发' } },
7
+ { id: 'info', label: { en: 'News & world', es: 'Noticias y mundo', de: 'Nachrichten & Welt', 'zh-Hant': '新聞與世界', 'zh-Hans': '新闻与世界' } },
8
+ { id: 'media', label: { en: 'Media', es: 'Multimedia', de: 'Medien', 'zh-Hant': '多媒體', 'zh-Hans': '多媒体' } },
9
+ { id: 'scene', label: { en: 'Scenes', es: 'Escenas', de: 'Szenen', 'zh-Hant': '場景', 'zh-Hans': '场景' } },
10
+ { id: 'fun', label: { en: 'Fun', es: 'Diversión', de: 'Spaß', 'zh-Hant': '趣味', 'zh-Hans': '趣味' } },
11
11
  ];
12
12
  /**
13
13
  * The version of the plugin API this Kiosko speaks. A plugin says which
@@ -15,7 +15,7 @@ export const CATEGORIES = [
15
15
  * package.json, `"kiosko": { "sdk": "^0.2.0" }`, so it can be refused before
16
16
  * it runs); the registry compares them with `satisfies`.
17
17
  */
18
- export const SDK_VERSION = '0.2.5';
18
+ export const SDK_VERSION = '0.2.6';
19
19
  /* Identity helpers: they only exist so TypeScript infers option and data types. */
20
20
  export function defineWidget(w) {
21
21
  return w;