@digitaldefiance/i18n-lib 1.0.10 → 1.0.12
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/context-manager.d.ts +11 -0
- package/dist/context-manager.js +42 -0
- package/dist/currency.d.ts +11 -0
- package/dist/currency.js +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context change management for i18n systems
|
|
3
|
+
*/
|
|
4
|
+
export type ContextChangeListener<T = any> = (property: string, oldValue: T, newValue: T) => void;
|
|
5
|
+
export declare class ContextManager<TContext extends Record<string, any>> {
|
|
6
|
+
private listeners;
|
|
7
|
+
addListener(listener: ContextChangeListener): void;
|
|
8
|
+
removeListener(listener: ContextChangeListener): void;
|
|
9
|
+
notifyChange<K extends keyof TContext>(property: K, oldValue: TContext[K], newValue: TContext[K]): void;
|
|
10
|
+
createProxy(context: TContext): TContext;
|
|
11
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Context change management for i18n systems
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ContextManager = void 0;
|
|
7
|
+
class ContextManager {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.listeners = [];
|
|
10
|
+
}
|
|
11
|
+
addListener(listener) {
|
|
12
|
+
this.listeners.push(listener);
|
|
13
|
+
}
|
|
14
|
+
removeListener(listener) {
|
|
15
|
+
const index = this.listeners.indexOf(listener);
|
|
16
|
+
if (index > -1) {
|
|
17
|
+
this.listeners.splice(index, 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
notifyChange(property, oldValue, newValue) {
|
|
21
|
+
this.listeners.forEach(listener => {
|
|
22
|
+
try {
|
|
23
|
+
listener(property, oldValue, newValue);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
console.error('Error in context change listener:', error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
createProxy(context) {
|
|
31
|
+
const manager = this;
|
|
32
|
+
return new Proxy(context, {
|
|
33
|
+
set(target, property, value) {
|
|
34
|
+
const oldValue = target[property];
|
|
35
|
+
target[property] = value;
|
|
36
|
+
manager.notifyChange(property, oldValue, value);
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.ContextManager = ContextManager;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Currency formatting utilities
|
|
3
|
+
*/
|
|
4
|
+
export type CurrencyPosition = 'prefix' | 'postfix' | 'infix';
|
|
5
|
+
export interface CurrencyFormat {
|
|
6
|
+
symbol: string;
|
|
7
|
+
position: CurrencyPosition;
|
|
8
|
+
groupSeparator: string;
|
|
9
|
+
decimalSeparator: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function getCurrencyFormat(locale: string, currencyCode: string): CurrencyFormat;
|
package/dist/currency.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Currency formatting utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getCurrencyFormat = getCurrencyFormat;
|
|
7
|
+
function getCurrencyFormat(locale, currencyCode) {
|
|
8
|
+
const formatter = new Intl.NumberFormat(locale, {
|
|
9
|
+
style: 'currency',
|
|
10
|
+
currency: currencyCode,
|
|
11
|
+
});
|
|
12
|
+
const parts = formatter.formatToParts(1234567.89);
|
|
13
|
+
const symbol = parts.find((part) => part.type === 'currency')?.value || '';
|
|
14
|
+
const symbolIndex = parts.findIndex((part) => part.type === 'currency');
|
|
15
|
+
const decimalIndex = parts.findIndex((part) => part.type === 'decimal');
|
|
16
|
+
const integerIndex = parts.findIndex((part) => part.type === 'integer');
|
|
17
|
+
let position;
|
|
18
|
+
if (decimalIndex === -1) {
|
|
19
|
+
// No decimal separator
|
|
20
|
+
if (symbolIndex < integerIndex) {
|
|
21
|
+
position = 'prefix';
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
position = 'postfix';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (symbolIndex < decimalIndex && symbolIndex < integerIndex) {
|
|
28
|
+
position = 'prefix';
|
|
29
|
+
}
|
|
30
|
+
else if (symbolIndex > decimalIndex) {
|
|
31
|
+
position = 'postfix';
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
position = 'infix';
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
symbol,
|
|
38
|
+
position,
|
|
39
|
+
groupSeparator: parts.find((part) => part.type === 'group')?.value || ',',
|
|
40
|
+
decimalSeparator: parts.find((part) => part.type === 'decimal')?.value || '.',
|
|
41
|
+
};
|
|
42
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,6 +21,8 @@ __exportStar(require("./enum-registry"), exports);
|
|
|
21
21
|
__exportStar(require("./context"), exports);
|
|
22
22
|
__exportStar(require("./utils"), exports);
|
|
23
23
|
__exportStar(require("./template"), exports);
|
|
24
|
+
__exportStar(require("./context-manager"), exports);
|
|
25
|
+
__exportStar(require("./currency"), exports);
|
|
24
26
|
// Re-export for convenience
|
|
25
27
|
var i18n_engine_1 = require("./i18n-engine");
|
|
26
28
|
Object.defineProperty(exports, "I18n", { enumerable: true, get: function () { return i18n_engine_1.I18nEngine; } });
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export type LanguageContext = 'admin' | 'user';
|
|
2
2
|
export type CustomLanguageContext<T extends string = LanguageContext> = T;
|
|
3
|
-
export type CurrencyPosition = 'prefix' | 'postfix' | 'infix';
|
|
4
3
|
export type StringsCollection<TStringKey extends string> = Partial<Record<TStringKey, string>>;
|
|
5
4
|
export type MasterStringsCollection<TStringKey extends string, TLanguage extends string> = Partial<Record<TLanguage, StringsCollection<TStringKey>>>;
|
|
6
5
|
export type LanguageCodeCollection<TLanguage extends string> = Partial<Record<TLanguage, string>>;
|