lambder 3.2.1 → 3.2.2
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/LambderI18n.d.ts +6 -0
- package/dist/LambderI18n.js +8 -0
- package/package.json +1 -1
package/dist/LambderI18n.d.ts
CHANGED
|
@@ -93,6 +93,12 @@ export interface LambderI18nInstance<TLanguages extends Record<string, LambderLa
|
|
|
93
93
|
readonly currentLanguageMeta: TLanguages[keyof TLanguages];
|
|
94
94
|
/** Subscribe to language changes. Returns an unsubscribe function. */
|
|
95
95
|
onLanguageChange(listener: (code: keyof TLanguages & string) => void): () => void;
|
|
96
|
+
/**
|
|
97
|
+
* Apply the active language to `<html lang>` and `<html dir>` (RTL support).
|
|
98
|
+
* No-op outside a browser. Re-apply on changes with
|
|
99
|
+
* `i18n.onLanguageChange(() => i18n.applyToDocument())`.
|
|
100
|
+
*/
|
|
101
|
+
applyToDocument(): void;
|
|
96
102
|
/** Type guard: is this string a supported language code? */
|
|
97
103
|
isLanguageCode(value: string): value is keyof TLanguages & string;
|
|
98
104
|
readonly languages: TLanguages;
|
package/dist/LambderI18n.js
CHANGED
|
@@ -133,6 +133,14 @@ const buildInstance = (core, layer) => {
|
|
|
133
133
|
get currentLanguage() { return core.state.resolve(); },
|
|
134
134
|
get currentLanguageMeta() { return core.languages[core.state.resolve()]; },
|
|
135
135
|
onLanguageChange(listener) { return core.state.subscribe(listener); },
|
|
136
|
+
applyToDocument() {
|
|
137
|
+
const doc = globalThis.document;
|
|
138
|
+
if (!doc)
|
|
139
|
+
return;
|
|
140
|
+
const code = core.state.resolve();
|
|
141
|
+
doc.documentElement.lang = code;
|
|
142
|
+
doc.documentElement.dir = core.languages[code]?.dir ?? "ltr";
|
|
143
|
+
},
|
|
136
144
|
isLanguageCode: core.isCode,
|
|
137
145
|
languages: core.languages,
|
|
138
146
|
languageList: core.languageList,
|