@digitaldefiance/i18n-lib 1.3.5 → 1.3.6
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/README.md +5 -0
- package/dist/context.d.ts +6 -6
- package/dist/context.js +1 -1
- package/dist/default-config.d.ts +2 -2
- package/dist/i18n-config.d.ts +2 -2
- package/dist/i18n-context.d.ts +2 -2
- package/dist/i18n-engine.d.ts +3 -3
- package/dist/plugin-i18n-engine.d.ts +1 -0
- package/dist/plugin-i18n-engine.js +3 -1
- package/dist/typed-error.d.ts +1 -1
- package/dist/types.d.ts +1 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2274,6 +2274,11 @@ For issues, questions, or contributions:
|
|
|
2274
2274
|
|
|
2275
2275
|
## ChangeLog
|
|
2276
2276
|
|
|
2277
|
+
### Version 1.3.6
|
|
2278
|
+
|
|
2279
|
+
- Simplify LanguageContextSpace and generics related to it
|
|
2280
|
+
- Make plugin engine respect admin context
|
|
2281
|
+
|
|
2277
2282
|
### Version 1.3.5
|
|
2278
2283
|
|
|
2279
2284
|
- CommonJS
|
package/dist/context.d.ts
CHANGED
|
@@ -11,34 +11,34 @@ import { LanguageContextSpace } from './types';
|
|
|
11
11
|
* @param defaultAdminTimezone - The default admin timezone (defaults to UTC)
|
|
12
12
|
* @returns A new I18nContext instance
|
|
13
13
|
*/
|
|
14
|
-
export declare function createContext<TLanguage extends string
|
|
14
|
+
export declare function createContext<TLanguage extends string>(defaultLanguage: TLanguage, defaultContext?: LanguageContextSpace, defaultCurrencyCode?: CurrencyCode, defaultTimezone?: Timezone, defaultAdminTimezone?: Timezone): I18nContext<TLanguage>;
|
|
15
15
|
/**
|
|
16
16
|
* Sets the language for the given I18n context.
|
|
17
17
|
* @param context - The I18n context to modify
|
|
18
18
|
* @param language - The language to set
|
|
19
19
|
*/
|
|
20
|
-
export declare function setLanguage<TLanguage extends string
|
|
20
|
+
export declare function setLanguage<TLanguage extends string>(context: I18nContext<TLanguage>, language: TLanguage): void;
|
|
21
21
|
/**
|
|
22
22
|
* Sets the admin language for the given I18n context.
|
|
23
23
|
* @param context - The I18n context to modify
|
|
24
24
|
* @param language - The admin language to set
|
|
25
25
|
*/
|
|
26
|
-
export declare function setAdminLanguage<TLanguage extends string
|
|
26
|
+
export declare function setAdminLanguage<TLanguage extends string>(context: I18nContext<TLanguage>, language: TLanguage): void;
|
|
27
27
|
/**
|
|
28
28
|
* Sets the current context for the given I18n context.
|
|
29
29
|
* @param context - The I18n context to modify
|
|
30
30
|
* @param languageContext - The language context to set
|
|
31
31
|
*/
|
|
32
|
-
export declare function setContext<TLanguage extends string
|
|
32
|
+
export declare function setContext<TLanguage extends string>(context: I18nContext<TLanguage>, languageContext: LanguageContextSpace): void;
|
|
33
33
|
/**
|
|
34
34
|
* Sets the timezone for the given I18n context.
|
|
35
35
|
* @param context - The I18n context to modify
|
|
36
36
|
* @param timezone - The timezone to set
|
|
37
37
|
*/
|
|
38
|
-
export declare function setTimezone<TLanguage extends string
|
|
38
|
+
export declare function setTimezone<TLanguage extends string>(context: I18nContext<TLanguage>, timezone: Timezone): void;
|
|
39
39
|
/**
|
|
40
40
|
* Sets the admin timezone for the given I18n context.
|
|
41
41
|
* @param context - The I18n context to modify
|
|
42
42
|
* @param timezone - The admin timezone to set
|
|
43
43
|
*/
|
|
44
|
-
export declare function setAdminTimezone<TLanguage extends string
|
|
44
|
+
export declare function setAdminTimezone<TLanguage extends string>(context: I18nContext<TLanguage>, timezone: Timezone): void;
|
package/dist/context.js
CHANGED
|
@@ -17,7 +17,7 @@ const timezone_1 = require("./timezone");
|
|
|
17
17
|
* @param defaultAdminTimezone - The default admin timezone (defaults to UTC)
|
|
18
18
|
* @returns A new I18nContext instance
|
|
19
19
|
*/
|
|
20
|
-
function createContext(defaultLanguage, defaultContext, defaultCurrencyCode = new currency_code_1.CurrencyCode('USD'), defaultTimezone = new timezone_1.Timezone('UTC'), defaultAdminTimezone = new timezone_1.Timezone('UTC')) {
|
|
20
|
+
function createContext(defaultLanguage, defaultContext = 'admin', defaultCurrencyCode = new currency_code_1.CurrencyCode('USD'), defaultTimezone = new timezone_1.Timezone('UTC'), defaultAdminTimezone = new timezone_1.Timezone('UTC')) {
|
|
21
21
|
return {
|
|
22
22
|
language: defaultLanguage,
|
|
23
23
|
adminLanguage: defaultLanguage,
|
package/dist/default-config.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare global {
|
|
|
20
20
|
StringKey: DefaultStringKey;
|
|
21
21
|
Language: DefaultLanguageCode;
|
|
22
22
|
LanguageCodes: LanguageCodeCollection<DefaultLanguageCode>;
|
|
23
|
-
engine: I18nEngine<I18n.Config['StringKey'], I18n.Config['Language'], Record<any, any
|
|
23
|
+
engine: I18nEngine<I18n.Config['StringKey'], I18n.Config['Language'], Record<any, any>>;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -29,4 +29,4 @@ export type Language = I18n.Config['Language'];
|
|
|
29
29
|
export type Engine = I18n.Config['engine'];
|
|
30
30
|
export type DefaultLanguageCodesType = I18n.Config['LanguageCodes'];
|
|
31
31
|
export declare const getI18nEngine: () => Engine;
|
|
32
|
-
export declare const getDefaultI18nEngine: <TConstants extends Record<string, any>,
|
|
32
|
+
export declare const getDefaultI18nEngine: <TConstants extends Record<string, any>, TContext extends I18nContext<DefaultLanguageCode>>(constants: TConstants, timezone?: Timezone, adminTimezone?: Timezone) => I18nEngine<DefaultStringKey, DefaultLanguageCode, TConstants, TContext>;
|
package/dist/i18n-config.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { LanguageCodeCollection, LanguageContextSpace, MasterStringsCollection }
|
|
|
4
4
|
/**
|
|
5
5
|
* I18n configuration interface
|
|
6
6
|
*/
|
|
7
|
-
export interface I18nConfig<TStringKey extends string, TLanguage extends string, TConstants extends Record<string, any> = Record<string, any
|
|
7
|
+
export interface I18nConfig<TStringKey extends string, TLanguage extends string, TConstants extends Record<string, any> = Record<string, any>> {
|
|
8
8
|
stringNames: TStringKey[];
|
|
9
9
|
strings: MasterStringsCollection<TStringKey, TLanguage>;
|
|
10
10
|
defaultLanguage: TLanguage;
|
|
11
|
-
defaultTranslationContext:
|
|
11
|
+
defaultTranslationContext: LanguageContextSpace;
|
|
12
12
|
defaultCurrencyCode: CurrencyCode;
|
|
13
13
|
languageCodes: LanguageCodeCollection<TLanguage>;
|
|
14
14
|
languages: TLanguage[];
|
package/dist/i18n-context.d.ts
CHANGED
|
@@ -4,11 +4,11 @@ import { LanguageContextSpace } from './types';
|
|
|
4
4
|
/**
|
|
5
5
|
* I18n context interface
|
|
6
6
|
*/
|
|
7
|
-
export interface I18nContext<TLanguage extends string
|
|
7
|
+
export interface I18nContext<TLanguage extends string> {
|
|
8
8
|
language: TLanguage;
|
|
9
9
|
adminLanguage: TLanguage;
|
|
10
10
|
currencyCode: CurrencyCode;
|
|
11
|
-
currentContext:
|
|
11
|
+
currentContext: LanguageContextSpace;
|
|
12
12
|
timezone: Timezone;
|
|
13
13
|
adminTimezone: Timezone;
|
|
14
14
|
}
|
package/dist/i18n-engine.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { EnumLanguageTranslation } from './types';
|
|
|
5
5
|
/**
|
|
6
6
|
* Internationalization engine class
|
|
7
7
|
*/
|
|
8
|
-
export declare class I18nEngine<TStringKey extends string, TLanguage extends string, TConstants extends Record<string, any> = Record<string, any>,
|
|
8
|
+
export declare class I18nEngine<TStringKey extends string, TLanguage extends string, TConstants extends Record<string, any> = Record<string, any>, TContext extends I18nContext<TLanguage> = I18nContext<TLanguage>> {
|
|
9
9
|
/**
|
|
10
10
|
* Registry for enum translations
|
|
11
11
|
*/
|
|
@@ -13,7 +13,7 @@ export declare class I18nEngine<TStringKey extends string, TLanguage extends str
|
|
|
13
13
|
/**
|
|
14
14
|
* Configuration for the i18n engine
|
|
15
15
|
*/
|
|
16
|
-
readonly config: I18nConfig<TStringKey, TLanguage, TConstants
|
|
16
|
+
readonly config: I18nConfig<TStringKey, TLanguage, TConstants>;
|
|
17
17
|
/**
|
|
18
18
|
* Static instances for semi-singleton pattern
|
|
19
19
|
*/
|
|
@@ -40,7 +40,7 @@ export declare class I18nEngine<TStringKey extends string, TLanguage extends str
|
|
|
40
40
|
* @param key Optional instance key for the semi-singleton pattern
|
|
41
41
|
* @throws Error if an instance with the same key already exists
|
|
42
42
|
*/
|
|
43
|
-
constructor(config: I18nConfig<TStringKey, TLanguage, TConstants
|
|
43
|
+
constructor(config: I18nConfig<TStringKey, TLanguage, TConstants>, key?: string, newContext?: () => TContext);
|
|
44
44
|
/**
|
|
45
45
|
* Gets an instance of the I18nEngine by key. If no key is provided, the default instance is returned.
|
|
46
46
|
* @param key The key of the instance to retrieve
|
|
@@ -83,6 +83,7 @@ export declare class PluginI18nEngine<TLanguages extends string> {
|
|
|
83
83
|
updateContext(updates: Partial<IActiveContext<TLanguages>>): void;
|
|
84
84
|
/**
|
|
85
85
|
* Get current language from global context
|
|
86
|
+
* Respects language context space (admin vs user)
|
|
86
87
|
*/
|
|
87
88
|
private getCurrentLanguage;
|
|
88
89
|
/**
|
|
@@ -220,10 +220,12 @@ class PluginI18nEngine {
|
|
|
220
220
|
}
|
|
221
221
|
/**
|
|
222
222
|
* Get current language from global context
|
|
223
|
+
* Respects language context space (admin vs user)
|
|
223
224
|
*/
|
|
224
225
|
getCurrentLanguage() {
|
|
225
226
|
const globalContext = global_active_context_1.GlobalActiveContext.getInstance();
|
|
226
|
-
|
|
227
|
+
const context = globalContext.getContext(this.contextKey);
|
|
228
|
+
return context.currentContext === 'admin' ? context.adminLanguage : context.language;
|
|
227
229
|
}
|
|
228
230
|
/**
|
|
229
231
|
* Set current language
|
package/dist/typed-error.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare abstract class TypedError<TEnum extends Record<string, string>, T
|
|
|
32
32
|
readonly reasonMap: CompleteReasonMap<TEnum, TStringKey>;
|
|
33
33
|
readonly language?: Language | undefined;
|
|
34
34
|
readonly otherVars?: Record<string, string | number> | undefined;
|
|
35
|
-
constructor(engine: I18nEngine<TStringKey, Language, Record<string, any
|
|
35
|
+
constructor(engine: I18nEngine<TStringKey, Language, Record<string, any>>, type: TEnum[keyof TEnum], reasonMap: CompleteReasonMap<TEnum, TStringKey>, language?: Language | undefined, otherVars?: Record<string, string | number> | undefined);
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Plugin-based TypedError that works with the new component registration system
|
package/dist/types.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { LanguageDefinition } from './language-definition';
|
|
|
4
4
|
/**
|
|
5
5
|
* Standard language context spaces
|
|
6
6
|
*/
|
|
7
|
-
export type LanguageContextSpace = 'admin' | 'user'
|
|
7
|
+
export type LanguageContextSpace = 'admin' | 'user';
|
|
8
8
|
/**
|
|
9
9
|
* Default currency code
|
|
10
10
|
*/
|
|
@@ -17,10 +17,6 @@ export declare const DefaultTimezone: string;
|
|
|
17
17
|
* Currency position type
|
|
18
18
|
*/
|
|
19
19
|
export type CurrencyPosition = 'prefix' | 'postfix' | 'infix';
|
|
20
|
-
/**
|
|
21
|
-
* Custom language context type
|
|
22
|
-
*/
|
|
23
|
-
export type CustomLanguageContext<T extends string = LanguageContextSpace> = T;
|
|
24
20
|
/**
|
|
25
21
|
* Collection of localized strings for a specific language
|
|
26
22
|
*/
|