lambder 3.2.2 → 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 +18 -2
- package/dist/LambderI18n.js +14 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/LambderI18n.d.ts
CHANGED
|
@@ -89,8 +89,14 @@ 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;
|
|
96
102
|
/**
|
|
@@ -103,7 +109,17 @@ export interface LambderI18nInstance<TLanguages extends Record<string, LambderLa
|
|
|
103
109
|
isLanguageCode(value: string): value is keyof TLanguages & string;
|
|
104
110
|
readonly languages: TLanguages;
|
|
105
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
|
+
})[];
|
|
106
116
|
readonly defaultLanguage: TDefault;
|
|
107
117
|
readonly enforced: TEnforced;
|
|
108
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;
|
|
109
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,7 +131,17 @@ 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); },
|
|
136
146
|
applyToDocument() {
|
|
137
147
|
const doc = globalThis.document;
|
|
@@ -144,6 +154,9 @@ const buildInstance = (core, layer) => {
|
|
|
144
154
|
isLanguageCode: core.isCode,
|
|
145
155
|
languages: core.languages,
|
|
146
156
|
languageList: core.languageList,
|
|
157
|
+
get languageMetaList() {
|
|
158
|
+
return core.languageList.map((code) => ({ code, ...core.languages[code] }));
|
|
159
|
+
},
|
|
147
160
|
defaultLanguage: core.defaultLanguage,
|
|
148
161
|
enforced: core.enforced,
|
|
149
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";
|