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 +8 -0
- package/README.md +26 -8
- package/dist/index.js +34 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -31
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/langsys-js-typescript)
|
|
4
|
+
[](https://github.com/langsys/langsys-js-typescript/actions)
|
|
5
|
+
[](https://github.com/langsys/langsys-js-typescript/commits)
|
|
6
|
+
[](https://github.com/langsys/langsys-js-typescript/pulse)
|
|
7
|
+
[](https://bundlejs.com/?q=langsys-js-typescript)
|
|
8
|
+
[](https://www.npmjs.com/package/langsys-js-typescript)
|
|
9
|
+
[](https://www.npmjs.com/package/langsys-js-typescript)
|
|
10
|
+
[](./LICENSE)
|
|
4
11
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
-
|
|
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
|
-
|
|
165
|
-
|
|
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
|
-
|
|
168
|
-
-
|
|
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() {
|