gt-i18n 0.7.8 → 0.7.10

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # gt-i18n
2
2
 
3
+ ## 0.7.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1158](https://github.com/generaltranslation/gt/pull/1158) [`5b85ccd`](https://github.com/generaltranslation/gt/commit/5b85ccd80b93b91eae9c873b258a13b6a57443c8) Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - add auto injection for jsx translation
8
+
9
+ - Updated dependencies [[`5b85ccd`](https://github.com/generaltranslation/gt/commit/5b85ccd80b93b91eae9c873b258a13b6a57443c8)]:
10
+ - @generaltranslation/supported-locales@2.0.60
11
+ - generaltranslation@8.2.2
12
+
13
+ ## 0.7.9
14
+
15
+ ### Patch Changes
16
+
17
+ - [#1161](https://github.com/generaltranslation/gt/pull/1161) [`eca3d8d`](https://github.com/generaltranslation/gt/commit/eca3d8d8298969258bb4ab576b698c48cfbc318f) Thanks [@moss-bryophyta](https://github.com/moss-bryophyta)! - Update logo blocks in READMEs
18
+
19
+ - Updated dependencies [[`eca3d8d`](https://github.com/generaltranslation/gt/commit/eca3d8d8298969258bb4ab576b698c48cfbc318f)]:
20
+ - generaltranslation@8.2.1
21
+ - @generaltranslation/supported-locales@2.0.59
22
+
3
23
  ## 0.7.8
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  <p align="center">
2
2
  <a href="https://generaltranslation.com/docs/i18n">
3
3
  <picture>
4
- <source media="(prefers-color-scheme: light)" srcset="https://generaltranslation.com/brand/gt-logo-light.svg">
5
- <img alt="General Translation" src="https://generaltranslation.com/brand/gt-logo-dark.svg" width="100" height="100">
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://generaltranslation.com/brand/gt-logo-dark.svg">
5
+ <img alt="General Translation" src="https://generaltranslation.com/brand/gt-logo-light.svg" width="100" height="100">
6
6
  </picture>
7
7
  </a>
8
8
  </p>
@@ -1,14 +1,18 @@
1
1
  import { I18nManagerConfig, I18nManagerConstructorParams } from './types';
2
2
  import { StorageAdapterType } from './storage-adapter/types';
3
- import { Translations } from './translations-manager/utils/types/translation-data';
3
+ import { Translation, Translations } from './translations-manager/utils/types/translation-data';
4
4
  import { StorageAdapter } from './storage-adapter/StorageAdapter';
5
5
  import { GT } from 'generaltranslation';
6
- import { InlineTranslationOptions } from '../translation-functions/types/options';
6
+ import { ResolutionOptions } from '../translation-functions/types/options';
7
7
  import { TranslationsLoader } from './translations-manager/translations-loaders/types';
8
8
  /**
9
9
  * Class for managing translation functionality
10
+ * @template T - The type of the storage adapter
11
+ * @template U - The type of the translation that will be cached
12
+ *
13
+ * TODO: next major version, move U to the first generic and make it a required parameter, no default value
10
14
  */
11
- declare class I18nManager<T extends StorageAdapter = StorageAdapter> {
15
+ declare class I18nManager<T extends StorageAdapter = StorageAdapter, U extends Translation = Translation> {
12
16
  protected config: I18nManagerConfig;
13
17
  /**
14
18
  * Cache for translations
@@ -65,14 +69,14 @@ declare class I18nManager<T extends StorageAdapter = StorageAdapter> {
65
69
  /**
66
70
  * Get the translations (error on unloaded translations)
67
71
  * @param {string} message - The message to get the translation for
68
- * @param {InlineTranslationOptions} [options] - The options for the translation
69
- * @returns {string | undefined} The translation for the given message and options synchronously
72
+ * @param {ResolutionOptions} [options] - The options for the translation
73
+ * @returns {U | undefined} The translation for the given message and options synchronously
70
74
  */
71
- resolveTranslationSync: TranslationResolver;
75
+ resolveTranslationSync: TranslationResolver<U>;
72
76
  /**
73
77
  * Get the translations
74
78
  */
75
- getTranslations(locale?: string): Promise<Translations>;
79
+ getTranslations(locale?: string): Promise<Translations<U>>;
76
80
  /**
77
81
  * Get translation for a given locale and message
78
82
  *
@@ -81,7 +85,7 @@ declare class I18nManager<T extends StorageAdapter = StorageAdapter> {
81
85
  *
82
86
  * Note: we can assume that the translation is a string because we are passing a string
83
87
  */
84
- getTranslationResolver(locale?: string): Promise<TranslationResolver>;
88
+ getTranslationResolver(locale?: string): Promise<TranslationResolver<U>>;
85
89
  /**
86
90
  * Returns true if translation is required
87
91
  * @param {string} [locale] - The user's locale
@@ -97,11 +101,10 @@ declare class I18nManager<T extends StorageAdapter = StorageAdapter> {
97
101
  }
98
102
  export { I18nManager };
99
103
  /**
100
- * Type definition for a synchronous translation resolution given a hashable message and options
101
- * @template T - The type of the message (default: string)
102
- * @template U - The type of the translation (default: string | undefined)
103
- * @param {T} message - The message to get the translation for
104
- * @param {InlineTranslationOptions} [options] - The options for the translation
105
- * @returns {U} The translation for the given message and options
104
+ * Type definition for a translation resolver
105
+ * @template U - The type of the translation (default: Translation)
106
+ * @param {U} message - The message to get the translation for
107
+ * @param {ResolutionOptions} [options] - The options for the translation
108
+ * @returns {U | undefined} The translation for the given message and options or undefined if the translation is not found
106
109
  */
107
- type TranslationResolver<T extends unknown = string, U extends unknown = string | undefined> = (message: T, options?: InlineTranslationOptions) => U;
110
+ type TranslationResolver<U extends Translation = Translation> = <T extends U = U>(message: T, options: ResolutionOptions) => T | undefined;
@@ -1,10 +1,13 @@
1
1
  import { I18nManager } from './I18nManager';
2
2
  import { StorageAdapter } from './storage-adapter/StorageAdapter';
3
+ import { Translation } from './translations-manager/utils/types/translation-data';
3
4
  /**
4
5
  * Get the singleton instance of I18nManager
5
6
  * @returns The singleton instance of I18nManager
7
+ * @template T - The type of the storage adapter
8
+ * @template U - The type of the translation that will be cached
6
9
  */
7
- export declare function getI18nManager<T extends StorageAdapter>(): I18nManager<T> | I18nManager<StorageAdapter>;
10
+ export declare function getI18nManager<T extends StorageAdapter = StorageAdapter, U extends Translation = Translation>(): I18nManager<T, U> | I18nManager<T, Translation> | I18nManager<StorageAdapter, U> | I18nManager<StorageAdapter, Translation>;
8
11
  /**
9
12
  * Configure the singleton instance of I18nManager
10
13
  * @param config - The configuration for the I18nManager
@@ -1,10 +1,10 @@
1
1
  import { TranslationsLoader } from './translations-loaders/types';
2
- import { Translations } from './utils/types/translation-data';
2
+ import { Translation, Translations } from './utils/types/translation-data';
3
3
  import { TranslationsManagerConfig } from './utils/types/translations-manager';
4
4
  /**
5
5
  * TranslationsManager is responsible for loading and caching translations
6
6
  */
7
- declare class TranslationsManager {
7
+ declare class TranslationsManager<T extends Translation> {
8
8
  /**
9
9
  * Translation loader function
10
10
  */
@@ -51,12 +51,12 @@ declare class TranslationsManager {
51
51
  /**
52
52
  * Get translations for a given locale
53
53
  */
54
- getTranslations(locale: string): Promise<Translations>;
54
+ getTranslations(locale: string): Promise<Translations<T>>;
55
55
  /**
56
56
  * Get translations for a given locale
57
57
  * @note This method does not account for cache expiry
58
58
  */
59
- getTranslationsSync(locale: string): Translations | undefined;
59
+ getTranslationsSync(locale: string): Translations<T> | undefined;
60
60
  /**
61
61
  * Get the translation loader function
62
62
  */
@@ -1,4 +1,4 @@
1
- import { Translations } from '../utils/types/translation-data';
1
+ import { Translation, Translations } from '../utils/types/translation-data';
2
2
  /**
3
3
  * Translations loader function type
4
4
  */
@@ -7,4 +7,4 @@ export type TranslationsLoader = (locale: string) => Promise<unknown>;
7
7
  * Safe translations loader function type
8
8
  * @returns A promise that resolves to a mapping of strings to {@link Translation}
9
9
  */
10
- export type SafeTranslationsLoader = (locale: string) => Promise<Translations>;
10
+ export type SafeTranslationsLoader<T extends Translation> = (locale: string) => Promise<Translations<T>>;
@@ -1,13 +1,15 @@
1
+ import { Content } from 'generaltranslation/types';
1
2
  /**
2
3
  * A single string translation
3
- * Unknown represents JSX translations which are out of scope for the `gt-i18n` package
4
+ * TODO: remove this type and use Content everywhere instead
4
5
  */
5
- export type Translation = string | unknown;
6
+ export type Translation = Content;
6
7
  /**
7
8
  * Object containing translations for a single locale
9
+ * TODO: when done, make the generic default to Translation
8
10
  */
9
- export type Translations = {
10
- [hash: string]: Translation;
11
+ export type Translations<T extends Translation | unknown = Translation> = {
12
+ [hash: string]: T;
11
13
  };
12
14
  /**
13
15
  * A mapping between locales and their {@link Translations} objects along with an expiry timestamp
@@ -15,12 +17,12 @@ export type Translations = {
15
17
  * @property {Promise<Translations>} promise - The promise for the translations object.
16
18
  * @property {number} expiresAt - The timestamp when the translations will expire.
17
19
  */
18
- export type TranslationsMap = Map<string, {
19
- promise: Promise<Translations>;
20
+ export type TranslationsMap<T extends Translation> = Map<string, {
21
+ promise: Promise<Translations<T>>;
20
22
  expiresAt: number;
21
23
  }>;
22
24
  /**
23
25
  * A mapping between locales and their {@link Translations} objects
24
26
  * Maps locale to translations object
25
27
  */
26
- export type ResolvedTranslationsMap = Map<string, Translations>;
28
+ export type ResolvedTranslationsMap<T extends Translation> = Map<string, Translations<T>>;
@@ -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)};var o=function(){return o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},o.apply(this,arguments)};function a(t,e,r,n){return new(r||(r=Promise))(function(o,a){function i(t){try{s(n.next(t))}catch(t){a(t)}}function c(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(i,c)}s((n=n.apply(t,e||[])).next())})}function i(t,e){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}function c(t,e,r){if(r||2===arguments.length)for(var n,o=0,a=e.length;o<a;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var s=function(t){console.warn(t)},l=function(t){console.error(t)};var u;function f(r){var n=this,o=function(e){var r=e.cacheUrl,n=void 0===r?t.defaultCacheUrl:r,o=e.projectId,a=e._versionId,i=e._branchId,c=a?"/".concat(a):"",s=i?"?branchId=".concat(i):"";return"".concat(n,"/").concat(o,"/[locale]")+c+s}(r);return function(t){return a(n,void 0,void 0,function(){var n,a;return i(this,function(i){switch(i.label){case 0:return t=e.resolveCanonicalLocale(t,r.customMapping),n=o.replace("[locale]",t),[4,fetch(n)];case 1:if(!(a=i.sent()).ok)throw new Error("Failed to load translations from ".concat(n));return[4,a.json()];case 2:return[2,i.sent()]}})})}}function p(e){return e.loadTranslations?u.CUSTOM:e.cacheUrl?u.REMOTE:void 0!==e.cacheUrl&&e.cacheUrl!==t.defaultCacheUrl||!e.projectId?u.DISABLED:u.GT_REMOTE}!function(t){t.GT_REMOTE="gt-remote",t.REMOTE="remote",t.CUSTOM="custom",t.DISABLED="disabled"}(u||(u={}));var d,h=function(){function t(t){var e;this.cache=new Map,this.resolvedCache=new Map,this.translationEntryTTL=null===t.cacheExpiryTime?-1:null!==(e=t.cacheExpiryTime)&&void 0!==e?e:6e4;var r=function(t){var e=p(t);e===u.DISABLED&&s("I18nManager: No translation loader found. No translations will be loaded.");switch(e){case u.REMOTE:case u.GT_REMOTE:return f({cacheUrl:t.cacheUrl,projectId:t.projectId,_versionId:t._versionId,_branchId:t._branchId,customMapping:t.customMapping});case u.CUSTOM:return t.loadTranslations;case u.DISABLED:return function(){var t=this;return function(e){return a(t,void 0,void 0,function(){return i(this,function(t){return[2,{}]})})}}()}}(t);this.translationLoader=this.attachResolveCaptureToTranslationLoader(this.protectTranslationLoader(r))}return t.prototype.protectTranslationLoader=function(t){var e=this;return function(r){return a(e,void 0,void 0,function(){var e;return i(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t(r)];case 1:return[2,n.sent()||{}];case 2:return e=n.sent(),l("Failed to load translations "+e),this.cache.delete(r),[2,{}];case 3:return[2]}})})}},t.prototype.attachResolveCaptureToTranslationLoader=function(t){var e=this;return function(r){return a(e,void 0,void 0,function(){var e;return i(this,function(n){switch(n.label){case 0:return[4,t(r)];case 1:return e=n.sent(),this.resolvedCache.set(r,e),[2,e]}})})}},t.prototype.handleCacheMiss=function(t){return a(this,void 0,void 0,function(){var e,r,n;return i(this,function(o){return e=this.translationLoader(t),r=this.translationEntryTTL<0?this.translationEntryTTL:Date.now()+this.translationEntryTTL,n={promise:e,expiresAt:r},this.cache.set(t,n),[2,e]})})},t.prototype.isCacheHit=function(t){if(!this.cache.has(t))return!1;var e=this.cache.get(t).expiresAt;return e<0||e>Date.now()},t.prototype.getTranslations=function(t){return a(this,void 0,void 0,function(){return i(this,function(e){return this.isCacheHit(t)?[2,this.cache.get(t).promise]:[2,this.handleCacheMiss(t)]})})},t.prototype.getTranslationsSync=function(t){return this.resolvedCache.get(t)},t.prototype.getTranslationLoader=function(){return this.translationLoader},t}();function g(e){return void 0!==e.runtimeUrl&&e.runtimeUrl!==t.defaultRuntimeApiUrl||!e.projectId||!e.devApiKey&&!e.apiKey?e.runtimeUrl?d.CUSTOM:d.DISABLED:d.GT}function v(t){return p(t)===u.GT_REMOTE||g(t)===d.GT}function y(t){var r=[];return r.push.apply(r,function(t){var e=[],r=t.projectId,n=t.loadTranslations;switch(p(t)){case u.REMOTE:case u.GT_REMOTE:r||e.push({type:"warning",message:"projectId is required when loading translations from a remote store"});break;case u.CUSTOM:n||e.push({type:"error",message:"loadTranslations is required when loading translations from a custom loader"});case u.DISABLED:}return e}(t)),r.push.apply(r,function(t){var e=[];switch(g(t)){case d.CUSTOM:case d.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 d.DISABLED:}return e}(t)),r.push.apply(r,function(t){var r=[];if(!v(t))return r;var n=t.defaultLocale,o=t.locales,a=t.customMapping;return new Set(c(c([],n?[n]:[],!0),o||[],!0)).forEach(function(t){e.isValidLocale(t,a)||r.push({type:"error",message:"Invalid locale: ".concat(t)})}),r}(t)),r}!function(t){t.GT="gt",t.CUSTOM="custom",t.DISABLED="disabled"}(d||(d={}));var m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="fallback-storage-adapter",e.storage={},e}return function(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)}(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 b(e,n){return r.hashSource(o(o(o(o({source:t.indexVars(e)},(null==n?void 0:n.$context)&&{context:n.$context}),(null==n?void 0:n.$id)&&{id:n.$id}),null!=(null==n?void 0:n.$maxChars)&&{maxChars:Math.abs(n.$maxChars)}),{dataFormat:(null==n?void 0:n.$format)||"ICU"}))}var L=function(){function r(r){var n,a,i,u,f=this;this.resolveTranslationSync=function(t,e){var r=f.getLocale(),n=f.translationsManager.getTranslationsSync(r);if(n)return n[b(t,e)]},function(t,e,r){if(void 0===r&&(r=!0),t.forEach(function(t){switch(t.type){case"error":l(e+t.message);break;case"warning":s(e+t.message)}}),r&&t.some(function(t){return"error"===t.type}))throw new Error("Validation errors occurred")}(y(r),"I18nManager: "),this.config=(i=v(a=r),u=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({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,o,a,i;return("string"==typeof(null===(n=t.customMapping)||void 0===n?void 0:n[r])?null===(o=t.customMapping)||void 0===o?void 0:o[r]:null===(i=null===(a=t.customMapping)||void 0===a?void 0:a[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}}(u):u)),this.storeAdapter=null!==(n=r.storeAdapter)&&void 0!==n?n:new m,this.translationsManager=new h(r)}return r.prototype.getAdapterType=function(){return this.storeAdapter.type},r.prototype.getLocale=function(){var t=this.storeAdapter.getItem("locale");return t||(s("getLocale() invoked outside of translation context, falling back to default locale"),this.config.defaultLocale)},r.prototype.setLocale=function(t){this.storeAdapter.setItem("locale",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 new e.GT({sourceLocale:this.config.defaultLocale,targetLocale:this.getLocale(),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.prototype.isTranslationEnabled=function(){return this.config.enableI18n},r.prototype.getTranslationLoader=function(){return this.translationsManager.getTranslationLoader()},r.prototype.getTranslations=function(){return a(this,arguments,void 0,function(t){return void 0===t&&(t=this.getLocale()),i(this,function(e){if(!this.config.locales.includes(t))throw new Error("Locale ".concat(t," not found in config"));return[2,this.translationsManager.getTranslations(t)]})})},r.prototype.getTranslationResolver=function(){return a(this,arguments,void 0,function(t){var e;return void 0===t&&(t=this.getLocale()),i(this,function(r){switch(r.label){case 0:return!1===this.config.enableI18n||t===this.config.defaultLocale?[2,function(t){return t}]:[4,this.translationsManager.getTranslations(t)];case 1:return e=r.sent(),[2,function(t,r){var n=b(t,r);return e[n]}]}})})},r.prototype.requiresTranslation=function(t){void 0===t&&(t=this.getLocale());var e=this.getDefaultLocale(),r=this.getGTClass(),n=this.getLocales();return this.config.enableI18n&&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}();var T=void 0;function I(){return T||(s("getI18nManager(): Translation failed because I18nManager not initialized."),T=new L({defaultLocale:t.libraryDefaultLocale,locales:[t.libraryDefaultLocale]})),T}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}))}var M=function(t){return'String interpolation failed for message: "'.concat(t,'".')};function w(r,n){var a;if(!r)return r;var i=n.$_fallback,c=E(n);try{var l=t.extractVars(i||""),u=function(t,r,n,o){try{return e.formatMessage(t,{variables:r,locales:n,dataFormat:o})}catch(e){return s(M(t)),t}}(Object.keys(l).length?t.condenseVars(r):r,o(o(o({},c),l),((a={})[t.VAR_IDENTIFIER]="other",a)),n.$_locales,n.$format);return e.formatCutoff(u,{maxChars:n.$maxChars})}catch(t){return s(M(r)),null!=i?w(i,o(o({},n),{$_fallback:void 0})):e.formatCutoff(r,{maxChars:n.$maxChars})}}function x(t){return"string"==typeof t&&-1!==t.lastIndexOf(":")?t.slice(0,t.lastIndexOf(":")):t}function O(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=x,exports.decodeOptions=O,exports.getDefaultLocale=function(){return I().getDefaultLocale()},exports.getLocale=function(){return I().getLocale()},exports.getLocaleProperties=function(t){return I().getGTClass().getLocaleProperties(t)},exports.getLocales=function(){return I().getLocales()},exports.getVersionId=function(){return I().getVersionId()},exports.gtFallback=function(t,e){return void 0===e&&(e={}),w(t,e)},exports.mFallback=function(t,e){var r;return void 0===e&&(e={}),t?function(t){return!(!t.$_hash||!t.$_source)}(null!==(r=O(t))&&void 0!==r?r:{})?x(t):w(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 c=E(a),l=n;try{l=e.formatMessage(n,{locales:[t.libraryDefaultLocale],variables:o(o({},c),(i={},i[t.VAR_IDENTIFIER]="other",i))})}catch(t){return s(M(n)),n}var u=n,f=a.$_hash||b(n,a),p=o(o({},a),{$_source:u,$_hash:f}),d=t.encode(JSON.stringify(p));return"".concat(l,":").concat(d)},exports.t=function(t,e){void 0===e&&(e={});var r=function(t,e){void 0===e&&(e={});var r=I(),n=r.resolveTranslationSync(t,e);if(n)return w(n,o(o({$_locales:r.getLocale()},e),{$_fallback:t}))}(t,e);if(r)return r;var n=I();return w(t,o(o({$_locales:n.getDefaultLocale()},e),{$_fallback:t}))};
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)};var o=function(){return o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},o.apply(this,arguments)};function a(t,e,r,n){return new(r||(r=Promise))(function(o,a){function i(t){try{s(n.next(t))}catch(t){a(t)}}function c(t){try{s(n.throw(t))}catch(t){a(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(i,c)}s((n=n.apply(t,e||[])).next())})}function i(t,e){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(s){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=e.call(t,a)}catch(t){c=[6,t],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,s])}}}function c(t,e,r){if(r||2===arguments.length)for(var n,o=0,a=e.length;o<a;o++)!n&&o in e||(n||(n=Array.prototype.slice.call(e,0,o)),n[o]=e[o]);return t.concat(n||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var s=function(t){console.warn(t)},l=function(t){console.error(t)};var u;function f(r){var n=this,o=function(e){var r=e.cacheUrl,n=void 0===r?t.defaultCacheUrl:r,o=e.projectId,a=e._versionId,i=e._branchId,c=a?"/".concat(a):"",s=i?"?branchId=".concat(i):"";return"".concat(n,"/").concat(o,"/[locale]")+c+s}(r);return function(t){return a(n,void 0,void 0,function(){var n,a;return i(this,function(i){switch(i.label){case 0:return t=e.resolveCanonicalLocale(t,r.customMapping),n=o.replace("[locale]",t),[4,fetch(n)];case 1:if(!(a=i.sent()).ok)throw new Error("Failed to load translations from ".concat(n));return[4,a.json()];case 2:return[2,i.sent()]}})})}}function p(e){return e.loadTranslations?u.CUSTOM:e.cacheUrl?u.REMOTE:void 0!==e.cacheUrl&&e.cacheUrl!==t.defaultCacheUrl||!e.projectId?u.DISABLED:u.GT_REMOTE}!function(t){t.GT_REMOTE="gt-remote",t.REMOTE="remote",t.CUSTOM="custom",t.DISABLED="disabled"}(u||(u={}));var d,h=function(){function t(t){var e;this.cache=new Map,this.resolvedCache=new Map,this.translationEntryTTL=null===t.cacheExpiryTime?-1:null!==(e=t.cacheExpiryTime)&&void 0!==e?e:6e4;var r=function(t){var e=p(t);e===u.DISABLED&&s("I18nManager: No translation loader found. No translations will be loaded.");switch(e){case u.REMOTE:case u.GT_REMOTE:return f({cacheUrl:t.cacheUrl,projectId:t.projectId,_versionId:t._versionId,_branchId:t._branchId,customMapping:t.customMapping});case u.CUSTOM:return t.loadTranslations;case u.DISABLED:return function(){var t=this;return function(e){return a(t,void 0,void 0,function(){return i(this,function(t){return[2,{}]})})}}()}}(t);this.translationLoader=this.attachResolveCaptureToTranslationLoader(this.protectTranslationLoader(r))}return t.prototype.protectTranslationLoader=function(t){var e=this;return function(r){return a(e,void 0,void 0,function(){var e;return i(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,t(r)];case 1:return[2,n.sent()||{}];case 2:return e=n.sent(),l("Failed to load translations "+e),this.cache.delete(r),[2,{}];case 3:return[2]}})})}},t.prototype.attachResolveCaptureToTranslationLoader=function(t){var e=this;return function(r){return a(e,void 0,void 0,function(){var e;return i(this,function(n){switch(n.label){case 0:return[4,t(r)];case 1:return e=n.sent(),this.resolvedCache.set(r,e),[2,e]}})})}},t.prototype.handleCacheMiss=function(t){return a(this,void 0,void 0,function(){var e,r,n;return i(this,function(o){return e=this.translationLoader(t),r=this.translationEntryTTL<0?this.translationEntryTTL:Date.now()+this.translationEntryTTL,n={promise:e,expiresAt:r},this.cache.set(t,n),[2,e]})})},t.prototype.isCacheHit=function(t){if(!this.cache.has(t))return!1;var e=this.cache.get(t).expiresAt;return e<0||e>Date.now()},t.prototype.getTranslations=function(t){return a(this,void 0,void 0,function(){return i(this,function(e){return this.isCacheHit(t)?[2,this.cache.get(t).promise]:[2,this.handleCacheMiss(t)]})})},t.prototype.getTranslationsSync=function(t){return this.resolvedCache.get(t)},t.prototype.getTranslationLoader=function(){return this.translationLoader},t}();function g(e){return void 0!==e.runtimeUrl&&e.runtimeUrl!==t.defaultRuntimeApiUrl||!e.projectId||!e.devApiKey&&!e.apiKey?e.runtimeUrl?d.CUSTOM:d.DISABLED:d.GT}function v(t){return p(t)===u.GT_REMOTE||g(t)===d.GT}function y(t){var r=[];return r.push.apply(r,function(t){var e=[],r=t.projectId,n=t.loadTranslations;switch(p(t)){case u.REMOTE:case u.GT_REMOTE:r||e.push({type:"warning",message:"projectId is required when loading translations from a remote store"});break;case u.CUSTOM:n||e.push({type:"error",message:"loadTranslations is required when loading translations from a custom loader"});case u.DISABLED:}return e}(t)),r.push.apply(r,function(t){var e=[];switch(g(t)){case d.CUSTOM:case d.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 d.DISABLED:}return e}(t)),r.push.apply(r,function(t){var r=[];if(!v(t))return r;var n=t.defaultLocale,o=t.locales,a=t.customMapping;return new Set(c(c([],n?[n]:[],!0),o||[],!0)).forEach(function(t){e.isValidLocale(t,a)||r.push({type:"error",message:"Invalid locale: ".concat(t)})}),r}(t)),r}!function(t){t.GT="gt",t.CUSTOM="custom",t.DISABLED="disabled"}(d||(d={}));var m=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.type="fallback-storage-adapter",e.storage={},e}return function(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)}(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 b(e,n){return r.hashSource(o(o(o(o({source:"JSX"===n.$format?e:t.indexVars(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(){function r(r){var n,a,i,u,f=this;this.resolveTranslationSync=function(t,e){var r=f.getLocale(),n=f.translationsManager.getTranslationsSync(r);if(n)return n[b(t,e)]},function(t,e,r){if(void 0===r&&(r=!0),t.forEach(function(t){switch(t.type){case"error":l(e+t.message);break;case"warning":s(e+t.message)}}),r&&t.some(function(t){return"error"===t.type}))throw new Error("Validation errors occurred")}(y(r),"I18nManager: "),this.config=(i=v(a=r),u=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({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,o,a,i;return("string"==typeof(null===(n=t.customMapping)||void 0===n?void 0:n[r])?null===(o=t.customMapping)||void 0===o?void 0:o[r]:null===(i=null===(a=t.customMapping)||void 0===a?void 0:a[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}}(u):u)),this.storeAdapter=null!==(n=r.storeAdapter)&&void 0!==n?n:new m,this.translationsManager=new h(r)}return r.prototype.getAdapterType=function(){return this.storeAdapter.type},r.prototype.getLocale=function(){var t=this.storeAdapter.getItem("locale");return t||(s("getLocale() invoked outside of translation context, falling back to default locale"),this.config.defaultLocale)},r.prototype.setLocale=function(t){this.storeAdapter.setItem("locale",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 new e.GT({sourceLocale:this.config.defaultLocale,targetLocale:this.getLocale(),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.prototype.isTranslationEnabled=function(){return this.config.enableI18n},r.prototype.getTranslationLoader=function(){return this.translationsManager.getTranslationLoader()},r.prototype.getTranslations=function(){return a(this,arguments,void 0,function(t){return void 0===t&&(t=this.getLocale()),i(this,function(e){if(!this.config.locales.includes(t))throw new Error("Locale ".concat(t," not found in config"));return[2,this.translationsManager.getTranslations(t)]})})},r.prototype.getTranslationResolver=function(){return a(this,arguments,void 0,function(t){var e;return void 0===t&&(t=this.getLocale()),i(this,function(r){switch(r.label){case 0:return!1===this.config.enableI18n||t===this.config.defaultLocale?[2,function(t){return t}]:[4,this.translationsManager.getTranslations(t)];case 1:return e=r.sent(),[2,function(t,r){var n=b(t,r);return e[n]}]}})})},r.prototype.requiresTranslation=function(t){void 0===t&&(t=this.getLocale());var e=this.getDefaultLocale(),r=this.getGTClass(),n=this.getLocales();return this.config.enableI18n&&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}();var T=void 0;function I(){return T||(s("getI18nManager(): Translation failed because I18nManager not initialized."),T=new L({defaultLocale:t.libraryDefaultLocale,locales:[t.libraryDefaultLocale]})),T}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}))}var M=function(t){return'String interpolation failed for message: "'.concat(t,'".')};function w(r,n){var a;if(!r)return r;var i=n.$_fallback,c=E(n);try{var l=t.extractVars(i||""),u=function(t,r,n,o){try{return e.formatMessage(t,{variables:r,locales:n,dataFormat:o})}catch(e){return s(M(t)),t}}(Object.keys(l).length?t.condenseVars(r):r,o(o(o({},c),l),((a={})[t.VAR_IDENTIFIER]="other",a)),n.$_locales,n.$format);return e.formatCutoff(u,{maxChars:n.$maxChars})}catch(t){return s(M(r)),null!=i?w(i,o(o({},n),{$_fallback:void 0})):e.formatCutoff(r,{maxChars:n.$maxChars})}}function x(t){return"string"==typeof t&&-1!==t.lastIndexOf(":")?t.slice(0,t.lastIndexOf(":")):t}function O(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=x,exports.decodeOptions=O,exports.getDefaultLocale=function(){return I().getDefaultLocale()},exports.getLocale=function(){return I().getLocale()},exports.getLocaleProperties=function(t){return I().getGTClass().getLocaleProperties(t)},exports.getLocales=function(){return I().getLocales()},exports.getVersionId=function(){return I().getVersionId()},exports.gtFallback=function(t,e){return void 0===e&&(e={}),w(t,e)},exports.mFallback=function(t,e){var r;return void 0===e&&(e={}),t?function(t){return!(!t.$_hash||!t.$_source)}(null!==(r=O(t))&&void 0!==r?r:{})?x(t):w(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 c=E(a),l=n;try{l=e.formatMessage(n,{locales:[t.libraryDefaultLocale],variables:o(o({},c),(i={},i[t.VAR_IDENTIFIER]="other",i))})}catch(t){return s(M(n)),n}var u=n,f=a.$_hash||b(n,o({$format:"ICU"},a)),p=o(o({},a),{$_source:u,$_hash:f}),d=t.encode(JSON.stringify(p));return"".concat(l,":").concat(d)},exports.t=function(t,e){void 0===e&&(e={});var r=function(t,e){void 0===e&&(e={});var r=I(),n=r.resolveTranslationSync(t,o({$format:"ICU"},e));if(n)return w(n,o(o({$_locales:r.getLocale()},e),{$_fallback:t}))}(t,e);if(r)return r;var n=I();return w(t,o(o({$_locales:n.getDefaultLocale()},e),{$_fallback:t}))};
2
2
  //# sourceMappingURL=index.cjs.min.cjs.map