@tolgee/core 5.0.0-alpha.1 → 5.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -0
- package/README.njk.md +61 -0
- package/dist/tolgee.cjs.js +185 -143
- package/dist/tolgee.cjs.js.map +1 -1
- package/dist/tolgee.cjs.min.js +1 -1
- package/dist/tolgee.cjs.min.js.map +1 -1
- package/dist/tolgee.esm.js +185 -143
- package/dist/tolgee.esm.js.map +1 -1
- package/dist/tolgee.esm.min.mjs +1 -1
- package/dist/tolgee.esm.min.mjs.map +1 -1
- package/dist/tolgee.umd.js +185 -143
- package/dist/tolgee.umd.js.map +1 -1
- package/dist/tolgee.umd.min.js +1 -1
- package/dist/tolgee.umd.min.js.map +1 -1
- package/lib/Controller/Controller.d.ts +8 -4
- package/lib/Controller/Events/EventEmitter.d.ts +1 -1
- package/lib/Controller/Events/EventEmitterSelective.d.ts +1 -1
- package/lib/Controller/Events/Events.d.ts +1 -0
- package/lib/Controller/Plugins/Plugins.d.ts +4 -4
- package/lib/Controller/State/State.d.ts +2 -1
- package/lib/Controller/State/initState.d.ts +13 -2
- package/lib/{Tolgee.d.ts → TolgeeCore.d.ts} +13 -4
- package/lib/helpers.d.ts +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/types/events.d.ts +2 -2
- package/lib/types/index.d.ts +1 -1
- package/lib/types/plugin.d.ts +6 -9
- package/package.json +2 -2
- package/src/Controller/Controller.ts +5 -4
- package/src/Controller/Events/EventEmitter.ts +6 -2
- package/src/Controller/Events/EventEmitterSelective.test.ts +23 -0
- package/src/Controller/Events/EventEmitterSelective.ts +8 -5
- package/src/Controller/Events/Events.ts +19 -8
- package/src/Controller/Plugins/Plugins.ts +66 -63
- package/src/Controller/State/initState.ts +16 -1
- package/src/{Tolgee.ts → TolgeeCore.ts} +12 -3
- package/src/__test/backend.test.ts +2 -2
- package/src/__test/cache.test.ts +6 -3
- package/src/__test/client.test.ts +2 -2
- package/src/__test/events.test.ts +30 -5
- package/src/__test/format.simple.test.ts +2 -14
- package/src/__test/formatError.test.ts +61 -0
- package/src/__test/initialization.test.ts +4 -4
- package/src/__test/languageDetection.test.ts +8 -8
- package/src/__test/languageStorage.test.ts +10 -11
- package/src/__test/languages.test.ts +8 -8
- package/src/__test/loading.test.ts +2 -2
- package/src/__test/namespaces.fallback.test.ts +5 -5
- package/src/__test/namespaces.test.ts +4 -4
- package/src/__test/options.test.ts +3 -3
- package/src/__test/plugins.test.ts +4 -4
- package/src/helpers.ts +8 -0
- package/src/index.ts +1 -1
- package/src/types/events.ts +2 -2
- package/src/types/index.ts +1 -1
- package/src/types/plugin.ts +12 -12
package/dist/tolgee.cjs.js
CHANGED
|
@@ -43,8 +43,16 @@ function unique(arr) {
|
|
|
43
43
|
function sanitizeUrl(url) {
|
|
44
44
|
return url ? url.replace(/\/+$/, '') : url;
|
|
45
45
|
}
|
|
46
|
+
function getErrorMessage(error) {
|
|
47
|
+
if (typeof error === 'string') {
|
|
48
|
+
return error;
|
|
49
|
+
}
|
|
50
|
+
else if (typeof (error === null || error === void 0 ? void 0 : error.message) === 'string') {
|
|
51
|
+
return error.message;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
46
54
|
|
|
47
|
-
const EventEmitter = () => {
|
|
55
|
+
const EventEmitter = (isActive) => {
|
|
48
56
|
let handlers = [];
|
|
49
57
|
const listen = (handler) => {
|
|
50
58
|
const handlerWrapper = (e) => {
|
|
@@ -58,12 +66,14 @@ const EventEmitter = () => {
|
|
|
58
66
|
};
|
|
59
67
|
};
|
|
60
68
|
const emit = (data) => {
|
|
61
|
-
|
|
69
|
+
if (isActive()) {
|
|
70
|
+
handlers.forEach((handler) => handler({ value: data }));
|
|
71
|
+
}
|
|
62
72
|
};
|
|
63
73
|
return Object.freeze({ listen, emit });
|
|
64
74
|
};
|
|
65
75
|
|
|
66
|
-
const EventEmitterSelective = (getFallbackNs, getDefaultNs) => {
|
|
76
|
+
const EventEmitterSelective = (isActive, getFallbackNs, getDefaultNs) => {
|
|
67
77
|
const listeners = new Set();
|
|
68
78
|
const partialListeners = new Set();
|
|
69
79
|
const listen = (handler) => {
|
|
@@ -137,26 +147,32 @@ const EventEmitterSelective = (getFallbackNs, getDefaultNs) => {
|
|
|
137
147
|
callHandlers(namespacesArray);
|
|
138
148
|
};
|
|
139
149
|
const emit = (ns, delayed) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
150
|
+
if (isActive()) {
|
|
151
|
+
queue.push(ns);
|
|
152
|
+
if (!delayed) {
|
|
153
|
+
solveQueue();
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
setTimeout(solveQueue, 0);
|
|
157
|
+
}
|
|
146
158
|
}
|
|
147
159
|
};
|
|
148
160
|
return Object.freeze({ listenSome, listen, emit });
|
|
149
161
|
};
|
|
150
162
|
|
|
151
163
|
const Events = (getFallbackNs, getDefaultNs) => {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
164
|
+
let emitterActive = true;
|
|
165
|
+
function isActive() {
|
|
166
|
+
return emitterActive;
|
|
167
|
+
}
|
|
168
|
+
const onPendingLanguageChange = EventEmitter(isActive);
|
|
169
|
+
const onLanguageChange = EventEmitter(isActive);
|
|
170
|
+
const onLoadingChange = EventEmitter(isActive);
|
|
171
|
+
const onFetchingChange = EventEmitter(isActive);
|
|
172
|
+
const onInitialLoaded = EventEmitter(isActive);
|
|
173
|
+
const onRunningChange = EventEmitter(isActive);
|
|
174
|
+
const onCacheChange = EventEmitter(isActive);
|
|
175
|
+
const onUpdate = EventEmitterSelective(isActive, getFallbackNs, getDefaultNs);
|
|
160
176
|
onInitialLoaded.listen(() => onUpdate.emit());
|
|
161
177
|
onLanguageChange.listen(() => onUpdate.emit());
|
|
162
178
|
onCacheChange.listen(({ value }) => {
|
|
@@ -182,6 +198,9 @@ const Events = (getFallbackNs, getDefaultNs) => {
|
|
|
182
198
|
return onUpdate.listen(handler);
|
|
183
199
|
}
|
|
184
200
|
};
|
|
201
|
+
function setEmmiterActive(active) {
|
|
202
|
+
emitterActive = active;
|
|
203
|
+
}
|
|
185
204
|
return Object.freeze({
|
|
186
205
|
onPendingLanguageChange,
|
|
187
206
|
onLanguageChange,
|
|
@@ -191,6 +210,7 @@ const Events = (getFallbackNs, getDefaultNs) => {
|
|
|
191
210
|
onRunningChange,
|
|
192
211
|
onCacheChange,
|
|
193
212
|
onUpdate,
|
|
213
|
+
setEmmiterActive,
|
|
194
214
|
on,
|
|
195
215
|
});
|
|
196
216
|
};
|
|
@@ -430,9 +450,78 @@ const Cache = (onCacheChange, backendGetRecord, backendGetDevRecord, withDefault
|
|
|
430
450
|
});
|
|
431
451
|
};
|
|
432
452
|
|
|
453
|
+
/******************************************************************************
|
|
454
|
+
Copyright (c) Microsoft Corporation.
|
|
455
|
+
|
|
456
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
457
|
+
purpose with or without fee is hereby granted.
|
|
458
|
+
|
|
459
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
460
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
461
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
462
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
463
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
464
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
465
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
466
|
+
***************************************************************************** */
|
|
467
|
+
|
|
468
|
+
function __rest(s, e) {
|
|
469
|
+
var t = {};
|
|
470
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
471
|
+
t[p] = s[p];
|
|
472
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
473
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
474
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
475
|
+
t[p[i]] = s[p[i]];
|
|
476
|
+
}
|
|
477
|
+
return t;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const defaultObserverOptions = {
|
|
481
|
+
tagAttributes: {
|
|
482
|
+
textarea: ['placeholder'],
|
|
483
|
+
input: ['value', 'placeholder'],
|
|
484
|
+
img: ['alt'],
|
|
485
|
+
'*': ['aria-label', 'title'],
|
|
486
|
+
},
|
|
487
|
+
restrictedElements: ['script', 'style'],
|
|
488
|
+
highlightKeys: ['Alt'],
|
|
489
|
+
highlightColor: 'rgb(255, 0, 0)',
|
|
490
|
+
highlightWidth: 5,
|
|
491
|
+
inputPrefix: '%-%tolgee:',
|
|
492
|
+
inputSuffix: '%-%',
|
|
493
|
+
passToParent: ['option', 'optgroup'],
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
const DEFAULT_FORMAT_ERROR = 'invalid';
|
|
497
|
+
const defaultValues = {
|
|
498
|
+
defaultNs: '',
|
|
499
|
+
observerOptions: defaultObserverOptions,
|
|
500
|
+
observerType: 'invisible',
|
|
501
|
+
onFormatError: DEFAULT_FORMAT_ERROR,
|
|
502
|
+
};
|
|
503
|
+
const combineOptions = (...states) => {
|
|
504
|
+
let result = {};
|
|
505
|
+
states.forEach((state) => {
|
|
506
|
+
result = Object.assign(Object.assign(Object.assign({}, result), state), { observerOptions: Object.assign(Object.assign({}, result.observerOptions), state === null || state === void 0 ? void 0 : state.observerOptions) });
|
|
507
|
+
});
|
|
508
|
+
return result;
|
|
509
|
+
};
|
|
510
|
+
const initState = (options, previousState) => {
|
|
511
|
+
const initialOptions = combineOptions(defaultValues, previousState === null || previousState === void 0 ? void 0 : previousState.initialOptions, options);
|
|
512
|
+
// remove extra '/' from url end
|
|
513
|
+
initialOptions.apiUrl = sanitizeUrl(initialOptions.apiUrl);
|
|
514
|
+
return {
|
|
515
|
+
initialOptions,
|
|
516
|
+
activeNamespaces: (previousState === null || previousState === void 0 ? void 0 : previousState.activeNamespaces) || new Map(),
|
|
517
|
+
language: previousState === null || previousState === void 0 ? void 0 : previousState.language,
|
|
518
|
+
pendingLanguage: previousState === null || previousState === void 0 ? void 0 : previousState.language,
|
|
519
|
+
isInitialLoading: false,
|
|
520
|
+
isRunning: false,
|
|
521
|
+
};
|
|
522
|
+
};
|
|
523
|
+
|
|
433
524
|
const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTranslationNs, getTranslation, changeTranslation) => {
|
|
434
|
-
let prepared = false;
|
|
435
|
-
let onPrepareQueue = [];
|
|
436
525
|
const plugins = {
|
|
437
526
|
ui: undefined,
|
|
438
527
|
observer: undefined,
|
|
@@ -493,7 +582,7 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
493
582
|
instances.finalFormatter = formatter;
|
|
494
583
|
};
|
|
495
584
|
const setUi = (ui) => {
|
|
496
|
-
plugins.ui =
|
|
585
|
+
plugins.ui = ui;
|
|
497
586
|
};
|
|
498
587
|
const hasUi = () => {
|
|
499
588
|
return Boolean(plugins.ui);
|
|
@@ -501,6 +590,9 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
501
590
|
const setLanguageStorage = (storage) => {
|
|
502
591
|
instances.languageStorage = storage;
|
|
503
592
|
};
|
|
593
|
+
const getLanguageStorage = () => {
|
|
594
|
+
return instances.languageStorage;
|
|
595
|
+
};
|
|
504
596
|
const setStoredLanguage = (language) => {
|
|
505
597
|
var _a;
|
|
506
598
|
(_a = instances.languageStorage) === null || _a === void 0 ? void 0 : _a.setLanguage(language);
|
|
@@ -540,11 +632,11 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
540
632
|
const setDevBackend = (backend) => {
|
|
541
633
|
instances.devBackend = backend;
|
|
542
634
|
};
|
|
543
|
-
const run = (
|
|
544
|
-
var _a, _b;
|
|
545
|
-
if (!instances.ui
|
|
635
|
+
const run = () => {
|
|
636
|
+
var _a, _b, _c;
|
|
637
|
+
if (!instances.ui) {
|
|
546
638
|
const { apiKey, apiUrl, projectId } = getInitialOptions();
|
|
547
|
-
instances.ui =
|
|
639
|
+
instances.ui = (_a = plugins.ui) === null || _a === void 0 ? void 0 : _a.call(plugins, {
|
|
548
640
|
apiKey: apiKey,
|
|
549
641
|
apiUrl: apiUrl,
|
|
550
642
|
projectId,
|
|
@@ -553,13 +645,13 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
553
645
|
});
|
|
554
646
|
}
|
|
555
647
|
if (!instances.observer) {
|
|
556
|
-
instances.observer = (
|
|
648
|
+
instances.observer = (_b = plugins.observer) === null || _b === void 0 ? void 0 : _b.call(plugins, {
|
|
557
649
|
translate,
|
|
558
650
|
onClick,
|
|
559
651
|
options: getInitialOptions().observerOptions,
|
|
560
652
|
});
|
|
561
653
|
}
|
|
562
|
-
(
|
|
654
|
+
(_c = instances.observer) === null || _c === void 0 ? void 0 : _c.run({ mouseHighlight: true });
|
|
563
655
|
};
|
|
564
656
|
const getDevBackend = () => {
|
|
565
657
|
return instances.devBackend;
|
|
@@ -602,9 +694,6 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
602
694
|
var _a;
|
|
603
695
|
(_a = instances.observer) === null || _a === void 0 ? void 0 : _a.retranslate();
|
|
604
696
|
};
|
|
605
|
-
const onPrepare = (callback) => {
|
|
606
|
-
onPrepareQueue.push(callback);
|
|
607
|
-
};
|
|
608
697
|
function addPlugin(tolgeeInstance, plugin) {
|
|
609
698
|
const pluginTools = Object.freeze({
|
|
610
699
|
setFinalFormatter,
|
|
@@ -617,46 +706,68 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
617
706
|
addBackend,
|
|
618
707
|
setLanguageDetector,
|
|
619
708
|
setLanguageStorage,
|
|
620
|
-
onPrepare,
|
|
621
709
|
});
|
|
622
710
|
plugin(tolgeeInstance, pluginTools);
|
|
623
|
-
if (prepared) {
|
|
624
|
-
prepare();
|
|
625
|
-
}
|
|
626
711
|
}
|
|
627
|
-
function formatTranslation(
|
|
628
|
-
var
|
|
712
|
+
function formatTranslation(_a) {
|
|
713
|
+
var _b;
|
|
714
|
+
var { formatEnabled } = _a, props = __rest(_a, ["formatEnabled"]);
|
|
715
|
+
const { key, translation, defaultValue, noWrap, params, orEmpty, ns } = props;
|
|
629
716
|
const formattableTranslation = translation || defaultValue;
|
|
630
717
|
let result = formattableTranslation || (orEmpty ? '' : key);
|
|
631
|
-
if (instances.observer && !noWrap) {
|
|
632
|
-
result = instances.observer.wrap({
|
|
633
|
-
key,
|
|
634
|
-
translation: result,
|
|
635
|
-
defaultValue,
|
|
636
|
-
params,
|
|
637
|
-
ns,
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
718
|
const language = getLanguage();
|
|
641
|
-
const isFormatEnabled = formatEnabled || !((
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
719
|
+
const isFormatEnabled = formatEnabled || !((_b = instances.observer) === null || _b === void 0 ? void 0 : _b.outputNotFormattable);
|
|
720
|
+
const wrap = (result) => {
|
|
721
|
+
if (instances.observer && !noWrap) {
|
|
722
|
+
return instances.observer.wrap({
|
|
723
|
+
key,
|
|
724
|
+
translation: result,
|
|
725
|
+
defaultValue,
|
|
726
|
+
params,
|
|
727
|
+
ns,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
return result;
|
|
731
|
+
};
|
|
732
|
+
result = wrap(result);
|
|
733
|
+
try {
|
|
734
|
+
if (formattableTranslation && language && isFormatEnabled) {
|
|
735
|
+
for (const formatter of instances.formatters) {
|
|
736
|
+
result = formatter.format({
|
|
737
|
+
translation: result,
|
|
738
|
+
language,
|
|
739
|
+
params,
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (instances.finalFormatter &&
|
|
744
|
+
formattableTranslation &&
|
|
745
|
+
language &&
|
|
746
|
+
isFormatEnabled) {
|
|
747
|
+
result = instances.finalFormatter.format({
|
|
645
748
|
translation: result,
|
|
646
749
|
language,
|
|
647
750
|
params,
|
|
648
751
|
});
|
|
649
752
|
}
|
|
650
753
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
}
|
|
754
|
+
catch (e) {
|
|
755
|
+
// eslint-disable-next-line no-console
|
|
756
|
+
console.error(e);
|
|
757
|
+
const errorMessage = getErrorMessage(e) || DEFAULT_FORMAT_ERROR;
|
|
758
|
+
const onFormatError = getInitialOptions().onFormatError;
|
|
759
|
+
const formatErrorType = typeof onFormatError;
|
|
760
|
+
if (formatErrorType === 'string') {
|
|
761
|
+
result = onFormatError;
|
|
762
|
+
}
|
|
763
|
+
else if (formatErrorType === 'function') {
|
|
764
|
+
result = onFormatError(errorMessage, props);
|
|
765
|
+
}
|
|
766
|
+
else {
|
|
767
|
+
result = DEFAULT_FORMAT_ERROR;
|
|
768
|
+
}
|
|
769
|
+
// wrap error message, so it's detectable
|
|
770
|
+
result = wrap(result);
|
|
660
771
|
}
|
|
661
772
|
return result;
|
|
662
773
|
}
|
|
@@ -670,22 +781,14 @@ const Plugins = (getLanguage, getInitialOptions, getAvailableLanguages, getTrans
|
|
|
670
781
|
}
|
|
671
782
|
return params.translation;
|
|
672
783
|
};
|
|
673
|
-
function prepare() {
|
|
674
|
-
prepared = true;
|
|
675
|
-
while (onPrepareQueue.length) {
|
|
676
|
-
const queue = onPrepareQueue;
|
|
677
|
-
onPrepareQueue = [];
|
|
678
|
-
queue.forEach((callback) => callback());
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
784
|
return Object.freeze({
|
|
682
|
-
prepare,
|
|
683
785
|
addPlugin,
|
|
684
786
|
formatTranslation,
|
|
685
787
|
getDevBackend,
|
|
686
788
|
getBackendRecord,
|
|
687
789
|
getBackendDevRecord,
|
|
688
790
|
getLanguageDetector,
|
|
791
|
+
getLanguageStorage,
|
|
689
792
|
getInitialLanguage,
|
|
690
793
|
setStoredLanguage,
|
|
691
794
|
run,
|
|
@@ -716,48 +819,6 @@ const ValueObserver = (initialValue, valueGetter, handler) => {
|
|
|
716
819
|
});
|
|
717
820
|
};
|
|
718
821
|
|
|
719
|
-
const defaultObserverOptions = {
|
|
720
|
-
tagAttributes: {
|
|
721
|
-
textarea: ['placeholder'],
|
|
722
|
-
input: ['value', 'placeholder'],
|
|
723
|
-
img: ['alt'],
|
|
724
|
-
'*': ['aria-label', 'title'],
|
|
725
|
-
},
|
|
726
|
-
restrictedElements: ['script', 'style'],
|
|
727
|
-
highlightKeys: ['Alt'],
|
|
728
|
-
highlightColor: 'rgb(255, 0, 0)',
|
|
729
|
-
highlightWidth: 5,
|
|
730
|
-
inputPrefix: '%-%tolgee:',
|
|
731
|
-
inputSuffix: '%-%',
|
|
732
|
-
passToParent: ['option', 'optgroup'],
|
|
733
|
-
};
|
|
734
|
-
|
|
735
|
-
const defaultValues = {
|
|
736
|
-
defaultNs: '',
|
|
737
|
-
observerOptions: defaultObserverOptions,
|
|
738
|
-
observerType: 'invisible',
|
|
739
|
-
};
|
|
740
|
-
const combineOptions = (...states) => {
|
|
741
|
-
let result = {};
|
|
742
|
-
states.forEach((state) => {
|
|
743
|
-
result = Object.assign(Object.assign(Object.assign({}, result), state), { observerOptions: Object.assign(Object.assign({}, result.observerOptions), state === null || state === void 0 ? void 0 : state.observerOptions) });
|
|
744
|
-
});
|
|
745
|
-
return result;
|
|
746
|
-
};
|
|
747
|
-
const initState = (options, previousState) => {
|
|
748
|
-
const initialOptions = combineOptions(defaultValues, previousState === null || previousState === void 0 ? void 0 : previousState.initialOptions, options);
|
|
749
|
-
// remove extra '/' from url end
|
|
750
|
-
initialOptions.apiUrl = sanitizeUrl(initialOptions.apiUrl);
|
|
751
|
-
return {
|
|
752
|
-
initialOptions,
|
|
753
|
-
activeNamespaces: (previousState === null || previousState === void 0 ? void 0 : previousState.activeNamespaces) || new Map(),
|
|
754
|
-
language: previousState === null || previousState === void 0 ? void 0 : previousState.language,
|
|
755
|
-
pendingLanguage: previousState === null || previousState === void 0 ? void 0 : previousState.language,
|
|
756
|
-
isInitialLoading: false,
|
|
757
|
-
isRunning: false,
|
|
758
|
-
};
|
|
759
|
-
};
|
|
760
|
-
|
|
761
822
|
const State = (onLanguageChange, onPendingLanguageChange, onRunningChange) => {
|
|
762
823
|
let state = initState();
|
|
763
824
|
let devCredentials = undefined;
|
|
@@ -895,33 +956,6 @@ const State = (onLanguageChange, onPendingLanguageChange, onRunningChange) => {
|
|
|
895
956
|
});
|
|
896
957
|
};
|
|
897
958
|
|
|
898
|
-
/******************************************************************************
|
|
899
|
-
Copyright (c) Microsoft Corporation.
|
|
900
|
-
|
|
901
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
902
|
-
purpose with or without fee is hereby granted.
|
|
903
|
-
|
|
904
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
905
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
906
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
907
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
908
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
909
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
910
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
911
|
-
***************************************************************************** */
|
|
912
|
-
|
|
913
|
-
function __rest(s, e) {
|
|
914
|
-
var t = {};
|
|
915
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
916
|
-
t[p] = s[p];
|
|
917
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
918
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
919
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
920
|
-
t[p[i]] = s[p[i]];
|
|
921
|
-
}
|
|
922
|
-
return t;
|
|
923
|
-
}
|
|
924
|
-
|
|
925
959
|
function parseCombinedOptions(_a) {
|
|
926
960
|
var { ns, noWrap, orEmpty, params } = _a, rest = __rest(_a, ["ns", "noWrap", "orEmpty", "params"]);
|
|
927
961
|
const options = {
|
|
@@ -1119,15 +1153,15 @@ const Controller = ({ options }) => {
|
|
|
1119
1153
|
return cache.loadRecords(descriptors, isDev());
|
|
1120
1154
|
}
|
|
1121
1155
|
const checkCorrectConfiguration = () => {
|
|
1122
|
-
const
|
|
1123
|
-
if (
|
|
1156
|
+
const languageComputable = pluginService.getLanguageDetector() || pluginService.getLanguageStorage();
|
|
1157
|
+
if (languageComputable) {
|
|
1124
1158
|
const availableLanguages = state.getAvailableLanguages();
|
|
1125
1159
|
if (!availableLanguages) {
|
|
1126
1160
|
throw new Error(missingOptionError('availableLanguages'));
|
|
1127
1161
|
}
|
|
1128
1162
|
}
|
|
1129
1163
|
if (!state.getLanguage() && !state.getInitialOptions().defaultLanguage) {
|
|
1130
|
-
if (
|
|
1164
|
+
if (languageComputable) {
|
|
1131
1165
|
throw new Error(missingOptionError('defaultLanguage'));
|
|
1132
1166
|
}
|
|
1133
1167
|
else {
|
|
@@ -1143,7 +1177,7 @@ const Controller = ({ options }) => {
|
|
|
1143
1177
|
cache.invalidate();
|
|
1144
1178
|
}
|
|
1145
1179
|
state.setRunning(true);
|
|
1146
|
-
pluginService.run(
|
|
1180
|
+
pluginService.run();
|
|
1147
1181
|
result = loadInitial();
|
|
1148
1182
|
}
|
|
1149
1183
|
return Promise.resolve(result);
|
|
@@ -1205,6 +1239,10 @@ const createTolgee = (options) => {
|
|
|
1205
1239
|
* ```
|
|
1206
1240
|
*/
|
|
1207
1241
|
onNsUpdate: controller.onUpdate.listenSome,
|
|
1242
|
+
/**
|
|
1243
|
+
* Turn off/on events emitting. Is on by default.
|
|
1244
|
+
*/
|
|
1245
|
+
setEmmiterActive: controller.setEmmiterActive,
|
|
1208
1246
|
/**
|
|
1209
1247
|
* @return current language if set.
|
|
1210
1248
|
*/
|
|
@@ -1319,13 +1357,17 @@ const createTolgee = (options) => {
|
|
|
1319
1357
|
*/
|
|
1320
1358
|
unwrap: controller.unwrap,
|
|
1321
1359
|
/**
|
|
1322
|
-
* Override creadentials passed on initialization
|
|
1360
|
+
* Override creadentials passed on initialization.
|
|
1361
|
+
*
|
|
1362
|
+
* When called in running state, tolgee stops and runs again.
|
|
1323
1363
|
*/
|
|
1324
1364
|
overrideCredentials(credentials) {
|
|
1325
1365
|
withRestart(() => controller.overrideCredentials(credentials));
|
|
1326
1366
|
},
|
|
1327
1367
|
/**
|
|
1328
|
-
* Add tolgee plugin.
|
|
1368
|
+
* Add tolgee plugin after initialization.
|
|
1369
|
+
*
|
|
1370
|
+
* When called in running state, tolgee stops and runs again.
|
|
1329
1371
|
*/
|
|
1330
1372
|
addPlugin(plugin) {
|
|
1331
1373
|
if (plugin) {
|
|
@@ -1354,7 +1396,7 @@ const createTolgee = (options) => {
|
|
|
1354
1396
|
* const tolgee = Tolgee().use(...).init(...)
|
|
1355
1397
|
* ```
|
|
1356
1398
|
*/
|
|
1357
|
-
const
|
|
1399
|
+
const TolgeeCore = () => {
|
|
1358
1400
|
const state = {
|
|
1359
1401
|
plugins: [],
|
|
1360
1402
|
options: {},
|
|
@@ -1532,7 +1574,7 @@ const FormatSimple = () => (tolgee, tools) => {
|
|
|
1532
1574
|
};
|
|
1533
1575
|
|
|
1534
1576
|
exports.FormatSimple = FormatSimple;
|
|
1535
|
-
exports.
|
|
1577
|
+
exports.TolgeeCore = TolgeeCore;
|
|
1536
1578
|
exports.getFallback = getFallback;
|
|
1537
1579
|
exports.getFallbackArray = getFallbackArray;
|
|
1538
1580
|
exports.getTranslateProps = getTranslateProps;
|