@digitaldefiance/i18n-lib 1.2.1 → 1.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/README.md +21 -0
- package/dist/i18n-engine.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/translation-engine.d.ts +8 -0
- package/dist/typed-error.d.ts +2 -6
- package/dist/typed-error.js +2 -2
- package/package.json +1 -1
- package/dist/core-language.d.ts +0 -13
- package/dist/core-language.js +0 -17
- package/dist/package.json +0 -52
- package/dist/registry-context.d.ts +0 -12
- package/dist/src/active-context.d.ts +0 -29
- package/dist/src/active-context.js +0 -2
- package/dist/src/context-manager.d.ts +0 -33
- package/dist/src/context-manager.js +0 -61
- package/dist/src/context.d.ts +0 -43
- package/dist/src/context.js +0 -69
- package/dist/src/currency-code.d.ts +0 -19
- package/dist/src/currency-code.js +0 -36
- package/dist/src/currency-format.d.ts +0 -10
- package/dist/src/currency-format.js +0 -2
- package/dist/src/currency.d.ts +0 -11
- package/dist/src/currency.js +0 -48
- package/dist/src/enum-registry.d.ts +0 -35
- package/dist/src/enum-registry.js +0 -67
- package/dist/src/i18n-engine.d.ts +0 -156
- package/dist/src/i18n-engine.js +0 -267
- package/dist/src/index.d.ts +0 -13
- package/dist/src/index.js +0 -32
- package/dist/src/template.d.ts +0 -12
- package/dist/src/template.js +0 -30
- package/dist/src/timezone.d.ts +0 -11
- package/dist/src/timezone.js +0 -22
- package/dist/src/types.d.ts +0 -78
- package/dist/src/types.js +0 -14
- package/dist/src/utils.d.ts +0 -41
- package/dist/src/utils.js +0 -85
- /package/dist/{registry-context.js → translation-engine.js} +0 -0
package/README.md
CHANGED
|
@@ -1059,6 +1059,27 @@ Part of the DigitalBurnbag project - a secure file sharing and automated protoco
|
|
|
1059
1059
|
|
|
1060
1060
|
## ChangeLog
|
|
1061
1061
|
|
|
1062
|
+
### Version 1.2.3
|
|
1063
|
+
|
|
1064
|
+
- Thu Oct 23 2025 18:50:00 GMT-0700 (Pacific Daylight Time)
|
|
1065
|
+
- Minor update to fix safeTranslate being private
|
|
1066
|
+
|
|
1067
|
+
### Version 1.2.2
|
|
1068
|
+
|
|
1069
|
+
- Thu Oct 23 2025 18:40:00 GMT-0700 (Pacific Daylight Time)
|
|
1070
|
+
|
|
1071
|
+
**i18n Library - TranslationEngine Interface Refactoring**
|
|
1072
|
+
|
|
1073
|
+
- Made `TranslationEngine` interface generic with `TStringKey` type parameter for improved type safety
|
|
1074
|
+
- Changed `translate` and `safeTranslate` methods from optional to required in `TranslationEngine` interface
|
|
1075
|
+
- Exported `TranslationEngine` from `typed-error.ts` for consistent usage across packages
|
|
1076
|
+
- Updated `TypedHandleableError` in ecies-lib to use generic `TranslationEngine<TStringKey>` instead of inline interface types
|
|
1077
|
+
- Updated test mocks to implement both required `translate` and `safeTranslate` methods
|
|
1078
|
+
|
|
1079
|
+
**Breaking Changes:**
|
|
1080
|
+
- Any code implementing `TranslationEngine` must now provide both `translate` and `safeTranslate` methods (previously optional)
|
|
1081
|
+
- `TranslationEngine` now requires explicit type parameter when used (e.g., `TranslationEngine<EciesStringKey>`)
|
|
1082
|
+
|
|
1062
1083
|
### Version 1.2.1
|
|
1063
1084
|
|
|
1064
1085
|
- Thu Oct 23 2025 15:10:00 GMT-0700 (Pacific Daylight Time)
|
package/dist/i18n-engine.d.ts
CHANGED
|
@@ -112,7 +112,7 @@ export declare class I18nEngine<TStringKey extends string, TLanguage extends str
|
|
|
112
112
|
* @param language The language to translate to
|
|
113
113
|
* @returns The translated string or the key if translation fails
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
safeTranslate(key: TStringKey, vars?: Record<string, string | number>, language?: TLanguage): string;
|
|
116
116
|
/**
|
|
117
117
|
* Retrieves the string for the given language and key, throwing an error if not found.
|
|
118
118
|
* @param language The language to get the string for
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export * from './plugin-i18n-engine';
|
|
|
32
32
|
export * from './registry-config';
|
|
33
33
|
export * from './registry-error';
|
|
34
34
|
export * from './registry-error-type';
|
|
35
|
+
export * from './translation-engine';
|
|
35
36
|
export * from './translation-request';
|
|
36
37
|
export * from './translation-response';
|
|
37
38
|
export { createCoreI18nEngine as createCoreI18n } from './core-i18n';
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ __exportStar(require("./plugin-i18n-engine"), exports);
|
|
|
51
51
|
__exportStar(require("./registry-config"), exports);
|
|
52
52
|
__exportStar(require("./registry-error"), exports);
|
|
53
53
|
__exportStar(require("./registry-error-type"), exports);
|
|
54
|
+
__exportStar(require("./translation-engine"), exports);
|
|
54
55
|
__exportStar(require("./translation-request"), exports);
|
|
55
56
|
__exportStar(require("./translation-response"), exports);
|
|
56
57
|
// Re-export for convenience
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal interface for translation engines
|
|
3
|
+
* Allows flexibility in what can be used as a translation engine
|
|
4
|
+
*/
|
|
5
|
+
export interface TranslationEngine<TStringKey extends string = string> {
|
|
6
|
+
translate: (key: TStringKey, vars?: Record<string, string | number>, lang?: any) => string;
|
|
7
|
+
safeTranslate: (key: TStringKey, vars?: Record<string, string | number>, lang?: any) => string;
|
|
8
|
+
}
|
package/dist/typed-error.d.ts
CHANGED
|
@@ -3,12 +3,8 @@ import { I18nEngine } from './i18n-engine';
|
|
|
3
3
|
import { CoreLanguageCode } from './core-i18n';
|
|
4
4
|
import { CoreStringKey } from './core-string-key';
|
|
5
5
|
import { PluginI18nEngine } from './plugin-i18n-engine';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export interface TranslationEngine {
|
|
10
|
-
safeTranslate(componentId: string, stringKey: string, variables?: Record<string, string | number>, language?: string): string;
|
|
11
|
-
}
|
|
6
|
+
import { TranslationEngine } from './translation-engine';
|
|
7
|
+
export { TranslationEngine };
|
|
12
8
|
/**
|
|
13
9
|
* Type constraint to ensure reasonMap has entries for all enum values
|
|
14
10
|
*/
|
package/dist/typed-error.js
CHANGED
|
@@ -32,7 +32,7 @@ class BaseTypedError extends Error {
|
|
|
32
32
|
let message;
|
|
33
33
|
if (key && engine) {
|
|
34
34
|
// Try to translate the error message using the engine
|
|
35
|
-
message = engine.safeTranslate(
|
|
35
|
+
message = engine.safeTranslate(key, variables, language);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
38
|
// Fallback to a basic English message
|
|
@@ -141,7 +141,7 @@ function createTranslatedError(engine, componentId, type, reasonMap, variables,
|
|
|
141
141
|
if (key && engine) {
|
|
142
142
|
try {
|
|
143
143
|
// Try to translate the error message using the engine
|
|
144
|
-
message = engine.safeTranslate(
|
|
144
|
+
message = engine.safeTranslate(key, variables, language);
|
|
145
145
|
}
|
|
146
146
|
catch (translationError) {
|
|
147
147
|
// Fallback if translation fails
|
package/package.json
CHANGED
package/dist/core-language.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default languages supported by the core I18n system
|
|
3
|
-
*/
|
|
4
|
-
export declare enum CoreLanguage {
|
|
5
|
-
EnglishUS = "en-US",
|
|
6
|
-
EnglishUK = "en-UK",
|
|
7
|
-
French = "fr",
|
|
8
|
-
Spanish = "es",
|
|
9
|
-
German = "de",
|
|
10
|
-
MandarinChinese = "zh-CN",
|
|
11
|
-
Japanese = "ja",
|
|
12
|
-
Ukrainian = "uk"
|
|
13
|
-
}
|
package/dist/core-language.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CoreLanguage = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Default languages supported by the core I18n system
|
|
6
|
-
*/
|
|
7
|
-
var CoreLanguage;
|
|
8
|
-
(function (CoreLanguage) {
|
|
9
|
-
CoreLanguage["EnglishUS"] = "en-US";
|
|
10
|
-
CoreLanguage["EnglishUK"] = "en-UK";
|
|
11
|
-
CoreLanguage["French"] = "fr";
|
|
12
|
-
CoreLanguage["Spanish"] = "es";
|
|
13
|
-
CoreLanguage["German"] = "de";
|
|
14
|
-
CoreLanguage["MandarinChinese"] = "zh-CN";
|
|
15
|
-
CoreLanguage["Japanese"] = "ja";
|
|
16
|
-
CoreLanguage["Ukrainian"] = "uk";
|
|
17
|
-
})(CoreLanguage || (exports.CoreLanguage = CoreLanguage = {}));
|
package/dist/package.json
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@digitaldefiance/i18n-lib",
|
|
3
|
-
"version": "1.0.23",
|
|
4
|
-
"description": "Generic i18n library with enum translation support",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "yarn tsc",
|
|
9
|
-
"test": "yarn jest --detectOpenHandles",
|
|
10
|
-
"lint": "eslint src/**/*.ts tests/**/*.ts",
|
|
11
|
-
"lint:fix": "eslint src/**/*.ts tests/**/*.ts --fix",
|
|
12
|
-
"prettier:check": "prettier --check 'src/**/*.{ts,tsx}' 'tests/**/*.{ts,tsx}'",
|
|
13
|
-
"prettier:fix": "prettier --write 'src/**/*.{ts,tsx}' 'tests/**/*.{ts,tsx}'",
|
|
14
|
-
"format": "yarn prettier:fix && yarn lint:fix",
|
|
15
|
-
"prepublishOnly": "yarn build",
|
|
16
|
-
"publish:public": "npm publish --access public"
|
|
17
|
-
},
|
|
18
|
-
"devDependencies": {
|
|
19
|
-
"@types/jest": "^29.0.0",
|
|
20
|
-
"@typescript-eslint/eslint-plugin": "^8.31.1",
|
|
21
|
-
"@typescript-eslint/parser": "^8.31.1",
|
|
22
|
-
"eslint": "^9.8.0",
|
|
23
|
-
"eslint-config-prettier": "^10.1.2",
|
|
24
|
-
"eslint-plugin-import": "^2.32.0",
|
|
25
|
-
"eslint-plugin-prettier": "^5.3.1",
|
|
26
|
-
"jest": "^29.0.0",
|
|
27
|
-
"jest-util": "^30.0.5",
|
|
28
|
-
"prettier": "^2.6.2",
|
|
29
|
-
"prettier-plugin-organize-imports": "^4.1.0",
|
|
30
|
-
"ts-jest": "^29.0.0",
|
|
31
|
-
"typescript": "^5.9.2"
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"dist",
|
|
35
|
-
"README.md"
|
|
36
|
-
],
|
|
37
|
-
"keywords": [
|
|
38
|
-
"i18n",
|
|
39
|
-
"internationalization",
|
|
40
|
-
"typescript",
|
|
41
|
-
"enum",
|
|
42
|
-
"translation"
|
|
43
|
-
],
|
|
44
|
-
"author": "Digital Defiance",
|
|
45
|
-
"license": "MIT",
|
|
46
|
-
"packageManager": "yarn@4.10.3",
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"moment": "^2.30.1",
|
|
49
|
-
"moment-timezone": "^0.6.0"
|
|
50
|
-
},
|
|
51
|
-
"type": "commonjs"
|
|
52
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CurrencyCode } from './currency-code';
|
|
2
|
-
import { Timezone } from './timezone';
|
|
3
|
-
/**
|
|
4
|
-
* Translation context similar to existing I18nContext
|
|
5
|
-
*/
|
|
6
|
-
export interface RegistryContext<TLanguages extends string> {
|
|
7
|
-
currentLanguage: TLanguages;
|
|
8
|
-
fallbackLanguage: TLanguages;
|
|
9
|
-
currencyCode: CurrencyCode;
|
|
10
|
-
timezone: Timezone;
|
|
11
|
-
adminTimezone: Timezone;
|
|
12
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { LanguageContext } from './types';
|
|
2
|
-
import { Timezone } from './timezone';
|
|
3
|
-
import { CurrencyCode } from './currency-code';
|
|
4
|
-
export interface IActiveContext<TLanguage extends string> {
|
|
5
|
-
/**
|
|
6
|
-
* The default language for the user facing application
|
|
7
|
-
*/
|
|
8
|
-
language: TLanguage;
|
|
9
|
-
/**
|
|
10
|
-
* The default language for the admin interface
|
|
11
|
-
*/
|
|
12
|
-
adminLanguage: TLanguage;
|
|
13
|
-
/**
|
|
14
|
-
* The default currency code for the user facing application
|
|
15
|
-
*/
|
|
16
|
-
currencyCode: CurrencyCode;
|
|
17
|
-
/**
|
|
18
|
-
* The default language context for the current context
|
|
19
|
-
*/
|
|
20
|
-
currentContext: LanguageContext;
|
|
21
|
-
/**
|
|
22
|
-
* The default timezone for the user facing application
|
|
23
|
-
*/
|
|
24
|
-
timezone: Timezone;
|
|
25
|
-
/**
|
|
26
|
-
* The default timezone for the admin interface
|
|
27
|
-
*/
|
|
28
|
-
adminTimezone: Timezone;
|
|
29
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context change management for i18n systems
|
|
3
|
-
*/
|
|
4
|
-
export type ContextChangeListener<T = any> = (property: string, oldValue: T, newValue: T) => void;
|
|
5
|
-
/**
|
|
6
|
-
* Manages context changes and notifies listeners.
|
|
7
|
-
*/
|
|
8
|
-
export declare class ContextManager<TContext extends Record<string, any>> {
|
|
9
|
-
protected listeners: ContextChangeListener[];
|
|
10
|
-
/**
|
|
11
|
-
* Adds a listener to be notified of context changes.
|
|
12
|
-
* @param listener - The listener function to add
|
|
13
|
-
*/
|
|
14
|
-
addListener(listener: ContextChangeListener): void;
|
|
15
|
-
/**
|
|
16
|
-
* Removes a listener from the notification list.
|
|
17
|
-
* @param listener - The listener function to remove
|
|
18
|
-
*/
|
|
19
|
-
removeListener(listener: ContextChangeListener): void;
|
|
20
|
-
/**
|
|
21
|
-
* Notifies all listeners of a context change.
|
|
22
|
-
* @param property - The property that changed
|
|
23
|
-
* @param oldValue - The old value of the property
|
|
24
|
-
* @param newValue - The new value of the property
|
|
25
|
-
*/
|
|
26
|
-
notifyChange<K extends keyof TContext>(property: K, oldValue: TContext[K], newValue: TContext[K]): void;
|
|
27
|
-
/**
|
|
28
|
-
* Creates a proxy for the given context to automatically notify listeners on changes.
|
|
29
|
-
* @param context - The context object to proxy
|
|
30
|
-
* @returns A proxied version of the context object
|
|
31
|
-
*/
|
|
32
|
-
createProxy(context: TContext): TContext;
|
|
33
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ContextManager = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Manages context changes and notifies listeners.
|
|
6
|
-
*/
|
|
7
|
-
class ContextManager {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.listeners = [];
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Adds a listener to be notified of context changes.
|
|
13
|
-
* @param listener - The listener function to add
|
|
14
|
-
*/
|
|
15
|
-
addListener(listener) {
|
|
16
|
-
this.listeners.push(listener);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Removes a listener from the notification list.
|
|
20
|
-
* @param listener - The listener function to remove
|
|
21
|
-
*/
|
|
22
|
-
removeListener(listener) {
|
|
23
|
-
const index = this.listeners.indexOf(listener);
|
|
24
|
-
if (index > -1) {
|
|
25
|
-
this.listeners.splice(index, 1);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Notifies all listeners of a context change.
|
|
30
|
-
* @param property - The property that changed
|
|
31
|
-
* @param oldValue - The old value of the property
|
|
32
|
-
* @param newValue - The new value of the property
|
|
33
|
-
*/
|
|
34
|
-
notifyChange(property, oldValue, newValue) {
|
|
35
|
-
this.listeners.forEach((listener) => {
|
|
36
|
-
try {
|
|
37
|
-
listener(property, oldValue, newValue);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.error('Error in context change listener:', error);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates a proxy for the given context to automatically notify listeners on changes.
|
|
46
|
-
* @param context - The context object to proxy
|
|
47
|
-
* @returns A proxied version of the context object
|
|
48
|
-
*/
|
|
49
|
-
createProxy(context) {
|
|
50
|
-
const manager = this;
|
|
51
|
-
return new Proxy(context, {
|
|
52
|
-
set(target, property, value) {
|
|
53
|
-
const oldValue = target[property];
|
|
54
|
-
target[property] = value;
|
|
55
|
-
manager.notifyChange(property, oldValue, value);
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.ContextManager = ContextManager;
|
package/dist/src/context.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { CurrencyCode } from './currency-code';
|
|
2
|
-
import { Timezone } from './timezone';
|
|
3
|
-
import { I18nContext, LanguageContext } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a new I18n context with default values.
|
|
6
|
-
* @param defaultLanguage - The default language for the context
|
|
7
|
-
* @param defaultContext - The default language context
|
|
8
|
-
* @param defaultCurrencyCode - The default currency code (defaults to USD)
|
|
9
|
-
* @param defaultTimezone - The default timezone (defaults to UTC)
|
|
10
|
-
* @param defaultAdminTimezone - The default admin timezone (defaults to UTC)
|
|
11
|
-
* @returns A new I18nContext instance
|
|
12
|
-
*/
|
|
13
|
-
export declare function createContext<TLanguage extends string, TTranslationContext extends string = LanguageContext, TContext extends I18nContext<TLanguage, TTranslationContext> = I18nContext<TLanguage, TTranslationContext>>(defaultLanguage: TLanguage, defaultContext: TTranslationContext, defaultCurrencyCode?: CurrencyCode, defaultTimezone?: Timezone, defaultAdminTimezone?: Timezone): TContext;
|
|
14
|
-
/**
|
|
15
|
-
* Sets the language for the given I18n context.
|
|
16
|
-
* @param context - The I18n context to modify
|
|
17
|
-
* @param language - The language to set
|
|
18
|
-
*/
|
|
19
|
-
export declare function setLanguage<TLanguage extends string, TContext extends string = LanguageContext>(context: I18nContext<TLanguage, TContext>, language: TLanguage): void;
|
|
20
|
-
/**
|
|
21
|
-
* Sets the admin language for the given I18n context.
|
|
22
|
-
* @param context - The I18n context to modify
|
|
23
|
-
* @param language - The admin language to set
|
|
24
|
-
*/
|
|
25
|
-
export declare function setAdminLanguage<TLanguage extends string, TContext extends string = LanguageContext>(context: I18nContext<TLanguage, TContext>, language: TLanguage): void;
|
|
26
|
-
/**
|
|
27
|
-
* Sets the current context for the given I18n context.
|
|
28
|
-
* @param context - The I18n context to modify
|
|
29
|
-
* @param languageContext - The language context to set
|
|
30
|
-
*/
|
|
31
|
-
export declare function setContext<TLanguage extends string, TContext extends string = LanguageContext>(context: I18nContext<TLanguage, TContext>, languageContext: TContext): void;
|
|
32
|
-
/**
|
|
33
|
-
* Sets the timezone for the given I18n context.
|
|
34
|
-
* @param context - The I18n context to modify
|
|
35
|
-
* @param timezone - The timezone to set
|
|
36
|
-
*/
|
|
37
|
-
export declare function setTimezone<TLanguage extends string, TContext extends string = LanguageContext>(context: I18nContext<TLanguage, TContext>, timezone: Timezone): void;
|
|
38
|
-
/**
|
|
39
|
-
* Sets the admin timezone for the given I18n context.
|
|
40
|
-
* @param context - The I18n context to modify
|
|
41
|
-
* @param timezone - The admin timezone to set
|
|
42
|
-
*/
|
|
43
|
-
export declare function setAdminTimezone<TLanguage extends string, TContext extends string = LanguageContext>(context: I18nContext<TLanguage, TContext>, timezone: Timezone): void;
|
package/dist/src/context.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createContext = createContext;
|
|
4
|
-
exports.setLanguage = setLanguage;
|
|
5
|
-
exports.setAdminLanguage = setAdminLanguage;
|
|
6
|
-
exports.setContext = setContext;
|
|
7
|
-
exports.setTimezone = setTimezone;
|
|
8
|
-
exports.setAdminTimezone = setAdminTimezone;
|
|
9
|
-
const currency_code_1 = require("./currency-code");
|
|
10
|
-
const timezone_1 = require("./timezone");
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new I18n context with default values.
|
|
13
|
-
* @param defaultLanguage - The default language for the context
|
|
14
|
-
* @param defaultContext - The default language context
|
|
15
|
-
* @param defaultCurrencyCode - The default currency code (defaults to USD)
|
|
16
|
-
* @param defaultTimezone - The default timezone (defaults to UTC)
|
|
17
|
-
* @param defaultAdminTimezone - The default admin timezone (defaults to UTC)
|
|
18
|
-
* @returns A new I18nContext instance
|
|
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')) {
|
|
21
|
-
return {
|
|
22
|
-
language: defaultLanguage,
|
|
23
|
-
adminLanguage: defaultLanguage,
|
|
24
|
-
currencyCode: defaultCurrencyCode,
|
|
25
|
-
currentContext: defaultContext,
|
|
26
|
-
timezone: defaultTimezone,
|
|
27
|
-
adminTimezone: defaultAdminTimezone,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Sets the language for the given I18n context.
|
|
32
|
-
* @param context - The I18n context to modify
|
|
33
|
-
* @param language - The language to set
|
|
34
|
-
*/
|
|
35
|
-
function setLanguage(context, language) {
|
|
36
|
-
context.language = language;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Sets the admin language for the given I18n context.
|
|
40
|
-
* @param context - The I18n context to modify
|
|
41
|
-
* @param language - The admin language to set
|
|
42
|
-
*/
|
|
43
|
-
function setAdminLanguage(context, language) {
|
|
44
|
-
context.adminLanguage = language;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Sets the current context for the given I18n context.
|
|
48
|
-
* @param context - The I18n context to modify
|
|
49
|
-
* @param languageContext - The language context to set
|
|
50
|
-
*/
|
|
51
|
-
function setContext(context, languageContext) {
|
|
52
|
-
context.currentContext = languageContext;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Sets the timezone for the given I18n context.
|
|
56
|
-
* @param context - The I18n context to modify
|
|
57
|
-
* @param timezone - The timezone to set
|
|
58
|
-
*/
|
|
59
|
-
function setTimezone(context, timezone) {
|
|
60
|
-
context.timezone = timezone;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Sets the admin timezone for the given I18n context.
|
|
64
|
-
* @param context - The I18n context to modify
|
|
65
|
-
* @param timezone - The admin timezone to set
|
|
66
|
-
*/
|
|
67
|
-
function setAdminTimezone(context, timezone) {
|
|
68
|
-
context.adminTimezone = timezone;
|
|
69
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Class representing a validated currency code.
|
|
3
|
-
*/
|
|
4
|
-
export declare class CurrencyCode {
|
|
5
|
-
private _value;
|
|
6
|
-
/**
|
|
7
|
-
* Gets the currency code value.
|
|
8
|
-
*/
|
|
9
|
-
get value(): string;
|
|
10
|
-
/**
|
|
11
|
-
* Sets the currency code value after validating it.
|
|
12
|
-
*/
|
|
13
|
-
set value(value: string);
|
|
14
|
-
/**
|
|
15
|
-
* Gets the list of all valid currency codes.
|
|
16
|
-
*/
|
|
17
|
-
static get values(): string[];
|
|
18
|
-
constructor(value?: string);
|
|
19
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CurrencyCode = void 0;
|
|
4
|
-
const currency_codes_1 = require("currency-codes");
|
|
5
|
-
const types_1 = require("./types");
|
|
6
|
-
/**
|
|
7
|
-
* Class representing a validated currency code.
|
|
8
|
-
*/
|
|
9
|
-
class CurrencyCode {
|
|
10
|
-
/**
|
|
11
|
-
* Gets the currency code value.
|
|
12
|
-
*/
|
|
13
|
-
get value() {
|
|
14
|
-
return this._value;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Sets the currency code value after validating it.
|
|
18
|
-
*/
|
|
19
|
-
set value(value) {
|
|
20
|
-
if (!CurrencyCode.values.includes(value)) {
|
|
21
|
-
throw new Error('Invalid currency code');
|
|
22
|
-
}
|
|
23
|
-
this._value = value;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Gets the list of all valid currency codes.
|
|
27
|
-
*/
|
|
28
|
-
static get values() {
|
|
29
|
-
return (0, currency_codes_1.codes)();
|
|
30
|
-
}
|
|
31
|
-
constructor(value = types_1.DefaultCurrencyCode) {
|
|
32
|
-
this._value = types_1.DefaultCurrencyCode;
|
|
33
|
-
this.value = value;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.CurrencyCode = CurrencyCode;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CurrencyPosition } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Represents the format details for a specific currency in a given locale.
|
|
4
|
-
*/
|
|
5
|
-
export interface CurrencyFormat {
|
|
6
|
-
symbol: string;
|
|
7
|
-
position: CurrencyPosition;
|
|
8
|
-
groupSeparator: string;
|
|
9
|
-
decimalSeparator: string;
|
|
10
|
-
}
|
package/dist/src/currency.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Currency formatting utilities
|
|
3
|
-
*/
|
|
4
|
-
import { CurrencyFormat } from './currency-format';
|
|
5
|
-
/**
|
|
6
|
-
* Get currency format details for a given locale and currency code.
|
|
7
|
-
* @param locale The locale string (e.g., 'en-US')
|
|
8
|
-
* @param currencyCode The ISO 4217 currency code (e.g., 'USD')
|
|
9
|
-
* @returns The currency format details
|
|
10
|
-
*/
|
|
11
|
-
export declare function getCurrencyFormat(locale: string, currencyCode: string): CurrencyFormat;
|
package/dist/src/currency.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Currency formatting utilities
|
|
4
|
-
*/
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCurrencyFormat = getCurrencyFormat;
|
|
7
|
-
/**
|
|
8
|
-
* Get currency format details for a given locale and currency code.
|
|
9
|
-
* @param locale The locale string (e.g., 'en-US')
|
|
10
|
-
* @param currencyCode The ISO 4217 currency code (e.g., 'USD')
|
|
11
|
-
* @returns The currency format details
|
|
12
|
-
*/
|
|
13
|
-
function getCurrencyFormat(locale, currencyCode) {
|
|
14
|
-
const formatter = new Intl.NumberFormat(locale, {
|
|
15
|
-
style: 'currency',
|
|
16
|
-
currency: currencyCode,
|
|
17
|
-
});
|
|
18
|
-
const parts = formatter.formatToParts(1234567.89);
|
|
19
|
-
const symbol = parts.find((part) => part.type === 'currency')?.value || '';
|
|
20
|
-
const symbolIndex = parts.findIndex((part) => part.type === 'currency');
|
|
21
|
-
const decimalIndex = parts.findIndex((part) => part.type === 'decimal');
|
|
22
|
-
const integerIndex = parts.findIndex((part) => part.type === 'integer');
|
|
23
|
-
let position;
|
|
24
|
-
if (decimalIndex === -1) {
|
|
25
|
-
// No decimal separator
|
|
26
|
-
if (symbolIndex < integerIndex) {
|
|
27
|
-
position = 'prefix';
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
position = 'postfix';
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
else if (symbolIndex < decimalIndex && symbolIndex < integerIndex) {
|
|
34
|
-
position = 'prefix';
|
|
35
|
-
}
|
|
36
|
-
else if (symbolIndex > decimalIndex) {
|
|
37
|
-
position = 'postfix';
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
position = 'infix';
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
symbol,
|
|
44
|
-
position,
|
|
45
|
-
groupSeparator: parts.find((part) => part.type === 'group')?.value || ',',
|
|
46
|
-
decimalSeparator: parts.find((part) => part.type === 'decimal')?.value || '.',
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { EnumLanguageTranslation } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Registry for managing enum translations across multiple languages.
|
|
4
|
-
*/
|
|
5
|
-
export declare class EnumTranslationRegistry<TLanguage extends string> {
|
|
6
|
-
protected translations: Map<any, Partial<{ [L in TLanguage]: import("./types").EnumTranslation<any>; }>>;
|
|
7
|
-
protected enumNames: WeakMap<any, string>;
|
|
8
|
-
/**
|
|
9
|
-
* Registers an enumeration with its translations and a name.
|
|
10
|
-
* @param enumObj The enumeration object
|
|
11
|
-
* @param translations The translations for the enumeration
|
|
12
|
-
* @param enumName The name of the enumeration
|
|
13
|
-
*/
|
|
14
|
-
register<TEnum extends string | number>(enumObj: Record<string, TEnum>, translations: EnumLanguageTranslation<TEnum, TLanguage>, enumName: string): void;
|
|
15
|
-
/**
|
|
16
|
-
* Translates a value from the given enumeration to the specified language.
|
|
17
|
-
* @param enumObj The enumeration object
|
|
18
|
-
* @param value The value to translate
|
|
19
|
-
* @param language The target language for translation
|
|
20
|
-
* @returns The translated string
|
|
21
|
-
*/
|
|
22
|
-
translate<TEnum extends string | number>(enumObj: Record<string, TEnum>, value: TEnum, language: TLanguage): string;
|
|
23
|
-
/**
|
|
24
|
-
* Gets the name of the enumeration.
|
|
25
|
-
* @param enumObj The enumeration object
|
|
26
|
-
* @returns The name of the enumeration
|
|
27
|
-
*/
|
|
28
|
-
private getEnumName;
|
|
29
|
-
/**
|
|
30
|
-
* Checks if the registry has translations for the given enumeration.
|
|
31
|
-
* @param enumObj The enumeration object
|
|
32
|
-
* @returns True if translations exist, false otherwise
|
|
33
|
-
*/
|
|
34
|
-
has(enumObj: any): boolean;
|
|
35
|
-
}
|