lambder 3.2.1 → 3.2.3
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 +24 -2
- package/dist/LambderI18n.js +22 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/LambderI18n.d.ts
CHANGED
|
@@ -89,15 +89,37 @@ export interface LambderI18nInstance<TLanguages extends Record<string, LambderLa
|
|
|
89
89
|
resetLanguage(): void;
|
|
90
90
|
/** The currently active language code. */
|
|
91
91
|
readonly currentLanguage: keyof TLanguages & string;
|
|
92
|
-
/** Metadata of the currently active language. */
|
|
93
|
-
readonly currentLanguageMeta: TLanguages[keyof TLanguages]
|
|
92
|
+
/** Metadata of the currently active language, with `code` injected. */
|
|
93
|
+
readonly currentLanguageMeta: TLanguages[keyof TLanguages] & {
|
|
94
|
+
code: keyof TLanguages & string;
|
|
95
|
+
};
|
|
96
|
+
/** Text direction of the active language (defaults to "ltr"). */
|
|
97
|
+
readonly currentDir: "ltr" | "rtl";
|
|
98
|
+
/** BCP-47 locale of the active language for Intl APIs (defaults to the code). */
|
|
99
|
+
readonly currentIntlLocale: string;
|
|
94
100
|
/** Subscribe to language changes. Returns an unsubscribe function. */
|
|
95
101
|
onLanguageChange(listener: (code: keyof TLanguages & string) => void): () => void;
|
|
102
|
+
/**
|
|
103
|
+
* Apply the active language to `<html lang>` and `<html dir>` (RTL support).
|
|
104
|
+
* No-op outside a browser. Re-apply on changes with
|
|
105
|
+
* `i18n.onLanguageChange(() => i18n.applyToDocument())`.
|
|
106
|
+
*/
|
|
107
|
+
applyToDocument(): void;
|
|
96
108
|
/** Type guard: is this string a supported language code? */
|
|
97
109
|
isLanguageCode(value: string): value is keyof TLanguages & string;
|
|
98
110
|
readonly languages: TLanguages;
|
|
99
111
|
readonly languageList: (keyof TLanguages & string)[];
|
|
112
|
+
/** Ordered language metadata (declaration order), with `code` injected — ready for switcher menus. */
|
|
113
|
+
readonly languageMetaList: (TLanguages[keyof TLanguages] & {
|
|
114
|
+
code: keyof TLanguages & string;
|
|
115
|
+
})[];
|
|
100
116
|
readonly defaultLanguage: TDefault;
|
|
101
117
|
readonly enforced: TEnforced;
|
|
102
118
|
}
|
|
119
|
+
/** Language codes of an instance: `LambderI18nCodes<typeof i18n>`. */
|
|
120
|
+
export type LambderI18nCodes<T> = T extends LambderI18nInstance<infer L, any, any, any> ? keyof L & string : never;
|
|
121
|
+
/** Translation keys of an instance: `LambderI18nKeys<typeof i18n>`. */
|
|
122
|
+
export type LambderI18nKeys<T> = T extends LambderI18nInstance<any, any, any, infer C> ? keyof C & string : never;
|
|
123
|
+
/** Translator type of an instance: `LambderI18nTranslatorFor<typeof i18n>`. */
|
|
124
|
+
export type LambderI18nTranslatorFor<T> = T extends LambderI18nInstance<any, any, any, infer C> ? LambderI18nTranslator<C> : never;
|
|
103
125
|
export declare const createLambderI18n: <const TLanguages extends Record<string, LambderLanguageMeta>, const TDefault extends keyof TLanguages & string, const TEnforced extends readonly (keyof TLanguages & string)[], const TContract extends Record<string, string>>(config: LambderI18nConfig<TLanguages, TDefault, TEnforced, TContract>) => LambderI18nInstance<TLanguages, TDefault, TEnforced, TContract>;
|
package/dist/LambderI18n.js
CHANGED
|
@@ -131,11 +131,32 @@ const buildInstance = (core, layer) => {
|
|
|
131
131
|
setLanguage(code) { core.state.set(code); },
|
|
132
132
|
resetLanguage() { core.state.reset(); },
|
|
133
133
|
get currentLanguage() { return core.state.resolve(); },
|
|
134
|
-
get currentLanguageMeta() {
|
|
134
|
+
get currentLanguageMeta() {
|
|
135
|
+
const code = core.state.resolve();
|
|
136
|
+
return { code, ...core.languages[code] };
|
|
137
|
+
},
|
|
138
|
+
get currentDir() {
|
|
139
|
+
return core.languages[core.state.resolve()]?.dir ?? "ltr";
|
|
140
|
+
},
|
|
141
|
+
get currentIntlLocale() {
|
|
142
|
+
const code = core.state.resolve();
|
|
143
|
+
return core.languages[code]?.intlLocale ?? code;
|
|
144
|
+
},
|
|
135
145
|
onLanguageChange(listener) { return core.state.subscribe(listener); },
|
|
146
|
+
applyToDocument() {
|
|
147
|
+
const doc = globalThis.document;
|
|
148
|
+
if (!doc)
|
|
149
|
+
return;
|
|
150
|
+
const code = core.state.resolve();
|
|
151
|
+
doc.documentElement.lang = code;
|
|
152
|
+
doc.documentElement.dir = core.languages[code]?.dir ?? "ltr";
|
|
153
|
+
},
|
|
136
154
|
isLanguageCode: core.isCode,
|
|
137
155
|
languages: core.languages,
|
|
138
156
|
languageList: core.languageList,
|
|
157
|
+
get languageMetaList() {
|
|
158
|
+
return core.languageList.map((code) => ({ code, ...core.languages[code] }));
|
|
159
|
+
},
|
|
139
160
|
defaultLanguage: core.defaultLanguage,
|
|
140
161
|
enforced: core.enforced,
|
|
141
162
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type { LambderSessionContext } from "./LambderSessionManager.js";
|
|
|
20
20
|
export { LambderDdbCache } from "./LambderDdbCache.js";
|
|
21
21
|
export type { LambderDdbCacheOptions, LambderDdbCacheSetOptions, LambderDdbCacheGetOrSetOptions, } from "./LambderDdbCache.js";
|
|
22
22
|
export { createLambderI18n } from "./LambderI18n.js";
|
|
23
|
-
export type { LambderLanguageMeta, LambderI18nConfig, LambderI18nInstance, LambderI18nTranslator, LambderI18nExtractParams, } from "./LambderI18n.js";
|
|
23
|
+
export type { LambderLanguageMeta, LambderI18nConfig, LambderI18nInstance, LambderI18nTranslator, LambderI18nExtractParams, LambderI18nCodes, LambderI18nKeys, LambderI18nTranslatorFor, } from "./LambderI18n.js";
|
|
24
24
|
export { type ApiContractShape, } from "./LambderApiContract.js";
|
|
25
25
|
export type { LambderRenderContext, LambderSessionRenderContext, LambderHttpEvent } from "./LambderContext.js";
|
|
26
26
|
export { createContext, isV2HttpEvent } from "./LambderContext.js";
|