langsys-js-typescript 0.6.4 → 0.6.5

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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.6.5 - 2026-08-16
2
+
3
+ ### Added
4
+
5
+ - **Debug warning when a locale tag is not valid BCP 47.** `canonicalizeLocale` falls back to best-effort casing rather than throwing, which is the right behavior — but the return value cannot signal that it happened: a best-effort string is indistinguishable from a successfully canonicalized one. So a typo'd config locale degrades to a silent failed catalog lookup, and the app renders base language, which is exactly what a legitimately-untranslated locale looks like. Nothing downstream can tell the difference, so the warning is emitted where the information still exists. Behavior and return values are unchanged; silent in production.
6
+
7
+ Found by applying a predictive form of a pattern this release series kept hitting, contributed by the Svelte binding: **look for any fallback whose output is drawn from the same value space as its success output.** That makes the class searchable by inspection rather than discoverable by tripping over it — null-as-zero, empty-string-as-absent, best-effort-locale-as-canonical.
8
+
1
9
  ## 0.6.4 - 2026-08-16
2
10
 
3
11
  ### Fixed
package/README.md CHANGED
@@ -1,10 +1,17 @@
1
1
  # Langsys SDK — TypeScript
2
2
 
3
- Framework-agnostic TypeScript SDK for the [Langsys](https://Langsys.dev/) Translation Manager. Realtime, continuous translations with automatic token discovery — no framework required.
3
+ [![npm](https://img.shields.io/npm/v/langsys-js-typescript.svg?style=flat)](https://www.npmjs.com/package/langsys-js-typescript)
4
+ [![build](https://img.shields.io/github/actions/workflow/status/langsys/langsys-js-typescript/ci.yml?style=flat)](https://github.com/langsys/langsys-js-typescript/actions)
5
+ [![last commit](https://img.shields.io/github/last-commit/langsys/langsys-js-typescript.svg?style=flat)](https://github.com/langsys/langsys-js-typescript/commits)
6
+ [![commit activity](https://img.shields.io/github/commit-activity/m/langsys/langsys-js-typescript.svg?style=flat)](https://github.com/langsys/langsys-js-typescript/pulse)
7
+ [![bundle size](https://img.shields.io/bundlejs/size/langsys-js-typescript?style=flat)](https://bundlejs.com/?q=langsys-js-typescript)
8
+ [![types](https://img.shields.io/npm/types/langsys-js-typescript.svg?style=flat)](https://www.npmjs.com/package/langsys-js-typescript)
9
+ [![downloads](https://img.shields.io/npm/dm/langsys-js-typescript.svg?style=flat)](https://www.npmjs.com/package/langsys-js-typescript)
10
+ [![license](https://img.shields.io/npm/l/langsys-js-typescript.svg?style=flat)](./LICENSE)
4
11
 
5
- This is the base SDK. Framework-specific bindings (`langsys-js-svelte`, and similar packages for React / Vue / Solid that can be built on top of this) are thin wrappers that add idiomatic framework reactivity around the same core.
12
+ Framework-agnostic TypeScript SDK for the [Langsys](https://Langsys.dev/) Translation Manager. Realtime, continuous translations with automatic token discovery — no framework required.
6
13
 
7
- [![NPM License](https://img.shields.io/npm/l/all-contributors.svg?style=flat)](./LICENSE)
14
+ This is the base SDK. Framework-specific bindings (`langsys-js-svelte`, `langsys-js-react`, `langsys-js-vue`) are thin wrappers that add idiomatic framework reactivity around the same core.
8
15
 
9
16
  ## What's inside
10
17
 
@@ -14,7 +21,7 @@ This is the base SDK. Framework-specific bindings (`langsys-js-svelte`, and simi
14
21
  - `Translate` class — wraps a DOM element, walks text + translatable attributes, registers a content block with the Translation Manager, re-translates on locale change.
15
22
  - `Signal<T>` — tiny subscribe/set/update/get primitive. Compatible with Svelte's store contract by design, so the Svelte binding is nearly trivial.
16
23
  - `LangsysAppAPI` — direct HTTP access if you want to bypass everything else.
17
- - Zero runtime dependencies. Works in browsers, Node, any bundler.
24
+ - One runtime dependency (`intl-messageformat`, for ICU plurals and gender selects). ~20 kB gzipped. Works in browsers, Node, any bundler.
18
25
 
19
26
  ## Install
20
27
 
@@ -161,11 +168,22 @@ handle.destroy();
161
168
 
162
169
  Attributes honored on contained elements:
163
170
 
164
- - `placeholder`, `alt`, `title`, `aria-label`, `aria-placeholder`
165
- - `value` on `<button>`, `<input type="submit">`, `<input type="button">`
171
+ **Visible text**
172
+
173
+ - `placeholder`, `alt`, `title`, `label`
174
+ - `value` on `<button>`, `<input type="submit">`, `<input type="button">` — and *only* those; a text input's value is never rewritten
166
175
  - `<option>` text inside `<select>`
167
- - Several validation-message `data-*` attributes
168
- - `translate="no"` — elements marked this way (and their children) are skipped
176
+
177
+ **Screen-reader text** — `aria-label`, `aria-placeholder`, `aria-description`, `aria-valuetext`, `aria-roledescription`
178
+
179
+ > Leaving these untranslated has **no visible symptom**. Nothing on the page changes, so reviewing the rendered output cannot catch it — the failure is audible only to the users least able to work around it.
180
+
181
+ **Validation messages** — `data-error`, `data-error-message`, `data-validation-message`, `data-invalid-message`, `data-required-message`, `data-pattern-message`
182
+
183
+ **Opting out**
184
+
185
+ - `translate="no"` (case-insensitive), or `data-notrans` — `langsys-php`'s author-facing alias, honored here so an SSR-rendered page opts out consistently in both SDKs. Presence means intent; an explicit `="false"` or `="0"` opts back in.
186
+ - Elements marked this way, and their children, are skipped entirely.
169
187
 
170
188
  > **`Translate` tokenizes per text node — so inline markup splits a sentence.**
171
189
  >
package/dist/index.js CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  var intlMessageformat = require('intl-messageformat');
4
4
 
5
+ // src/logger.ts
6
+ var STYLES = {
7
+ log: "display:inline-block;background:rgb(239,239,244);color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
8
+ warn: "display:inline-block;background:gold;color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
9
+ error: "display:inline-block;background:#e0005a;color:#fff;font-weight:bold;padding:3px 7px;border-radius:3px"
10
+ };
11
+ var supportsStyle = typeof window !== "undefined";
12
+ function emit(level, label, args) {
13
+ if (supportsStyle) {
14
+ console[level](`%c${label}`, STYLES[level], ...args);
15
+ } else {
16
+ console[level](`[${label}]`, ...args);
17
+ }
18
+ }
19
+ var Logger = class {
20
+ constructor(debugEnabled = false) {
21
+ this.debugEnabled = debugEnabled;
22
+ }
23
+ log(...args) {
24
+ if (!this.debugEnabled) return;
25
+ emit("log", "Langsys Debug", args);
26
+ }
27
+ warn(...args) {
28
+ emit("warn", "Langsys Warning", args);
29
+ }
30
+ error(...args) {
31
+ emit("error", "Langsys Error", args);
32
+ }
33
+ };
34
+ var logger = new Logger(false);
35
+
5
36
  // src/locale.ts
6
37
  function canonicalizeLocale(locale) {
7
38
  if (!locale || typeof locale !== "string") return locale;
@@ -10,6 +41,9 @@ function canonicalizeLocale(locale) {
10
41
  const [canonical] = Intl.getCanonicalLocales(cleaned);
11
42
  return canonical ?? cleaned;
12
43
  } catch {
44
+ if (logger.debugEnabled) logger.warn(
45
+ `"${locale}" is not a valid BCP 47 locale tag. Falling back to best-effort casing, which will very likely miss the catalog and render base language with no other symptom.`
46
+ );
13
47
  return cleaned.split("-").map((part, i) => {
14
48
  if (i === 0) return part.toLowerCase();
15
49
  if (part.length === 4) return part[0].toUpperCase() + part.slice(1).toLowerCase();
@@ -53,37 +87,6 @@ function getValue(signal) {
53
87
  return signal.get();
54
88
  }
55
89
 
56
- // src/logger.ts
57
- var STYLES = {
58
- log: "display:inline-block;background:rgb(239,239,244);color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
59
- warn: "display:inline-block;background:gold;color:black;font-weight:bold;padding:3px 7px;border-radius:3px",
60
- error: "display:inline-block;background:#e0005a;color:#fff;font-weight:bold;padding:3px 7px;border-radius:3px"
61
- };
62
- var supportsStyle = typeof window !== "undefined";
63
- function emit(level, label, args) {
64
- if (supportsStyle) {
65
- console[level](`%c${label}`, STYLES[level], ...args);
66
- } else {
67
- console[level](`[${label}]`, ...args);
68
- }
69
- }
70
- var Logger = class {
71
- constructor(debugEnabled = false) {
72
- this.debugEnabled = debugEnabled;
73
- }
74
- log(...args) {
75
- if (!this.debugEnabled) return;
76
- emit("log", "Langsys Debug", args);
77
- }
78
- warn(...args) {
79
- emit("warn", "Langsys Warning", args);
80
- }
81
- error(...args) {
82
- emit("error", "Langsys Error", args);
83
- }
84
- };
85
- var logger = new Logger(false);
86
-
87
90
  // src/api.ts
88
91
  var LangsysAppAPIClass = class {
89
92
  constructor() {