gt-i18n 0.8.2 → 0.8.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/CHANGELOG.md +10 -0
- package/dist/config/types.d.ts +15 -0
- package/dist/i18n-manager/lifecycle-hooks/createLifecycleCallbacks.d.ts +8 -0
- package/dist/i18n-manager/lifecycle-hooks/types.d.ts +68 -0
- package/dist/i18n-manager/translations-manager/Cache.d.ts +13 -5
- package/dist/i18n-manager/translations-manager/LocalesCache.d.ts +16 -4
- package/dist/i18n-manager/translations-manager/TranslationsCache.d.ts +10 -6
- package/dist/i18n-manager/types.d.ts +6 -3
- package/dist/index.cjs.min.cjs +1 -1
- package/dist/index.cjs.min.cjs.map +1 -1
- package/dist/index.esm.min.mjs +1 -1
- package/dist/index.esm.min.mjs.map +1 -1
- package/dist/internal-types.d.ts +68 -8
- package/dist/internal.cjs.min.cjs +1 -1
- package/dist/internal.cjs.min.cjs.map +1 -1
- package/dist/internal.d.ts +95 -5
- package/dist/internal.esm.min.mjs +1 -1
- package/dist/internal.esm.min.mjs.map +1 -1
- package/dist/translation-functions/internal/index.d.ts +1 -0
- package/dist/translation-functions/types/options.d.ts +2 -0
- package/dist/types.d.ts +2 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# gt-i18n
|
|
2
2
|
|
|
3
|
+
## 0.8.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1218](https://github.com/generaltranslation/gt/pull/1218) [`02ef6fc`](https://github.com/generaltranslation/gt/commit/02ef6fcbd979247b9157e768e5a07b3285aaa6ec) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat(react/browser): dev hot reload
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`02ef6fc`](https://github.com/generaltranslation/gt/commit/02ef6fcbd979247b9157e768e5a07b3285aaa6ec)]:
|
|
10
|
+
- generaltranslation@8.2.5
|
|
11
|
+
- @generaltranslation/supported-locales@2.0.63
|
|
12
|
+
|
|
3
13
|
## 0.8.2
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/config/types.d.ts
CHANGED
|
@@ -36,4 +36,19 @@ export type GTConfig = {
|
|
|
36
36
|
runtimeUrl?: string | null;
|
|
37
37
|
modelProvider?: string;
|
|
38
38
|
localeCookieName?: string;
|
|
39
|
+
files?: {
|
|
40
|
+
gt?: {
|
|
41
|
+
parsingFlags?: {
|
|
42
|
+
/**
|
|
43
|
+
* Dev hot reload config, gt-react/browser only.
|
|
44
|
+
* - `true` enables strings hot reload (jsx handled at runtime via Suspense)
|
|
45
|
+
* - `{ strings?: boolean; jsx?: boolean }` enables selectively
|
|
46
|
+
*/
|
|
47
|
+
devHotReload?: boolean | {
|
|
48
|
+
strings?: boolean;
|
|
49
|
+
jsx?: boolean;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
39
54
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Translation } from '../translations-manager/utils/types/translation-data';
|
|
2
|
+
import type { LifecycleCallbacks, LocalesCacheLifecycleCallbacks } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Maps consumer-facing lifecycle callbacks to internal locales cache lifecycle callbacks.
|
|
5
|
+
* The consumer API exposes simplified params (locale, hash, value) while the internal
|
|
6
|
+
* API uses the full cache lifecycle params (inputKey, cacheKey, cacheValue, outputValue).
|
|
7
|
+
*/
|
|
8
|
+
export declare function createLifecycleCallbacks<TranslationValue extends Translation>({ onLocalesCacheHit, onLocalesCacheMiss, onTranslationsCacheHit, onTranslationsCacheMiss, }: LifecycleCallbacks<TranslationValue>): LocalesCacheLifecycleCallbacks<TranslationValue>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Translation } from '../translations-manager/utils/types/translation-data';
|
|
2
|
+
import type { TranslationKey, Hash } from '../translations-manager/TranslationsCache';
|
|
3
|
+
import type { Locale, CacheEntry } from '../translations-manager/LocalesCache';
|
|
4
|
+
/**
|
|
5
|
+
* Lifecycle callback
|
|
6
|
+
*/
|
|
7
|
+
export type LifecycleCallback<InputKey, CacheKey, CacheValue, OutputValue> = (params: {
|
|
8
|
+
inputKey: InputKey;
|
|
9
|
+
cacheKey: CacheKey;
|
|
10
|
+
cacheValue: CacheValue;
|
|
11
|
+
outputValue: OutputValue;
|
|
12
|
+
}) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Lifecycle param for the Cache constructor
|
|
15
|
+
*/
|
|
16
|
+
export type LifecycleParam<InputKey, CacheKey, CacheValue, OutputValue> = {
|
|
17
|
+
onHit?: LifecycleCallback<InputKey, CacheKey, CacheValue, OutputValue>;
|
|
18
|
+
onMiss?: LifecycleCallback<InputKey, CacheKey, CacheValue, OutputValue>;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Locales cache lifecycle callback
|
|
22
|
+
*/
|
|
23
|
+
export type LocalesCacheLifecycleCallback<TranslationValue extends Translation> = LifecycleCallback<Locale, Locale, CacheEntry<TranslationValue>, CacheEntry<TranslationValue>['translationsCache']>;
|
|
24
|
+
/**
|
|
25
|
+
* Translations cache lifecycle callback with locale embedded as first param.
|
|
26
|
+
* Uses base Translation type to avoid generic variance issues.
|
|
27
|
+
*/
|
|
28
|
+
export type TranslationsCacheLifecycleCallback<TranslationValue extends Translation> = (params: {
|
|
29
|
+
locale: Locale;
|
|
30
|
+
inputKey: TranslationKey<TranslationValue>;
|
|
31
|
+
cacheKey: Hash;
|
|
32
|
+
cacheValue: TranslationValue;
|
|
33
|
+
outputValue: TranslationValue;
|
|
34
|
+
}) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Combined locales cache lifecycle callbacks
|
|
37
|
+
*/
|
|
38
|
+
export type LocalesCacheLifecycleCallbacks<TranslationValue extends Translation> = {
|
|
39
|
+
onLocalesCacheHit?: LocalesCacheLifecycleCallback<TranslationValue>;
|
|
40
|
+
onLocalesCacheMiss?: LocalesCacheLifecycleCallback<TranslationValue>;
|
|
41
|
+
onTranslationsCacheHit?: TranslationsCacheLifecycleCallback<TranslationValue>;
|
|
42
|
+
onTranslationsCacheMiss?: TranslationsCacheLifecycleCallback<TranslationValue>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Simplified lifecycle callbacks for I18nManager consumers.
|
|
46
|
+
* These provide a cleaner interface than the internal cache lifecycle types,
|
|
47
|
+
* with locale and hash exposed directly instead of the full cache internals.
|
|
48
|
+
*/
|
|
49
|
+
export type LifecycleCallbacks<TranslationValue extends Translation> = {
|
|
50
|
+
onTranslationsCacheHit?: (params: {
|
|
51
|
+
locale: Locale;
|
|
52
|
+
hash: Hash;
|
|
53
|
+
value: TranslationValue;
|
|
54
|
+
}) => void;
|
|
55
|
+
onTranslationsCacheMiss?: (params: {
|
|
56
|
+
locale: Locale;
|
|
57
|
+
hash: Hash;
|
|
58
|
+
value: TranslationValue;
|
|
59
|
+
}) => void;
|
|
60
|
+
onLocalesCacheHit?: (params: {
|
|
61
|
+
locale: Locale;
|
|
62
|
+
value: Record<Hash, TranslationValue>;
|
|
63
|
+
}) => void;
|
|
64
|
+
onLocalesCacheMiss?: (params: {
|
|
65
|
+
locale: Locale;
|
|
66
|
+
value: Record<Hash, TranslationValue>;
|
|
67
|
+
}) => void;
|
|
68
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { LifecycleCallback, LifecycleParam } from '../lifecycle-hooks/types';
|
|
1
2
|
/**
|
|
2
3
|
* Cache class
|
|
3
4
|
* This is designed in such a way that it is the responsibility of the client
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
*
|
|
6
7
|
* TODO: maybe add "OutputValue" as a reflection of "InputKey"
|
|
7
8
|
*/
|
|
8
|
-
declare abstract class Cache<InputKey, CacheKey extends string, CacheValue> {
|
|
9
|
+
declare abstract class Cache<InputKey, CacheKey extends string, CacheValue, OutputValue extends unknown> {
|
|
9
10
|
/**
|
|
10
11
|
* Cache of items
|
|
11
12
|
*/
|
|
@@ -14,12 +15,20 @@ declare abstract class Cache<InputKey, CacheKey extends string, CacheValue> {
|
|
|
14
15
|
* Promise cache for inflight fallbacks
|
|
15
16
|
*/
|
|
16
17
|
private fallbackPromises;
|
|
18
|
+
/**
|
|
19
|
+
* Lifecycle callbacks - invoked in implementation of the abstract methods
|
|
20
|
+
* - onHit: invoked when a cache hit occurs
|
|
21
|
+
* - onMiss: invoked when a cache miss occurs
|
|
22
|
+
*/
|
|
23
|
+
protected onHit?: LifecycleCallback<InputKey, CacheKey, CacheValue, OutputValue>;
|
|
24
|
+
protected onMiss?: LifecycleCallback<InputKey, CacheKey, CacheValue, OutputValue>;
|
|
17
25
|
/**
|
|
18
26
|
* Constructor
|
|
19
27
|
* @param {Object} params - The parameters for the cache
|
|
20
28
|
* @param {Record<CacheKey, CacheValue>} params.init - The initial cache
|
|
29
|
+
* @param {CacheLifecycle} [lifecycle] - Optional lifecycle callbacks
|
|
21
30
|
*/
|
|
22
|
-
constructor(init: Record<CacheKey, CacheValue>);
|
|
31
|
+
constructor(init: Record<CacheKey, CacheValue>, lifecycle?: LifecycleParam<InputKey, CacheKey, CacheValue, OutputValue>);
|
|
23
32
|
/**
|
|
24
33
|
* Set the value for a key
|
|
25
34
|
*/
|
|
@@ -43,12 +52,11 @@ declare abstract class Cache<InputKey, CacheKey extends string, CacheValue> {
|
|
|
43
52
|
protected abstract fallback(key: InputKey): Promise<CacheValue>;
|
|
44
53
|
/**
|
|
45
54
|
* Lookup a value in the cache
|
|
46
|
-
* This abstract method allows for manipulation of the cache value before the return
|
|
47
55
|
*/
|
|
48
|
-
abstract get(key: InputKey):
|
|
56
|
+
abstract get(key: InputKey): OutputValue | undefined;
|
|
49
57
|
/**
|
|
50
58
|
* Miss the cache
|
|
51
59
|
*/
|
|
52
|
-
|
|
60
|
+
abstract miss(key: InputKey): Promise<OutputValue | undefined>;
|
|
53
61
|
}
|
|
54
62
|
export { Cache };
|
|
@@ -2,6 +2,7 @@ import { Cache } from './Cache';
|
|
|
2
2
|
import { Hash, TranslationsCache } from './TranslationsCache';
|
|
3
3
|
import { Translation } from './utils/types/translation-data';
|
|
4
4
|
import { CreateTranslateMany } from './utils/createTranslateMany';
|
|
5
|
+
import type { LocalesCacheLifecycleCallbacks } from '../lifecycle-hooks/types';
|
|
5
6
|
/**
|
|
6
7
|
* Just being explicit about the purpose of this type
|
|
7
8
|
*/
|
|
@@ -12,7 +13,7 @@ export type Locale = string;
|
|
|
12
13
|
* @property {number} expiresAt - The time at which the cache entry expires.
|
|
13
14
|
* @property {TranslationsCache<TranslationValue>} translationsCache - The translations cache for the locale.
|
|
14
15
|
*/
|
|
15
|
-
type CacheEntry<TranslationValue extends Translation> = {
|
|
16
|
+
export type CacheEntry<TranslationValue extends Translation> = {
|
|
16
17
|
expiresAt: number;
|
|
17
18
|
translationsCache: TranslationsCache<TranslationValue>;
|
|
18
19
|
};
|
|
@@ -25,7 +26,7 @@ export type SafeTranslationsLoader<TranslationValue extends Translation> = (loca
|
|
|
25
26
|
/**
|
|
26
27
|
* Cache for looking up translations by locale
|
|
27
28
|
*/
|
|
28
|
-
export declare class LocalesCache<TranslationValue extends Translation> extends Cache<Locale, Locale, CacheEntry<TranslationValue
|
|
29
|
+
export declare class LocalesCache<TranslationValue extends Translation> extends Cache<Locale, Locale, CacheEntry<TranslationValue>, CacheEntry<TranslationValue>['translationsCache']> {
|
|
29
30
|
/**
|
|
30
31
|
* Translation loader function
|
|
31
32
|
*/
|
|
@@ -38,6 +39,11 @@ export declare class LocalesCache<TranslationValue extends Translation> extends
|
|
|
38
39
|
* Time to live for cache entries
|
|
39
40
|
*/
|
|
40
41
|
private ttl;
|
|
42
|
+
/**
|
|
43
|
+
* Translations cache lifecycle callbacks (locale embedded)
|
|
44
|
+
*/
|
|
45
|
+
private _onTranslationsCacheHit?;
|
|
46
|
+
private _onTranslationsCacheMiss?;
|
|
41
47
|
/**
|
|
42
48
|
* Constructor
|
|
43
49
|
* @param {Object} params - The parameters for the cache
|
|
@@ -46,11 +52,12 @@ export declare class LocalesCache<TranslationValue extends Translation> extends
|
|
|
46
52
|
* @param {SafeTranslationsLoader<TranslationValue>} params.loadTranslations - The translation loader function
|
|
47
53
|
* @param {CreateTranslateMany} params.createTranslateMany - Factory function for creating a translate many function
|
|
48
54
|
*/
|
|
49
|
-
constructor({ init, ttl, loadTranslations, createTranslateMany, }: {
|
|
55
|
+
constructor({ init, ttl, loadTranslations, createTranslateMany, lifecycle: { onLocalesCacheHit: onHit, onLocalesCacheMiss: onMiss, onTranslationsCacheHit, onTranslationsCacheMiss, }, }: {
|
|
50
56
|
init?: Record<string, CacheEntry<TranslationValue>>;
|
|
51
57
|
ttl?: number | null;
|
|
52
58
|
createTranslateMany: CreateTranslateMany;
|
|
53
59
|
loadTranslations: SafeTranslationsLoader<TranslationValue>;
|
|
60
|
+
lifecycle: LocalesCacheLifecycleCallbacks<TranslationValue>;
|
|
54
61
|
});
|
|
55
62
|
/**
|
|
56
63
|
* Get the translations for a given locale
|
|
@@ -78,5 +85,10 @@ export declare class LocalesCache<TranslationValue extends Translation> extends
|
|
|
78
85
|
* @returns The cache entry
|
|
79
86
|
*/
|
|
80
87
|
protected fallback(locale: Locale): Promise<CacheEntry<TranslationValue>>;
|
|
88
|
+
/**
|
|
89
|
+
* Create the translations cache lifecycle
|
|
90
|
+
* @param locale - The locale
|
|
91
|
+
* @returns The translations cache lifecycle
|
|
92
|
+
*/
|
|
93
|
+
private _createTranslationsCacheLifecycle;
|
|
81
94
|
}
|
|
82
|
-
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LookupOptions } from '../../translation-functions/types/options';
|
|
2
2
|
import { Cache } from './Cache';
|
|
3
|
+
import type { LifecycleParam } from '../lifecycle-hooks/types';
|
|
3
4
|
import { Translation } from './utils/types/translation-data';
|
|
4
5
|
import type { GT } from 'generaltranslation';
|
|
5
6
|
/**
|
|
@@ -8,7 +9,7 @@ import type { GT } from 'generaltranslation';
|
|
|
8
9
|
* @property {TranslationValue} message - The message from the source
|
|
9
10
|
* @property {LookupOptions} options - The options for the translation
|
|
10
11
|
*/
|
|
11
|
-
type TranslationKey<TranslationValue extends Translation> = {
|
|
12
|
+
export type TranslationKey<TranslationValue extends Translation> = {
|
|
12
13
|
message: TranslationValue;
|
|
13
14
|
options: LookupOptions;
|
|
14
15
|
};
|
|
@@ -22,8 +23,13 @@ export type Hash = string;
|
|
|
22
23
|
export type TranslateMany = (sources: Parameters<GT['translateMany']>[0]) => ReturnType<GT['translateMany']>;
|
|
23
24
|
/**
|
|
24
25
|
* A cache for a single locale's translations
|
|
26
|
+
*
|
|
27
|
+
* Principles:
|
|
28
|
+
* - This class is language agnostic, and should never store the locale code as a parameter.
|
|
29
|
+
* Locale logic is handled at the LocalesCache level. Use a callback function that has the
|
|
30
|
+
* locale parameter embedded if you wish to use the locale code.
|
|
25
31
|
*/
|
|
26
|
-
export declare class TranslationsCache<TranslationValue extends Translation> extends Cache<TranslationKey<TranslationValue>, Hash, TranslationValue> {
|
|
32
|
+
export declare class TranslationsCache<TranslationValue extends Translation> extends Cache<TranslationKey<TranslationValue>, Hash, TranslationValue, TranslationValue> {
|
|
27
33
|
/**
|
|
28
34
|
* Queue of translation requests
|
|
29
35
|
*/
|
|
@@ -38,8 +44,6 @@ export declare class TranslationsCache<TranslationValue extends Translation> ext
|
|
|
38
44
|
private _activeRequests;
|
|
39
45
|
/**
|
|
40
46
|
* Translate many function
|
|
41
|
-
* TODO: omit the targetLocale requirement from the second argument, this can be supplied
|
|
42
|
-
* on instantiation
|
|
43
47
|
*/
|
|
44
48
|
private _translateMany;
|
|
45
49
|
/**
|
|
@@ -48,9 +52,10 @@ export declare class TranslationsCache<TranslationValue extends Translation> ext
|
|
|
48
52
|
* @param {Record<Hash, TranslationValue>} params.init - The initial cache
|
|
49
53
|
* @param {Function} params.fallback - Get the fallback value for a cache miss
|
|
50
54
|
*/
|
|
51
|
-
constructor({ init, translateMany, }: {
|
|
55
|
+
constructor({ init, translateMany, lifecycle, }: {
|
|
52
56
|
init: Record<Hash, TranslationValue>;
|
|
53
57
|
translateMany: TranslateMany;
|
|
58
|
+
lifecycle: LifecycleParam<TranslationKey<TranslationValue>, Hash, TranslationValue, TranslationValue>;
|
|
54
59
|
});
|
|
55
60
|
/**
|
|
56
61
|
* Get the translation value for a given key
|
|
@@ -108,4 +113,3 @@ export declare class TranslationsCache<TranslationValue extends Translation> ext
|
|
|
108
113
|
*/
|
|
109
114
|
private _handleTranslationResponse;
|
|
110
115
|
}
|
|
111
|
-
export {};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { StorageAdapterType } from './storage-adapter/types';
|
|
2
1
|
import { CustomMapping } from 'generaltranslation/types';
|
|
3
2
|
import { GTConfig } from '../config/types';
|
|
4
3
|
import { StorageAdapter } from './storage-adapter/StorageAdapter';
|
|
4
|
+
import { StorageAdapterType } from './storage-adapter/types';
|
|
5
5
|
import { TranslationsLoader } from './translations-manager/translations-loaders/types';
|
|
6
|
+
import { Translation } from './translations-manager/utils/types/translation-data';
|
|
7
|
+
import type { LifecycleCallbacks } from './lifecycle-hooks/types';
|
|
6
8
|
/**
|
|
7
9
|
* Parameters for the I18nManager constructor
|
|
8
10
|
*/
|
|
9
|
-
export type I18nManagerConstructorParams<T extends StorageAdapter = StorageAdapter> = GTConfig & {
|
|
11
|
+
export type I18nManagerConstructorParams<T extends StorageAdapter = StorageAdapter, TranslationValue extends Translation = Translation> = GTConfig & {
|
|
10
12
|
loadTranslations?: TranslationsLoader;
|
|
11
13
|
storeAdapter?: T;
|
|
12
14
|
environment?: 'development' | 'production';
|
|
15
|
+
lifecycle?: LifecycleCallbacks<TranslationValue>;
|
|
13
16
|
};
|
|
14
17
|
/**
|
|
15
18
|
* I18nManager class configuration
|
|
@@ -26,4 +29,4 @@ export type I18nManagerConfig = {
|
|
|
26
29
|
runtimeUrl?: string | null;
|
|
27
30
|
_versionId?: string;
|
|
28
31
|
};
|
|
29
|
-
export type { TranslationsLoader, StorageAdapter, StorageAdapterType };
|
|
32
|
+
export type { TranslationsLoader, StorageAdapter, StorageAdapterType, LifecycleCallbacks, };
|
package/dist/index.cjs.min.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("generaltranslation/internal"),e=require("generaltranslation"),r=require("generaltranslation/id"),n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},n(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var o=function(){return o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},o.apply(this,arguments)};function i(t,e,r,n){return new(r||(r=Promise))(function(a,o){function i(t){try{c(n.next(t))}catch(t){o(t)}}function s(t){try{c(n.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(i,s)}c((n=n.apply(t,e||[])).next())})}function s(t,e){var r,n,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(o=0)),o;)try{if(r=1,n&&(a=2&s[0]?n.return:s[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,s[1])).done)return a;switch(n=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,n=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],n=0}finally{r=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function c(t,e,r){if(r||2===arguments.length)for(var n,a=0,o=e.length;a<o;a++)!n&&a in e||(n||(n=Array.prototype.slice.call(e,0,a)),n[a]=e[a]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var l,u,h=function(t){console.warn(t)},f=function(t){console.error(t)};function p(e){return e.loadTranslations?l.CUSTOM:e.cacheUrl?l.REMOTE:void 0!==e.cacheUrl&&e.cacheUrl!==t.defaultCacheUrl||!e.projectId?l.DISABLED:l.GT_REMOTE}function d(e){return void 0!==e.runtimeUrl&&e.runtimeUrl!==t.defaultRuntimeApiUrl||!e.projectId||!e.devApiKey&&!e.apiKey?e.runtimeUrl?u.CUSTOM:u.DISABLED:u.GT}function v(t){return p(t)===l.GT_REMOTE||d(t)===u.GT}function g(t){var r=[];return r.push.apply(r,function(t){var e=[],r=t.projectId,n=t.loadTranslations;switch(p(t)){case l.REMOTE:case l.GT_REMOTE:r||e.push({type:"warning",message:"projectId is required when loading translations from a remote store"});break;case l.CUSTOM:n||e.push({type:"error",message:"loadTranslations is required when loading translations from a custom loader"});case l.DISABLED:}return e}(t)),r.push.apply(r,function(t){var e=[];switch(d(t)){case u.CUSTOM:case u.GT:t.projectId||e.push({type:"warning",message:"projectId is required"}),t.devApiKey||t.apiKey||e.push({type:"warning",message:"devApiKey or apiKey is required"});case u.DISABLED:}return e}(t)),r.push.apply(r,function(t){var r=[];if(!v(t))return r;var n=t.defaultLocale,a=t.locales,o=t.customMapping;return new Set(c(c([],n?[n]:[],!0),a||[],!0)).forEach(function(t){e.isValidLocale(t,o)||r.push({type:"error",message:"Invalid locale: ".concat(t)})}),r}(t)),r}!function(t){t.GT_REMOTE="gt-remote",t.REMOTE="remote",t.CUSTOM="custom",t.DISABLED="disabled"}(l||(l={})),function(t){t.GT="gt",t.CUSTOM="custom",t.DISABLED="disabled"}(u||(u={}));var y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="fallback-storage-adapter",e.storage={},e}return a(e,t),e.prototype.getItem=function(t){return this.storage[t]},e.prototype.setItem=function(t,e){this.storage[t]=e},e.prototype.removeItem=function(t){delete this.storage[t]},e}(function(){});function m(r){var n=this,a=function(e){var r=e.cacheUrl,n=void 0===r?t.defaultCacheUrl:r,a=e.projectId,o=e._versionId,i=e._branchId,s=o?"/".concat(o):"",c=i?"?branchId=".concat(i):"";return"".concat(n,"/").concat(a,"/[locale]")+s+c}(r);return function(t){return i(n,void 0,void 0,function(){var n,o;return s(this,function(i){switch(i.label){case 0:return t=e.resolveCanonicalLocale(t,r.customMapping),n=a.replace("[locale]",t),[4,fetch(n)];case 1:if(!(o=i.sent()).ok)throw new Error("Failed to load translations from ".concat(n));return[4,o.json()];case 2:return[2,i.sent()]}})})}}function b(t){var e=t.type,r=t.remoteTranslationLoaderParams,n=t.loadTranslations;e===l.DISABLED&&h("I18nManager: No translation loader found. No translations will be loaded.");var a=r.cacheUrl,o=r.projectId,c=r._versionId,u=r._branchId,f=r.customMapping;switch(e){case l.REMOTE:case l.GT_REMOTE:return m({cacheUrl:a||"",projectId:o||"",_versionId:c,_branchId:u,customMapping:f});case l.CUSTOM:return n;case l.DISABLED:return function(){var t=this;return function(e){return i(t,void 0,void 0,function(){return s(this,function(t){return[2,{}]})})}}()}}var T=function(){function t(t){this.cache={},this.fallbackPromises={},this.cache=structuredClone(t)}return t.prototype.setCache=function(t,e){this.cache[t]=e},t.prototype.getCache=function(t){var e=this.genKey(t);return this.cache[e]},t.prototype.getInternalCache=function(){return this.cache},t.prototype.missCache=function(t){return i(this,void 0,void 0,function(){var e,r,n;return s(this,function(a){switch(a.label){case 0:return e=this.genKey(t),void 0===this.fallbackPromises[e]?[3,2]:[4,this.fallbackPromises[e]];case 1:return[2,a.sent()];case 2:r=this.fallback(t),this.fallbackPromises[e]=r,a.label=3;case 3:return a.trys.push([3,,5,6]),[4,r];case 4:return n=a.sent(),this.cache[e]=n,[2,n];case 5:return delete this.fallbackPromises[e],[7];case 6:return[2]}})})},t}();function _(e,n){return r.hashSource(o(o(o(o({source:"ICU"===n.$format?t.indexVars(e):e},(null==n?void 0:n.$context)&&{context:n.$context}),(null==n?void 0:n.$id)&&{id:n.$id}),"$maxChars"in n&&null!=n.$maxChars&&{$maxChars:Math.abs(n.$maxChars)}),{dataFormat:n.$format}))}var L=function(t){function e(e){var r=e.init,n=e.translateMany,a=t.call(this,r)||this;return a._queue=[],a._batchTimer=null,a._activeRequests=0,a._translateMany=n,a}return a(e,t),e.prototype.get=function(t){return this.getCache(t)},e.prototype.miss=function(t){return this.missCache(t)},e.prototype.genKey=function(t){return _(t.message,t.options)},e.prototype.fallback=function(t){var e=this._enqueueTranslation(t);return this._queue.length>=25?this._flushNow():this._scheduleBatch(),e},e.prototype._flushNow=function(){this._batchTimer&&(clearTimeout(this._batchTimer),this._batchTimer=null),this._drainQueue()},e.prototype._scheduleBatch=function(){var t=this;this._batchTimer||(this._batchTimer=setTimeout(function(){t._batchTimer=null,t._drainQueue()},50))},e.prototype._drainQueue=function(){for(;this._queue.length>0&&this._activeRequests<100;){var t=this._queue.splice(0,25);this._sendBatchRequest(t)}this._queue.length>0&&this._scheduleBatch()},e.prototype._enqueueTranslation=function(t){var e=this,r=this.genKey(t),n=t.options;return new Promise(function(a,i){e._queue.push({key:r,source:t.message,metadata:o(o(o(o({},(null==n?void 0:n.$context)&&{context:n.$context}),(null==n?void 0:n.$id)&&{id:n.$id}),"$maxChars"in n&&null!=n.$maxChars&&{$maxChars:Math.abs(n.$maxChars)}),{dataFormat:n.$format}),resolve:function(t){return a(t)},reject:i})})},e.prototype._sendBatchRequest=function(t){return i(this,void 0,void 0,function(){var e,r;return s(this,function(n){switch(n.label){case 0:return this._activeRequests++,e=function(t){return t.reduce(function(t,e){return t[e.key]={source:e.source,metadata:e.metadata},t},{})}(t),[4,this._sendBatchRequestWithErrorHandling(t,e)];case 1:return(r=n.sent())&&this._handleTranslationResponse(t,r),this._activeRequests--,[2]}})})},e.prototype._sendBatchRequestWithErrorHandling=function(t,e){return i(this,void 0,void 0,function(){var r,n,a;return s(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this._translateMany(e)];case 1:return[2,o.sent()];case 2:for(r=o.sent(),n=0,a=t;n<a.length;n++)a[n].reject(r);return[2,void 0];case 3:return[2]}})})},e.prototype._handleTranslationResponse=function(t,e){for(var r=0,n=t;r<n.length;r++){var a=n[r],o=a.key,i=e[o];if(i&&i.success){var s=i.translation;this.setCache(o,s),a.resolve(s)}else a.reject(null==i?void 0:i.error)}},e}(T);var I=function(t){function e(e){var r=e.init,n=void 0===r?{}:r,a=e.ttl,o=e.loadTranslations,i=e.createTranslateMany,s=t.call(this,n)||this;return s.ttl=6e4,s.ttl=null===a?-1:null!=a?a:6e4,s._translationLoader=o,s._createTranslateMany=i,s}return a(e,t),e.prototype.get=function(t){var e=this.getCache(t);if(e&&!(e.expiresAt>0&&e.expiresAt<Date.now()))return e.translationsCache},e.prototype.miss=function(t){return i(this,void 0,void 0,function(){return s(this,function(e){switch(e.label){case 0:return[4,this.missCache(t)];case 1:return[2,e.sent().translationsCache]}})})},e.prototype.genKey=function(t){return t},e.prototype.fallback=function(t){return i(this,void 0,void 0,function(){var e,r,n,a,o;return s(this,function(i){switch(i.label){case 0:return e=this._translationLoader(t),r=this.ttl<0?this.ttl:Date.now()+this.ttl,a=L.bind,o={},[4,e];case 1:return n=new(a.apply(L,[void 0,(o.init=i.sent(),o.translateMany=this._createTranslateMany(t),o)])),[2,{translationsCache:n,expiresAt:r}]}})})},e}(T),C=function(){function r(r){var n,a,i,s,l=this;this.resolveTranslationSync=function(t,e){return l.lookupTranslation(t,e)},function(t,e,r){if(void 0===r&&(r=!0),t.forEach(function(t){switch(t.type){case"error":f(e+t.message);break;case"warning":h(e+t.message)}}),r&&t.some(function(t){return"error"===t.type}))throw new Error("Validation errors occurred")}(g(r),"I18nManager: "),this.config=(i=v(a=r),s=function(t){var e=t.defaultLocale,r=t.locales,n=t.customMapping;return{defaultLocale:e,locales:Array.from(new Set(c([e],r,!0))),customMapping:n||{}}}({defaultLocale:a.defaultLocale||t.libraryDefaultLocale,locales:a.locales||[t.libraryDefaultLocale],customMapping:a.customMapping}),o({environment:a.environment||"production",enableI18n:void 0===a.enableI18n||a.enableI18n,projectId:a.projectId,devApiKey:a.devApiKey,apiKey:a.apiKey,runtimeUrl:a.runtimeUrl,_versionId:a._versionId},i?function(t){var r=e.standardizeLocale(t.defaultLocale),n=t.locales.map(function(r){var n,a,o,i;return("string"==typeof(null===(n=t.customMapping)||void 0===n?void 0:n[r])?null===(a=t.customMapping)||void 0===a?void 0:a[r]:null===(i=null===(o=t.customMapping)||void 0===o?void 0:o[r])||void 0===i?void 0:i.code)?r:e.standardizeLocale(r)}),a=Object.fromEntries(Object.entries(t.customMapping||{}).map(function(t){var r=t[0],n=t[1];return[r,"string"==typeof n?e.standardizeLocale(n):o(o({},n),n.code?{code:e.standardizeLocale(n.code)}:{})]}));return{defaultLocale:r,locales:n,customMapping:a}}(s):s)),this.storeAdapter=null!==(n=r.storeAdapter)&&void 0!==n?n:new y;var u,d,m=function(t){return b({loadTranslations:t.loadTranslations,type:p(t),remoteTranslationLoaderParams:{cacheUrl:t.cacheUrl,projectId:t.projectId,_versionId:t._versionId,_branchId:t._branchId,customMapping:t.customMapping}})}(r),T=(u=this.getGTClassClean(),d=12e3,function(t){return function(e){return u.translateMany(e,{targetLocale:t},d)}});this.localesCache=new I({loadTranslations:m,createTranslateMany:T})}return r.prototype.getAdapterType=function(){return this.storeAdapter.type},r.prototype.getLocale=function(){var t=this.storeAdapter.getItem("locale");return t||(h("getLocale() invoked outside of translation context, falling back to default locale"),this.config.defaultLocale)},r.prototype.setLocale=function(t){try{this.validateLocale(t);var e=this.getGTClass();this.storeAdapter.setItem("locale",e.determineLocale(t))}catch(t){this.handleError(t)}},r.prototype.getDefaultLocale=function(){return this.config.defaultLocale},r.prototype.getLocales=function(){return this.config.locales},r.prototype.getVersionId=function(){return this.config._versionId},r.prototype.getGTClass=function(){return this.getGTClassClean(this.getLocale())},r.prototype.isTranslationEnabled=function(){return this.config.enableI18n},r.prototype.getTranslationLoader=function(){var t=this;return function(e){return t.loadTranslations(e)}},r.prototype.loadTranslations=function(){return i(this,arguments,void 0,function(t){var e,r;return void 0===t&&(t=this.getLocale()),s(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),this.validateLocale(t),this.requiresTranslation(t)?(e=this.localesCache.get(t))?[3,2]:[4,this.localesCache.miss(t)]:[2,{}];case 1:e=n.sent(),n.label=2;case 2:return[2,e.getInternalCache()];case 3:return r=n.sent(),this.handleError(r),[2,{}];case 4:return[2]}})})},r.prototype.lookupTranslation=function(t,e){var r;try{var n=null!==(r=e.$locale)&&void 0!==r?r:this.getLocale();if(this.validateLocale(n),!this.requiresTranslation(n))return t;var a=this.localesCache.get(n);if(!a)return;return a.get({message:t,options:e})}catch(t){return void this.handleError(t)}},r.prototype.lookupTranslationWithFallback=function(t,e){return i(this,void 0,void 0,function(){var r,n,a,o,i;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),r=null!==(i=e.$locale)&&void 0!==i?i:this.getLocale(),this.validateLocale(r),this.requiresTranslation(r)?(n=this.localesCache.get(r))?[3,2]:[4,this.localesCache.miss(r)]:[2,t];case 1:n=s.sent(),s.label=2;case 2:return null!=(a=n.get({message:t,options:e}))?[3,4]:[4,n.miss({message:t,options:e})];case 3:a=s.sent(),s.label=4;case 4:return[2,a];case 5:return o=s.sent(),this.handleError(o),[2,void 0];case 6:return[2]}})})},r.prototype.getLookupTranslation=function(){return i(this,arguments,void 0,function(t,e){var r,n,a;return void 0===t&&(t=this.getLocale()),void 0===e&&(e=[]),s(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),this.validateLocale(t),this.requiresTranslation(t)?(r=function(t,e){var r=t.filter(function(t){return null==t.options.$locale||t.options.$locale===e});return r}(e,t),r.length!==e.length&&h("I18nManager: getLookupTranslation(): prefetchEntries must all be the same locale, ignoring all entries that are not for ".concat(t)),(n=this.localesCache.get(t))?[3,2]:[4,this.localesCache.miss(t)]):[2,function(t){return t}];case 1:n=o.sent(),o.label=2;case 2:return n?[4,Promise.all(r.filter(function(t){return null==n.get(t)}).map(function(t){return n.miss(t)}))]:[2,function(){}];case 3:return o.sent(),[2,function(t,e){return n.get({message:t,options:e})}];case 4:return a=o.sent(),this.handleError(a),[2,function(t){return t}];case 5:return[2]}})})},r.prototype.getTranslations=function(){return i(this,arguments,void 0,function(t){return void 0===t&&(t=this.getLocale()),s(this,function(e){try{return this.validateLocale(t),[2,this.loadTranslations(t)]}catch(t){return this.handleError(t),[2,{}]}return[2]})})},r.prototype.getTranslationResolver=function(){return i(this,arguments,void 0,function(t){return void 0===t&&(t=this.getLocale()),s(this,function(e){return[2,this.getLookupTranslation(t)]})})},r.prototype.requiresTranslation=function(t){void 0===t&&(t=this.getLocale());var e=this.getDefaultLocale(),r=this.getGTClass(),n=this.getLocales();return this.isTranslationEnabled()&&r.requiresTranslation(e,t,n)},r.prototype.requiresDialectTranslation=function(t){void 0===t&&(t=this.getLocale());var e=this.getDefaultLocale(),r=this.getGTClass();return this.requiresTranslation(t)&&r.isSameLanguage(e,t)},r.prototype.handleError=function(t){if("development"===this.config.environment)throw t;f("I18nManager: "+t)},r.prototype.validateLocale=function(t){var e=this.getGTClass();if(!e.isValidLocale(t)||!e.determineLocale(t))throw new Error("I18nManager: validateLocale(): locale ".concat(t," is not valid"))},r.prototype.getGTClassClean=function(t){return new e.GT({sourceLocale:this.config.defaultLocale,targetLocale:t,locales:this.config.locales,customMapping:this.config.customMapping,projectId:this.config.projectId,baseUrl:this.config.runtimeUrl||void 0,apiKey:this.config.apiKey,devApiKey:this.config.devApiKey})},r}();var $=void 0;function w(){return $||(h("getI18nManager(): Translation failed because I18nManager not initialized."),$=new C({defaultLocale:t.libraryDefaultLocale,locales:[t.libraryDefaultLocale]})),$}function E(t){return Object.fromEntries(Object.entries(t).filter(function(t){var e=t[0];return"$id"!==e&&"$context"!==e&&"$maxChars"!==e&&"$hash"!==e&&"$_hash"!==e&&"$_source"!==e&&"$_fallback"!==e&&"$format"!==e&&"$_locales"!==e&&"$locale"!==e}))}var M=function(t){return'String interpolation failed for message: "'.concat(t,'".')};function x(r,n){var a,i;if(!r)return r;var s=n.$_fallback,c=E(n);try{var l=t.extractVars(s||""),u=function(t,r,n,a){try{return e.formatMessage(t,{variables:r,locales:n,dataFormat:a})}catch(e){return h(M(t)),t}}(Object.keys(l).length?t.condenseVars(r):r,o(o(o({},c),l),((a={})[t.VAR_IDENTIFIER]="other",a)),null!==(i=n.$locale)&&void 0!==i?i:n.$_locales,n.$format);return e.formatCutoff(u,{maxChars:n.$maxChars})}catch(t){return h(M(r)),null!=n.$_fallback?x(n.$_fallback,o(o({},n),{$_fallback:void 0})):e.formatCutoff(r,{maxChars:n.$maxChars})}}function O(t,r){var n;switch(null!==(n=r.$format)&&void 0!==n?n:"STRING"){case"ICU":return x(t,r);case"I18NEXT":case"STRING":return function(t,r){var n;return e.formatCutoff(t,{locales:null!==(n=r.$locale)&&void 0!==n?n:r.$_locales,maxChars:r.$maxChars})}(t,r);default:return t}}function k(t,e){var r=function(t,e){return o({$format:e},t)}(e,"STRING");return function(t){var e=t.source,r=t.target,n=t.options,a=w();return null!=r?O(r,o({$locale:a.getLocale(),$_fallback:e},n)):O(e,o({$locale:a.getDefaultLocale()},n))}({source:t,target:w().lookupTranslation(t,r),options:r})}function j(t){return"string"==typeof t&&-1!==t.lastIndexOf(":")?t.slice(0,t.lastIndexOf(":")):t}function S(e){if(-1===e.lastIndexOf(":"))return null;var r=e.slice(e.lastIndexOf(":")+1);try{return JSON.parse(t.decode(r))}catch(t){return null}}Object.defineProperty(exports,"declareStatic",{enumerable:!0,get:function(){return t.declareStatic}}),Object.defineProperty(exports,"declareVar",{enumerable:!0,get:function(){return t.declareVar}}),Object.defineProperty(exports,"decodeVars",{enumerable:!0,get:function(){return t.decodeVars}}),Object.defineProperty(exports,"derive",{enumerable:!0,get:function(){return t.derive}}),exports.decodeMsg=j,exports.decodeOptions=S,exports.getDefaultLocale=function(){return w().getDefaultLocale()},exports.getLocale=function(){return w().getLocale()},exports.getLocaleProperties=function(t){return w().getGTClass().getLocaleProperties(t)},exports.getLocales=function(){return w().getLocales()},exports.getVersionId=function(){return w().getVersionId()},exports.gtFallback=function(t,e){return void 0===e&&(e={}),x(t,e)},exports.mFallback=function(t,e){var r;return void 0===e&&(e={}),t?function(t){return!(!t.$_hash||!t.$_source)}(null!==(r=S(t))&&void 0!==r?r:{})?j(t):x(t,e):t},exports.msg=function r(n,a){var i;if("string"!=typeof n)return a?n.map(function(t,e){return r(t,o(o({},a),a.$id&&{$id:"".concat(a.$id,".").concat(e)}))}):n;if(!a)return n;var s=E(a),c=n;try{c=e.formatMessage(n,{locales:[t.libraryDefaultLocale],variables:o(o({},s),(i={},i[t.VAR_IDENTIFIER]="other",i))})}catch(t){return h(M(n)),n}var l=n,u=a.$_hash||_(n,o({$format:"ICU"},a)),f=o(o({},a),{$_source:l,$_hash:u}),p=t.encode(JSON.stringify(f));return"".concat(c,":").concat(p)},exports.t=function(t,e){return k(t,o({$format:"ICU"},e))};
|
|
1
|
+
"use strict";var t=require("generaltranslation/internal"),e=require("generaltranslation"),n=require("generaltranslation/id"),r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){return o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},o.apply(this,arguments)};function i(t,e,n,r){return new(n||(n=Promise))(function(a,o){function i(t){try{c(r.next(t))}catch(t){o(t)}}function s(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?a(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,s)}c((r=r.apply(t,e||[])).next())})}function s(t,e){var n,r,a,o={label:0,sent:function(){if(1&a[0])throw a[1];return a[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=s(0),i.throw=s(1),i.return=s(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(o=0)),o;)try{if(n=1,r&&(a=2&s[0]?r.return:s[0]?r.throw||((a=r.return)&&a.call(r),0):r.next)&&!(a=a.call(r,s[1])).done)return a;switch(r=0,a&&(s=[2&s[0],a.value]),s[0]){case 0:case 1:a=s;break;case 4:return o.label++,{value:s[1],done:!1};case 5:o.label++,r=s[1],s=[0];continue;case 7:s=o.ops.pop(),o.trys.pop();continue;default:if(!(a=o.trys,(a=a.length>0&&a[a.length-1])||6!==s[0]&&2!==s[0])){o=0;continue}if(3===s[0]&&(!a||s[1]>a[0]&&s[1]<a[3])){o.label=s[1];break}if(6===s[0]&&o.label<a[1]){o.label=a[1],a=s;break}if(a&&o.label<a[2]){o.label=a[2],o.ops.push(s);break}a[2]&&o.ops.pop(),o.trys.pop();continue}s=e.call(t,o)}catch(t){s=[6,t],r=0}finally{n=a=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function c(t,e,n){if(n||2===arguments.length)for(var r,a=0,o=e.length;a<o;a++)!r&&a in e||(r||(r=Array.prototype.slice.call(e,0,a)),r[a]=e[a]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var l,u,h=function(t){console.warn(t)},f=function(t){console.error(t)};function p(e){return e.loadTranslations?l.CUSTOM:e.cacheUrl?l.REMOTE:void 0!==e.cacheUrl&&e.cacheUrl!==t.defaultCacheUrl||!e.projectId?l.DISABLED:l.GT_REMOTE}function d(e){return void 0!==e.runtimeUrl&&e.runtimeUrl!==t.defaultRuntimeApiUrl||!e.projectId||!e.devApiKey&&!e.apiKey?e.runtimeUrl?u.CUSTOM:u.DISABLED:u.GT}function v(t){return p(t)===l.GT_REMOTE||d(t)===u.GT}function g(t){var n=[];return n.push.apply(n,function(t){var e=[],n=t.projectId,r=t.loadTranslations;switch(p(t)){case l.REMOTE:case l.GT_REMOTE:n||e.push({type:"warning",message:"projectId is required when loading translations from a remote store"});break;case l.CUSTOM:r||e.push({type:"error",message:"loadTranslations is required when loading translations from a custom loader"});case l.DISABLED:}return e}(t)),n.push.apply(n,function(t){var e=[];switch(d(t)){case u.CUSTOM:case u.GT:t.projectId||e.push({type:"warning",message:"projectId is required"}),t.devApiKey||t.apiKey||e.push({type:"warning",message:"devApiKey or apiKey is required"});case u.DISABLED:}return e}(t)),n.push.apply(n,function(t){var n=[];if(!v(t))return n;var r=t.defaultLocale,a=t.locales,o=t.customMapping;return new Set(c(c([],r?[r]:[],!0),a||[],!0)).forEach(function(t){e.isValidLocale(t,o)||n.push({type:"error",message:"Invalid locale: ".concat(t)})}),n}(t)),n}!function(t){t.GT_REMOTE="gt-remote",t.REMOTE="remote",t.CUSTOM="custom",t.DISABLED="disabled"}(l||(l={})),function(t){t.GT="gt",t.CUSTOM="custom",t.DISABLED="disabled"}(u||(u={}));var y=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="fallback-storage-adapter",e.storage={},e}return a(e,t),e.prototype.getItem=function(t){return this.storage[t]},e.prototype.setItem=function(t,e){this.storage[t]=e},e.prototype.removeItem=function(t){delete this.storage[t]},e}(function(){});function m(n){var r=this,a=function(e){var n=e.cacheUrl,r=void 0===n?t.defaultCacheUrl:n,a=e.projectId,o=e._versionId,i=e._branchId,s=o?"/".concat(o):"",c=i?"?branchId=".concat(i):"";return"".concat(r,"/").concat(a,"/[locale]")+s+c}(n);return function(t){return i(r,void 0,void 0,function(){var r,o;return s(this,function(i){switch(i.label){case 0:return t=e.resolveCanonicalLocale(t,n.customMapping),r=a.replace("[locale]",t),[4,fetch(r)];case 1:if(!(o=i.sent()).ok)throw new Error("Failed to load translations from ".concat(r));return[4,o.json()];case 2:return[2,i.sent()]}})})}}function T(t){var e=t.type,n=t.remoteTranslationLoaderParams,r=t.loadTranslations;e===l.DISABLED&&h("I18nManager: No translation loader found. No translations will be loaded.");var a=n.cacheUrl,o=n.projectId,c=n._versionId,u=n._branchId,f=n.customMapping;switch(e){case l.REMOTE:case l.GT_REMOTE:return m({cacheUrl:a||"",projectId:o||"",_versionId:c,_branchId:u,customMapping:f});case l.CUSTOM:return r;case l.DISABLED:return function(){var t=this;return function(e){return i(t,void 0,void 0,function(){return s(this,function(t){return[2,{}]})})}}()}}var b=function(){function t(t,e){this.cache={},this.fallbackPromises={},this.cache=structuredClone(t),this.onHit=null==e?void 0:e.onHit,this.onMiss=null==e?void 0:e.onMiss}return t.prototype.setCache=function(t,e){this.cache[t]=e},t.prototype.getCache=function(t){var e=this.genKey(t);return this.cache[e]},t.prototype.getInternalCache=function(){return this.cache},t.prototype.missCache=function(t){return i(this,void 0,void 0,function(){var e,n,r;return s(this,function(a){switch(a.label){case 0:return e=this.genKey(t),void 0===this.fallbackPromises[e]?[3,2]:[4,this.fallbackPromises[e]];case 1:return[2,a.sent()];case 2:n=this.fallback(t),this.fallbackPromises[e]=n,a.label=3;case 3:return a.trys.push([3,,5,6]),[4,n];case 4:return r=a.sent(),this.cache[e]=r,[2,r];case 5:return delete this.fallbackPromises[e],[7];case 6:return[2]}})})},t}();function _(e,r){return n.hashSource(o(o(o(o({source:"ICU"===r.$format?t.indexVars(e):e},(null==r?void 0:r.$context)&&{context:r.$context}),(null==r?void 0:r.$id)&&{id:r.$id}),"$maxChars"in r&&null!=r.$maxChars&&{$maxChars:Math.abs(r.$maxChars)}),{dataFormat:r.$format}))}var C=function(t){function e(e){var n=e.init,r=e.translateMany,a=e.lifecycle,o=t.call(this,n,a)||this;return o._queue=[],o._batchTimer=null,o._activeRequests=0,o._translateMany=r,o}return a(e,t),e.prototype.get=function(t){var e=this.getCache(t);return null!=e&&this.onHit&&this.onHit({inputKey:t,cacheKey:this.genKey(t),cacheValue:e,outputValue:e}),e},e.prototype.miss=function(t){return i(this,void 0,void 0,function(){var e;return s(this,function(n){switch(n.label){case 0:return[4,this.missCache(t)];case 1:return null!=(e=n.sent())&&this.onMiss&&this.onMiss({inputKey:t,cacheKey:this.genKey(t),cacheValue:e,outputValue:e}),[2,e]}})})},e.prototype.genKey=function(t){return _(t.message,t.options)},e.prototype.fallback=function(t){var e=this._enqueueTranslation(t);return this._queue.length>=25?this._flushNow():this._scheduleBatch(),e},e.prototype._flushNow=function(){this._batchTimer&&(clearTimeout(this._batchTimer),this._batchTimer=null),this._drainQueue()},e.prototype._scheduleBatch=function(){var t=this;this._batchTimer||(this._batchTimer=setTimeout(function(){t._batchTimer=null,t._drainQueue()},50))},e.prototype._drainQueue=function(){for(;this._queue.length>0&&this._activeRequests<100;){var t=this._queue.splice(0,25);this._sendBatchRequest(t)}this._queue.length>0&&this._scheduleBatch()},e.prototype._enqueueTranslation=function(t){var e=this,n=this.genKey(t),r=t.options;return new Promise(function(a,i){e._queue.push({key:n,source:t.message,metadata:o(o(o(o({},(null==r?void 0:r.$context)&&{context:r.$context}),(null==r?void 0:r.$id)&&{id:r.$id}),"$maxChars"in r&&null!=r.$maxChars&&{$maxChars:Math.abs(r.$maxChars)}),{dataFormat:r.$format}),resolve:function(t){return a(t)},reject:i})})},e.prototype._sendBatchRequest=function(t){return i(this,void 0,void 0,function(){var e,n;return s(this,function(r){switch(r.label){case 0:return this._activeRequests++,e=function(t){return t.reduce(function(t,e){return t[e.key]={source:e.source,metadata:e.metadata},t},{})}(t),[4,this._sendBatchRequestWithErrorHandling(t,e)];case 1:return(n=r.sent())&&this._handleTranslationResponse(t,n),this._activeRequests--,[2]}})})},e.prototype._sendBatchRequestWithErrorHandling=function(t,e){return i(this,void 0,void 0,function(){var n,r,a;return s(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this._translateMany(e)];case 1:return[2,o.sent()];case 2:for(n=o.sent(),r=0,a=t;r<a.length;r++)a[r].reject(n);return[2,void 0];case 3:return[2]}})})},e.prototype._handleTranslationResponse=function(t,e){for(var n=0,r=t;n<r.length;n++){var a=r[n],o=a.key,i=e[o];if(i&&i.success){var s=i.translation;this.setCache(o,s),a.resolve(s)}else a.reject(null==i?void 0:i.error)}},e}(b);var L=function(t){function e(e){var n=e.init,r=void 0===n?{}:n,a=e.ttl,o=e.loadTranslations,i=e.createTranslateMany,s=e.lifecycle,c=s.onLocalesCacheHit,l=s.onLocalesCacheMiss,u=s.onTranslationsCacheHit,h=s.onTranslationsCacheMiss,f=t.call(this,r,{onHit:c,onMiss:l})||this;return f.ttl=6e4,f.ttl=null===a?-1:null!=a?a:6e4,f._translationLoader=o,f._createTranslateMany=i,f._onTranslationsCacheHit=u,f._onTranslationsCacheMiss=h,f}return a(e,t),e.prototype.get=function(t){var e=this.getCache(t);if(e&&!(e.expiresAt>0&&e.expiresAt<Date.now())){var n=e.translationsCache;return null!=n&&this.onHit&&this.onHit({inputKey:t,cacheKey:this.genKey(t),cacheValue:e,outputValue:n}),n}},e.prototype.miss=function(t){return i(this,void 0,void 0,function(){var e,n;return s(this,function(r){switch(r.label){case 0:return[4,this.missCache(t)];case 1:return e=r.sent(),null!=(n=e.translationsCache)&&this.onMiss&&this.onMiss({inputKey:t,cacheKey:this.genKey(t),cacheValue:e,outputValue:n}),[2,n]}})})},e.prototype.genKey=function(t){return t},e.prototype.fallback=function(t){return i(this,void 0,void 0,function(){var e,n,r,a;return s(this,function(o){switch(o.label){case 0:return e=this._translationLoader(t),n=this.ttl<0?this.ttl:Date.now()+this.ttl,r=C.bind,a={},[4,e];case 1:return[2,{translationsCache:new(r.apply(C,[void 0,(a.init=o.sent(),a.lifecycle=this._createTranslationsCacheLifecycle(t),a.translateMany=this._createTranslateMany(t),a)])),expiresAt:n}]}})})},e.prototype._createTranslationsCacheLifecycle=function(t){var e=this;return{onHit:this._onTranslationsCacheHit?function(n){return e._onTranslationsCacheHit(o({locale:t},n))}:void 0,onMiss:this._onTranslationsCacheMiss?function(n){return e._onTranslationsCacheMiss(o({locale:t},n))}:void 0}},e}(b);function I(t){var e=t.onLocalesCacheHit,n=t.onLocalesCacheMiss,r=t.onTranslationsCacheHit,a=t.onTranslationsCacheMiss;return{onLocalesCacheHit:function(t){null==e||e({locale:t.inputKey,value:t.outputValue.getInternalCache()})},onLocalesCacheMiss:function(t){null==n||n({locale:t.inputKey,value:t.outputValue.getInternalCache()})},onTranslationsCacheHit:function(t){null==r||r({locale:t.locale,hash:t.cacheKey,value:t.outputValue})},onTranslationsCacheMiss:function(t){null==a||a({locale:t.locale,hash:t.cacheKey,value:t.outputValue})}}}var M=function(){function n(n){var r,a,i,s,l,u=this;this.resolveTranslationSync=function(t,e){return u.lookupTranslation(t,e)},function(t,e,n){if(void 0===n&&(n=!0),t.forEach(function(t){switch(t.type){case"error":f(e+t.message);break;case"warning":h(e+t.message)}}),n&&t.some(function(t){return"error"===t.type}))throw new Error("Validation errors occurred")}(g(n),"I18nManager: "),this.config=(s=v(i=n),l=function(t){var e=t.defaultLocale,n=t.locales,r=t.customMapping;return{defaultLocale:e,locales:Array.from(new Set(c([e],n,!0))),customMapping:r||{}}}({defaultLocale:i.defaultLocale||t.libraryDefaultLocale,locales:i.locales||[t.libraryDefaultLocale],customMapping:i.customMapping}),o({environment:i.environment||"production",enableI18n:void 0===i.enableI18n||i.enableI18n,projectId:i.projectId,devApiKey:i.devApiKey,apiKey:i.apiKey,runtimeUrl:i.runtimeUrl,_versionId:i._versionId},s?function(t){var n=e.standardizeLocale(t.defaultLocale),r=t.locales.map(function(n){var r,a,o,i;return("string"==typeof(null===(r=t.customMapping)||void 0===r?void 0:r[n])?null===(a=t.customMapping)||void 0===a?void 0:a[n]:null===(i=null===(o=t.customMapping)||void 0===o?void 0:o[n])||void 0===i?void 0:i.code)?n:e.standardizeLocale(n)}),a=Object.fromEntries(Object.entries(t.customMapping||{}).map(function(t){var n=t[0],r=t[1];return[n,"string"==typeof r?e.standardizeLocale(r):o(o({},r),r.code?{code:e.standardizeLocale(r.code)}:{})]}));return{defaultLocale:n,locales:r,customMapping:a}}(l):l)),this.storeAdapter=null!==(r=n.storeAdapter)&&void 0!==r?r:new y;var d,m,b=function(t){return T({loadTranslations:t.loadTranslations,type:p(t),remoteTranslationLoaderParams:{cacheUrl:t.cacheUrl,projectId:t.projectId,_versionId:t._versionId,_branchId:t._branchId,customMapping:t.customMapping}})}(n),_=(d=this.getGTClassClean(),m=12e3,function(t){return function(e){return d.translateMany(e,{targetLocale:t},m)}});this.localesCache=new L({loadTranslations:b,createTranslateMany:_,lifecycle:I(null!==(a=n.lifecycle)&&void 0!==a?a:{})})}return n.prototype.getAdapterType=function(){return this.storeAdapter.type},n.prototype.getLocale=function(){var t=this.storeAdapter.getItem("locale");return t||(h("getLocale() invoked outside of translation context, falling back to default locale"),this.config.defaultLocale)},n.prototype.setLocale=function(t){try{this.validateLocale(t);var e=this.getGTClass();this.storeAdapter.setItem("locale",e.determineLocale(t))}catch(t){this.handleError(t)}},n.prototype.getDefaultLocale=function(){return this.config.defaultLocale},n.prototype.getLocales=function(){return this.config.locales},n.prototype.getVersionId=function(){return this.config._versionId},n.prototype.getGTClass=function(){return this.getGTClassClean(this.getLocale())},n.prototype.isTranslationEnabled=function(){return this.config.enableI18n},n.prototype.getTranslationLoader=function(){var t=this;return function(e){return t.loadTranslations(e)}},n.prototype.loadTranslations=function(){return i(this,arguments,void 0,function(t){var e,n;return void 0===t&&(t=this.getLocale()),s(this,function(r){switch(r.label){case 0:return r.trys.push([0,3,,4]),this.validateLocale(t),this.requiresTranslation(t)?(e=this.localesCache.get(t))?[3,2]:[4,this.localesCache.miss(t)]:[2,{}];case 1:e=r.sent(),r.label=2;case 2:return[2,e.getInternalCache()];case 3:return n=r.sent(),this.handleError(n),[2,{}];case 4:return[2]}})})},n.prototype.lookupTranslation=function(t,e){var n;try{var r=null!==(n=e.$locale)&&void 0!==n?n:this.getLocale();if(this.validateLocale(r),!this.requiresTranslation(r))return t;var a=this.localesCache.get(r);if(!a)return;return a.get({message:t,options:e})}catch(t){return void this.handleError(t)}},n.prototype.lookupTranslationWithFallback=function(t,e){return i(this,void 0,void 0,function(){var n,r,a,o,i;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,5,,6]),n=null!==(i=e.$locale)&&void 0!==i?i:this.getLocale(),this.validateLocale(n),this.requiresTranslation(n)?(r=this.localesCache.get(n))?[3,2]:[4,this.localesCache.miss(n)]:[2,t];case 1:r=s.sent(),s.label=2;case 2:return null!=(a=r.get({message:t,options:e}))?[3,4]:[4,r.miss({message:t,options:e})];case 3:a=s.sent(),s.label=4;case 4:return[2,a];case 5:return o=s.sent(),this.handleError(o),[2,void 0];case 6:return[2]}})})},n.prototype.getLookupTranslation=function(){return i(this,arguments,void 0,function(t,e){var n,r,a;return void 0===t&&(t=this.getLocale()),void 0===e&&(e=[]),s(this,function(o){switch(o.label){case 0:return o.trys.push([0,4,,5]),this.validateLocale(t),this.requiresTranslation(t)?(n=function(t,e){var n=t.filter(function(t){return null==t.options.$locale||t.options.$locale===e});return n}(e,t),n.length!==e.length&&h("I18nManager: getLookupTranslation(): prefetchEntries must all be the same locale, ignoring all entries that are not for ".concat(t)),(r=this.localesCache.get(t))?[3,2]:[4,this.localesCache.miss(t)]):[2,function(t){return t}];case 1:r=o.sent(),o.label=2;case 2:return r?[4,Promise.all(n.filter(function(t){return null==r.get(t)}).map(function(t){return r.miss(t)}))]:[2,function(){}];case 3:return o.sent(),[2,function(t,e){return r.get({message:t,options:e})}];case 4:return a=o.sent(),this.handleError(a),[2,function(t){return t}];case 5:return[2]}})})},n.prototype.getTranslations=function(){return i(this,arguments,void 0,function(t){return void 0===t&&(t=this.getLocale()),s(this,function(e){try{return this.validateLocale(t),[2,this.loadTranslations(t)]}catch(t){return this.handleError(t),[2,{}]}return[2]})})},n.prototype.getTranslationResolver=function(){return i(this,arguments,void 0,function(t){return void 0===t&&(t=this.getLocale()),s(this,function(e){return[2,this.getLookupTranslation(t)]})})},n.prototype.requiresTranslation=function(t){void 0===t&&(t=this.getLocale());var e=this.getDefaultLocale(),n=this.getGTClass(),r=this.getLocales();return this.isTranslationEnabled()&&n.requiresTranslation(e,t,r)},n.prototype.requiresDialectTranslation=function(t){void 0===t&&(t=this.getLocale());var e=this.getDefaultLocale(),n=this.getGTClass();return this.requiresTranslation(t)&&n.isSameLanguage(e,t)},n.prototype.handleError=function(t){if("development"===this.config.environment)throw t;f("I18nManager: "+t)},n.prototype.validateLocale=function(t){var e=this.getGTClass();if(!e.isValidLocale(t)||!e.determineLocale(t))throw new Error("I18nManager: validateLocale(): locale ".concat(t," is not valid"))},n.prototype.getGTClassClean=function(t){return new e.GT({sourceLocale:this.config.defaultLocale,targetLocale:t,locales:this.config.locales,customMapping:this.config.customMapping,projectId:this.config.projectId,baseUrl:this.config.runtimeUrl||void 0,apiKey:this.config.apiKey,devApiKey:this.config.devApiKey})},n}();var $=void 0;function w(){return $||(h("getI18nManager(): Translation failed because I18nManager not initialized."),$=new M({defaultLocale:t.libraryDefaultLocale,locales:[t.libraryDefaultLocale]})),$}function E(t){return Object.fromEntries(Object.entries(t).filter(function(t){var e=t[0];return"$id"!==e&&"$context"!==e&&"$maxChars"!==e&&"$hash"!==e&&"$_hash"!==e&&"$_source"!==e&&"$_fallback"!==e&&"$format"!==e&&"$_locales"!==e&&"$locale"!==e}))}var x=function(t){return'String interpolation failed for message: "'.concat(t,'".')};function O(n,r){var a,i;if(!n)return n;var s=r.$_fallback,c=E(r);try{var l=t.extractVars(s||""),u=function(t,n,r,a){try{return e.formatMessage(t,{variables:n,locales:r,dataFormat:a})}catch(e){return h(x(t)),t}}(Object.keys(l).length?t.condenseVars(n):n,o(o(o({},c),l),((a={})[t.VAR_IDENTIFIER]="other",a)),null!==(i=r.$locale)&&void 0!==i?i:r.$_locales,r.$format);return e.formatCutoff(u,{maxChars:r.$maxChars})}catch(t){return h(x(n)),null!=r.$_fallback?O(r.$_fallback,o(o({},r),{$_fallback:void 0})):e.formatCutoff(n,{maxChars:r.$maxChars})}}function k(t,n){var r;switch(null!==(r=n.$format)&&void 0!==r?r:"STRING"){case"ICU":return O(t,n);case"I18NEXT":case"STRING":return function(t,n){var r;return e.formatCutoff(t,{locales:null!==(r=n.$locale)&&void 0!==r?r:n.$_locales,maxChars:n.$maxChars})}(t,n);default:return t}}function j(t,e){var n=function(t,e){return o({$format:e},t)}(e,"STRING");return function(t){var e=t.source,n=t.target,r=t.options,a=w();return null!=n?k(n,o({$locale:a.getLocale(),$_fallback:e},r)):k(e,o({$locale:a.getDefaultLocale()},r))}({source:t,target:w().lookupTranslation(t,n),options:n})}function K(t){return"string"==typeof t&&-1!==t.lastIndexOf(":")?t.slice(0,t.lastIndexOf(":")):t}function S(e){if(-1===e.lastIndexOf(":"))return null;var n=e.slice(e.lastIndexOf(":")+1);try{return JSON.parse(t.decode(n))}catch(t){return null}}Object.defineProperty(exports,"declareStatic",{enumerable:!0,get:function(){return t.declareStatic}}),Object.defineProperty(exports,"declareVar",{enumerable:!0,get:function(){return t.declareVar}}),Object.defineProperty(exports,"decodeVars",{enumerable:!0,get:function(){return t.decodeVars}}),Object.defineProperty(exports,"derive",{enumerable:!0,get:function(){return t.derive}}),exports.decodeMsg=K,exports.decodeOptions=S,exports.getDefaultLocale=function(){return w().getDefaultLocale()},exports.getLocale=function(){return w().getLocale()},exports.getLocaleProperties=function(t){return w().getGTClass().getLocaleProperties(t)},exports.getLocales=function(){return w().getLocales()},exports.getVersionId=function(){return w().getVersionId()},exports.gtFallback=function(t,e){return void 0===e&&(e={}),O(t,e)},exports.mFallback=function(t,e){var n;return void 0===e&&(e={}),t?function(t){return!(!t.$_hash||!t.$_source)}(null!==(n=S(t))&&void 0!==n?n:{})?K(t):O(t,e):t},exports.msg=function n(r,a){var i;if("string"!=typeof r)return a?r.map(function(t,e){return n(t,o(o({},a),a.$id&&{$id:"".concat(a.$id,".").concat(e)}))}):r;if(!a)return r;var s=E(a),c=r;try{c=e.formatMessage(r,{locales:[t.libraryDefaultLocale],variables:o(o({},s),(i={},i[t.VAR_IDENTIFIER]="other",i))})}catch(t){return h(x(r)),r}var l=r,u=a.$_hash||_(r,o({$format:"ICU"},a)),f=o(o({},a),{$_source:l,$_hash:u}),p=t.encode(JSON.stringify(f));return"".concat(c,":").concat(p)},exports.t=function(t,e){return j(t,o({$format:"ICU"},e))};
|
|
2
2
|
//# sourceMappingURL=index.cjs.min.cjs.map
|