@tolgee/core 5.0.0-rc.9be0f0e.0 → 5.0.0

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.
Files changed (96) hide show
  1. package/README.md +174 -0
  2. package/README.njk.md +61 -0
  3. package/dist/tolgee.cjs.js +723 -351
  4. package/dist/tolgee.cjs.js.map +1 -1
  5. package/dist/tolgee.cjs.min.js +1 -1
  6. package/dist/tolgee.cjs.min.js.map +1 -1
  7. package/dist/{tolgee.esm.mjs → tolgee.esm.js} +722 -346
  8. package/dist/tolgee.esm.js.map +1 -0
  9. package/dist/tolgee.esm.min.mjs +1 -1
  10. package/dist/tolgee.esm.min.mjs.map +1 -1
  11. package/dist/tolgee.umd.js +723 -351
  12. package/dist/tolgee.umd.js.map +1 -1
  13. package/dist/tolgee.umd.min.js +1 -1
  14. package/dist/tolgee.umd.min.js.map +1 -1
  15. package/lib/Controller/Cache/Cache.d.ts +10 -9
  16. package/lib/Controller/Controller.d.ts +104 -45
  17. package/lib/Controller/Events/EventEmitter.d.ts +6 -0
  18. package/lib/Controller/Events/EventEmitterSelective.d.ts +7 -0
  19. package/lib/Controller/Events/Events.d.ts +14 -0
  20. package/lib/Controller/Plugins/Plugins.d.ts +12 -25
  21. package/lib/Controller/State/State.d.ts +27 -9
  22. package/lib/Controller/State/initState.d.ts +46 -15
  23. package/lib/Controller/State/observerOptions.d.ts +41 -0
  24. package/lib/Controller/ValueObserver.d.ts +5 -5
  25. package/lib/FormatSimple/FormatError.d.ts +7 -0
  26. package/lib/FormatSimple/FormatSimple.d.ts +2 -0
  27. package/lib/FormatSimple/formatParser.d.ts +1 -0
  28. package/lib/FormatSimple/formatter.d.ts +2 -0
  29. package/lib/TolgeeCore.d.ts +204 -0
  30. package/lib/TranslateParams.d.ts +1 -1
  31. package/lib/helpers.d.ts +8 -0
  32. package/lib/index.d.ts +4 -4
  33. package/lib/types/cache.d.ts +25 -0
  34. package/lib/types/events.d.ts +66 -0
  35. package/lib/types/general.d.ts +34 -0
  36. package/lib/types/index.d.ts +7 -0
  37. package/lib/types/plugin.d.ts +127 -0
  38. package/package.json +5 -4
  39. package/src/Controller/Cache/Cache.ts +31 -31
  40. package/src/Controller/Cache/helpers.ts +6 -6
  41. package/src/Controller/Controller.ts +78 -50
  42. package/src/Controller/Events/EventEmitter.ts +34 -0
  43. package/src/Controller/Events/EventEmitterSelective.test.ts +110 -0
  44. package/src/Controller/Events/EventEmitterSelective.ts +132 -0
  45. package/src/Controller/Events/Events.ts +69 -0
  46. package/src/Controller/Plugins/Plugins.ts +182 -133
  47. package/src/Controller/State/State.ts +43 -26
  48. package/src/Controller/State/initState.ts +97 -25
  49. package/src/Controller/State/observerOptions.ts +66 -0
  50. package/src/Controller/ValueObserver.ts +5 -2
  51. package/src/FormatSimple/FormatError.ts +26 -0
  52. package/src/FormatSimple/FormatSimple.ts +13 -0
  53. package/src/FormatSimple/formatParser.ts +133 -0
  54. package/src/FormatSimple/formatter.test.ts +190 -0
  55. package/src/FormatSimple/formatter.ts +19 -0
  56. package/src/TolgeeCore.ts +267 -0
  57. package/src/TranslateParams.test.ts +9 -12
  58. package/src/TranslateParams.ts +6 -5
  59. package/src/__test/backend.test.ts +6 -6
  60. package/src/__test/cache.test.ts +190 -0
  61. package/src/__test/client.test.ts +2 -2
  62. package/src/__test/events.test.ts +32 -7
  63. package/src/__test/format.simple.test.ts +14 -0
  64. package/src/__test/formatError.test.ts +61 -0
  65. package/src/__test/initialization.test.ts +15 -3
  66. package/src/__test/languageDetection.test.ts +14 -8
  67. package/src/__test/languageStorage.test.ts +10 -11
  68. package/src/__test/languages.test.ts +30 -6
  69. package/src/__test/loading.test.ts +2 -2
  70. package/src/__test/{namespacesFallback.test.ts → namespaces.fallback.test.ts} +10 -8
  71. package/src/__test/namespaces.test.ts +30 -7
  72. package/src/__test/options.test.ts +64 -0
  73. package/src/__test/plugins.test.ts +29 -18
  74. package/src/helpers.ts +53 -0
  75. package/src/index.ts +4 -10
  76. package/src/types/cache.ts +37 -0
  77. package/src/types/events.ts +85 -0
  78. package/src/types/general.ts +50 -0
  79. package/src/types/index.ts +19 -0
  80. package/src/types/plugin.ts +181 -0
  81. package/dist/tolgee.esm.mjs.map +0 -1
  82. package/lib/Controller/State/helpers.d.ts +0 -6
  83. package/lib/Events/EventEmitter.d.ts +0 -6
  84. package/lib/Events/EventEmitterSelective.d.ts +0 -15
  85. package/lib/Events/Events.d.ts +0 -50
  86. package/lib/Tolgee.d.ts +0 -2
  87. package/lib/constants.d.ts +0 -5
  88. package/lib/types.d.ts +0 -274
  89. package/src/Controller/State/helpers.ts +0 -41
  90. package/src/Events/EventEmitter.ts +0 -27
  91. package/src/Events/EventEmitterSelective.test.ts +0 -108
  92. package/src/Events/EventEmitterSelective.ts +0 -160
  93. package/src/Events/Events.ts +0 -66
  94. package/src/Tolgee.ts +0 -77
  95. package/src/constants.ts +0 -7
  96. package/src/types.ts +0 -380
@@ -0,0 +1,190 @@
1
+ import { TranslateParams } from '../types';
2
+ import IntlMessageFormat from 'intl-messageformat';
3
+ import { formatter } from './formatter';
4
+ import {
5
+ ErrorCode,
6
+ ERROR_PARAM_EMPTY,
7
+ ERROR_UNEXPECTED_CHAR,
8
+ ERROR_UNEXPECTED_END,
9
+ FormatError,
10
+ } from './FormatError';
11
+
12
+ function icu(text: string, params?: TranslateParams) {
13
+ return new IntlMessageFormat(text, 'en', undefined, {
14
+ ignoreTag: true,
15
+ }).format(params);
16
+ }
17
+
18
+ function getText() {
19
+ return expect.getState().currentTestName.replace('simple formatter ', '');
20
+ }
21
+
22
+ function matchIcu(params?: TranslateParams) {
23
+ const text = getText();
24
+ expect(formatter(text, params)).toEqual(icu(text, params));
25
+ }
26
+
27
+ function expectToThrow(
28
+ text: string,
29
+ code?: ErrorCode,
30
+ params?: TranslateParams
31
+ ) {
32
+ let error: FormatError | undefined = undefined;
33
+ try {
34
+ formatter(text, params);
35
+ } catch (e) {
36
+ error = e as FormatError;
37
+ }
38
+ expect(error).toBeInstanceOf(FormatError);
39
+ expect(error?.code).toEqual(code);
40
+ }
41
+
42
+ function expectToThrowWithIcu(code?: ErrorCode, params?: TranslateParams) {
43
+ const text = getText();
44
+ expect(() => icu(text, params)).toThrow();
45
+ expectToThrow(text, code, params);
46
+ }
47
+
48
+ function unsupported(code?: ErrorCode, params?: TranslateParams) {
49
+ const text = getText();
50
+ expect(() => icu(text, params)).not.toThrow();
51
+ expectToThrow(text, code, params);
52
+ }
53
+
54
+ function combineChars(chars: string[]) {
55
+ const result: string[] = [];
56
+ chars.forEach((char) => {
57
+ [`start${char}`, `${char}end`, `mid${char}dle`, char].forEach((param) => {
58
+ result.push(param);
59
+ });
60
+ });
61
+ return result;
62
+ }
63
+
64
+ function characterInParamSupported(chars: string[]) {
65
+ combineChars(chars).forEach((param) => {
66
+ const text = `test { ${param} } param`;
67
+ it(`works with: ${text}`, () => {
68
+ const params = { [param]: 'valid' };
69
+ expect(icu(text, params)).toEqual('test valid param');
70
+ expect(formatter(text, params)).toEqual('test valid param');
71
+ });
72
+ });
73
+ }
74
+
75
+ function characterInParamFailWithIcu(chars: string[]) {
76
+ combineChars(chars).forEach((param) => {
77
+ const text = `test { ${param} } param`;
78
+ it(`fails with: ${text}`, () => {
79
+ const params = { [param]: 'test' };
80
+ expect(() => icu(text, params)).toThrow();
81
+ expectToThrow(text, ERROR_UNEXPECTED_CHAR, params);
82
+ });
83
+ });
84
+ }
85
+
86
+ function characterInParamFail(chars: string[]) {
87
+ combineChars(chars).forEach((param) => {
88
+ const text = `test { ${param} } param`;
89
+ it(`works with: ${text}`, () => {
90
+ const params = { [param]: 'valid' };
91
+ expectToThrow(text, ERROR_UNEXPECTED_CHAR, params);
92
+ });
93
+ });
94
+ }
95
+
96
+ describe('simple formatter', () => {
97
+ test('test test', () => {
98
+ expect(getText()).toEqual('test test');
99
+ });
100
+
101
+ test('simple test', () => {
102
+ matchIcu();
103
+ });
104
+
105
+ test('this is {name}', () => {
106
+ matchIcu({ name: 'Bob' });
107
+ });
108
+
109
+ test('this is { name }', () => {
110
+ matchIcu({ name: 'Bob' });
111
+ });
112
+
113
+ test('{ user } has { num } apples.', () => {
114
+ matchIcu({ user: 'John', num: 2 });
115
+ });
116
+
117
+ test('passing params, but no params here', () => {
118
+ matchIcu({ user: 'John', num: 2 });
119
+ });
120
+
121
+ test('{ user } has { user } apples.', () => {
122
+ matchIcu({ user: 'John', num: 2 });
123
+ });
124
+
125
+ test("ICU: '{ parameter '} format", () => {
126
+ matchIcu();
127
+ });
128
+
129
+ test("this '{ escaped }' well", () => {
130
+ matchIcu();
131
+ });
132
+
133
+ test("this is '{ weird } but valid", () => {
134
+ matchIcu();
135
+ });
136
+
137
+ test("edge case '", () => {
138
+ matchIcu();
139
+ });
140
+
141
+ test("What's {subject}?", () => {
142
+ matchIcu({ subject: 'that' });
143
+ });
144
+
145
+ test('this is also } right', () => {
146
+ matchIcu();
147
+ });
148
+
149
+ test('this is just {} wrong', () => {
150
+ expectToThrowWithIcu(ERROR_PARAM_EMPTY);
151
+ });
152
+
153
+ test('this also { } wrong', () => {
154
+ expectToThrowWithIcu(ERROR_PARAM_EMPTY);
155
+ });
156
+
157
+ test('this plain { , } wrong', () => {
158
+ expectToThrowWithIcu(ERROR_UNEXPECTED_CHAR);
159
+ });
160
+
161
+ test('this is { unexpected', () => {
162
+ expectToThrowWithIcu(ERROR_UNEXPECTED_END);
163
+ });
164
+
165
+ test('this is obviously bad { yo yo }', () => {
166
+ expectToThrowWithIcu(ERROR_UNEXPECTED_CHAR);
167
+ });
168
+
169
+ test('this is obviously bad { yo, }', () => {
170
+ expectToThrowWithIcu(ERROR_UNEXPECTED_CHAR);
171
+ });
172
+
173
+ test('good for icu { yo, number } not for me', () => {
174
+ unsupported(ERROR_UNEXPECTED_CHAR, { yo: 6 });
175
+ });
176
+
177
+ describe('supported characters in params', () => {
178
+ characterInParamSupported(Array.from('019_axAX'));
179
+ });
180
+
181
+ describe('invalid characters in params', () => {
182
+ characterInParamFailWithIcu('[+-@#$~^&*{%)(§\'"`!?:.;<>[]\\=|☺'.split(''));
183
+ });
184
+
185
+ describe('unsupported characters which are supported in ICU', () => {
186
+ characterInParamFail(Array.from('šřýíéúůĚŽÝÁÍÉůú¨ˇ'));
187
+ characterInParamFail(['汉字', '字', 'हि', 'हिन्दी']);
188
+ characterInParamFail(['😊']);
189
+ });
190
+ });
@@ -0,0 +1,19 @@
1
+ import { DefaultParamType, TranslateParams } from '../types';
2
+ import { formatParser } from './formatParser';
3
+
4
+ export function formatter(
5
+ translation: string,
6
+ params?: TranslateParams<DefaultParamType>
7
+ ) {
8
+ const [texts, pars] = formatParser(translation);
9
+ const result = [texts[0]];
10
+ for (let i = 1; i < texts.length; i++) {
11
+ const parameter = params?.[pars[i - 1]];
12
+ if (parameter === undefined) {
13
+ throw new Error(`Missing parameter "${pars[i - 1]}" in "${translation}"`);
14
+ }
15
+ result.push(String(parameter));
16
+ result.push(texts[i]);
17
+ }
18
+ return result.join('');
19
+ }
@@ -0,0 +1,267 @@
1
+ import { Controller } from './Controller/Controller';
2
+ import { combineOptions } from './Controller/State/initState';
3
+ import { TolgeeOptions, TolgeePlugin, DevCredentials } from './types';
4
+
5
+ const createTolgee = (options: TolgeeOptions) => {
6
+ const controller = Controller({
7
+ options,
8
+ });
9
+
10
+ // restarts tolgee while applying callback
11
+ const withRestart = (callback: () => void) => {
12
+ const wasRunning = controller.isRunning();
13
+ wasRunning && controller.stop();
14
+ callback();
15
+ wasRunning && controller.run();
16
+ };
17
+
18
+ const tolgee = Object.freeze({
19
+ /**
20
+ * Listen to tolgee events.
21
+ */
22
+ on: controller.on,
23
+
24
+ /**
25
+ * Listen for specific namespaces changes.
26
+ *
27
+ * ```
28
+ * const sub = tolgee.onUpdate(handler)
29
+ *
30
+ * // subscribe to selected namespace
31
+ * sub.subscribeNs(['common'])
32
+ *
33
+ * // unsubscribe
34
+ * sub.unsubscribe()
35
+ * ```
36
+ */
37
+ onNsUpdate: controller.onUpdate.listenSome,
38
+
39
+ /**
40
+ * Turn off/on events emitting. Is on by default.
41
+ */
42
+ setEmmiterActive: controller.setEmmiterActive,
43
+
44
+ /**
45
+ * @return current language if set.
46
+ */
47
+ getLanguage: controller.getLanguage,
48
+
49
+ /**
50
+ * `pendingLanguage` represents language which is currently being loaded.
51
+ * @return current `pendingLanguage` if set.
52
+ */
53
+ getPendingLanguage: controller.getPendingLanguage,
54
+
55
+ /**
56
+ * Change current language.
57
+ * - if not running sets `pendingLanguage`, `language` to the new value
58
+ * - if running sets `pendingLanguage` to the value, fetches necessary data and then changes `language`
59
+ *
60
+ * @return Promise which is resolved when `language` is changed.
61
+ */
62
+ changeLanguage: controller.changeLanguage,
63
+
64
+ /**
65
+ * Temporarily change translation in cache.
66
+ * @return object with revert method.
67
+ */
68
+ changeTranslation: controller.changeTranslation,
69
+
70
+ /**
71
+ * Adds namespace(s) list of active namespaces. And if tolgee is running, loads required data.
72
+ */
73
+ addActiveNs: controller.addActiveNs,
74
+
75
+ /**
76
+ * Remove namespace(s) from active namespaces.
77
+ *
78
+ * Tolgee internally counts how many times was each active namespace added,
79
+ * so this method will remove namespace only if the counter goes down to 0.
80
+ */
81
+ removeActiveNs: controller.removeActiveNs,
82
+
83
+ /**
84
+ * Manually load multiple records from `Backend` (or `DevBackend` when in dev mode)
85
+ *
86
+ * It loads data together and adds them to cache in one operation, to prevent partly loaded state.
87
+ */
88
+ loadRecords: controller.loadRecords,
89
+
90
+ /**
91
+ * Manually load record from `Backend` (or `DevBackend` when in dev mode)
92
+ */
93
+ loadRecord: controller.loadRecord,
94
+
95
+ /**
96
+ *
97
+ */
98
+ addStaticData: controller.addStaticData,
99
+
100
+ /**
101
+ * Get record from cache.
102
+ */
103
+ getRecord: controller.getRecord,
104
+
105
+ /**
106
+ * Get all records from cache.
107
+ */
108
+ getAllRecords: controller.getAllRecords,
109
+
110
+ /**
111
+ * @param ns optional list of namespaces that you are interested in
112
+ * @return `true` if there are data that need to be fetched.
113
+ */
114
+ isLoaded: controller.isLoaded,
115
+
116
+ /**
117
+ * @return `true` if tolgee is loading initial data (triggered by `run`).
118
+ */
119
+ isInitialLoading: controller.isInitialLoading,
120
+
121
+ /**
122
+ * @param ns optional list of namespaces that you are interested in
123
+ * @return `true` if tolgee is loading some translations for the first time.
124
+ */
125
+ isLoading: controller.isLoading,
126
+
127
+ /**
128
+ * @param ns optional list of namespaces that you are interested in
129
+ * @return `true` if tolgee is fetching some translations.
130
+ */
131
+ isFetching: controller.isFetching,
132
+
133
+ /**
134
+ * @return `true` if tolgee is running.
135
+ */
136
+ isRunning: controller.isRunning,
137
+
138
+ /**
139
+ * Changes internal state to running: true and loads initial files.
140
+ * Runs runnable plugins mainly Observer if present.
141
+ */
142
+ run: controller.run,
143
+
144
+ /**
145
+ * Changes internal state to running: false and stops runnable plugins.
146
+ */
147
+ stop: controller.stop,
148
+
149
+ /**
150
+ * Returns translated and formatted key.
151
+ * If Observer is present and tolgee is running, wraps result to be identifiable in the DOM.
152
+ */
153
+ t: controller.t,
154
+
155
+ /**
156
+ * Highlight keys that match selection.
157
+ */
158
+ highlight: controller.highlight,
159
+
160
+ /**
161
+ * @return current Tolgee options.
162
+ */
163
+ getInitialOptions: controller.getInitialOptions,
164
+
165
+ /**
166
+ * Tolgee is in dev mode if `DevTools` plugin is used and `apiKey` + `apiUrl` are specified.
167
+ * @return `true` if tolgee is in dev mode.
168
+ */
169
+ isDev: controller.isDev,
170
+
171
+ /**
172
+ * Wraps translation if there is `Observer` plugin
173
+ */
174
+ wrap: controller.wrap,
175
+
176
+ /**
177
+ * Unwrap translation
178
+ */
179
+ unwrap: controller.unwrap,
180
+
181
+ /**
182
+ * Override creadentials passed on initialization.
183
+ *
184
+ * When called in running state, tolgee stops and runs again.
185
+ */
186
+ overrideCredentials(credentials: DevCredentials) {
187
+ withRestart(() => controller.overrideCredentials(credentials));
188
+ },
189
+
190
+ /**
191
+ * Add tolgee plugin after initialization.
192
+ *
193
+ * When called in running state, tolgee stops and runs again.
194
+ */
195
+ addPlugin(plugin: TolgeePlugin | undefined) {
196
+ if (plugin) {
197
+ withRestart(() => controller.addPlugin(tolgee, plugin));
198
+ }
199
+ },
200
+
201
+ /**
202
+ * Updates options after instance creation. Extends existing options,
203
+ * so it only changes the fields, that are listed.
204
+ *
205
+ * When called in running state, tolgee stops and runs again.
206
+ */
207
+ updateOptions(options?: TolgeeOptions) {
208
+ if (options) {
209
+ withRestart(() => controller.init(options));
210
+ }
211
+ },
212
+ });
213
+
214
+ return tolgee;
215
+ };
216
+
217
+ export type TolgeeInstance = ReturnType<typeof createTolgee>;
218
+
219
+ export type TolgeeChainer = {
220
+ /**
221
+ * Add plugin, plugins are applied when `init` method is called.
222
+ */
223
+ use: (plugin: TolgeePlugin | undefined) => TolgeeChainer;
224
+
225
+ /**
226
+ * Update default options before tolgee is initialized.
227
+ */
228
+ updateDefaults: (options: TolgeeOptions) => TolgeeChainer;
229
+
230
+ /**
231
+ * Initialize tolgee options and apply plugins
232
+ * @returns tolgee instance
233
+ */
234
+ init(options?: TolgeeOptions): TolgeeInstance;
235
+ };
236
+
237
+ /**
238
+ * Tolgee chainable constructor.
239
+ *
240
+ * Usage:
241
+ * ```
242
+ * const tolgee = Tolgee().use(...).init(...)
243
+ * ```
244
+ */
245
+ export const TolgeeCore = (): TolgeeChainer => {
246
+ const state = {
247
+ plugins: [] as (TolgeePlugin | undefined)[],
248
+ options: {} as TolgeeOptions,
249
+ };
250
+
251
+ const tolgeeChain = Object.freeze({
252
+ use(plugin: TolgeePlugin | undefined) {
253
+ state.plugins.push(plugin);
254
+ return tolgeeChain;
255
+ },
256
+ updateDefaults(options: TolgeeOptions) {
257
+ state.options = combineOptions(state.options, options);
258
+ return tolgeeChain;
259
+ },
260
+ init(options?: TolgeeOptions) {
261
+ const tolgee = createTolgee(combineOptions(state.options, options));
262
+ state.plugins.forEach(tolgee.addPlugin);
263
+ return tolgee;
264
+ },
265
+ });
266
+ return tolgeeChain;
267
+ };
@@ -1,40 +1,37 @@
1
- import { getTranslateParams } from './TranslateParams';
1
+ import { getTranslateProps } from './TranslateParams';
2
2
  import { TranslateProps } from './types';
3
3
 
4
4
  const testParams: TranslateProps = {
5
5
  key: 'test',
6
6
  defaultValue: 'Test',
7
7
  noWrap: true,
8
- ns: [],
8
+ ns: 'test',
9
9
  orEmpty: true,
10
- params: { yo: 'yo', ns: '(this is param not namespace)' },
10
+ params: { yo: 'yo' },
11
11
  };
12
12
 
13
- describe('getTranslateParams', () => {
13
+ describe('getTranslateProps', () => {
14
14
  it('manages regular params', () => {
15
- const result = getTranslateParams(testParams);
15
+ const result = getTranslateProps(testParams);
16
16
  expect(result).toEqual(testParams);
17
17
  });
18
18
 
19
19
  it('manages key with default value', () => {
20
- const result = getTranslateParams('test', 'Test');
20
+ const result = getTranslateProps('test', 'Test');
21
21
  expect(result).toEqual({ key: 'test', defaultValue: 'Test' });
22
22
  });
23
23
 
24
24
  it('manages key with options', () => {
25
- const result = getTranslateParams('test', { noWrap: true, yo: 'yo' });
25
+ const result = getTranslateProps('test', { noWrap: true, yo: 'yo' });
26
26
  expect(result).toEqual({ key: 'test', noWrap: true, params: { yo: 'yo' } });
27
27
  });
28
28
 
29
29
  it('manages key default and options', () => {
30
- const result = getTranslateParams('test', 'Test', {
30
+ const result = getTranslateProps('test', 'Test', {
31
31
  noWrap: true,
32
- ns: [],
32
+ ns: 'test',
33
33
  orEmpty: true,
34
34
  yo: 'yo',
35
- params: {
36
- ns: '(this is param not namespace)',
37
- },
38
35
  });
39
36
  expect(result).toEqual(testParams);
40
37
  });
@@ -11,20 +11,21 @@ function parseCombinedOptions({
11
11
  orEmpty,
12
12
  params,
13
13
  ...rest
14
- }: CombinedOptions<any>): Partial<TranslateProps> {
15
- const options: Required<TranslateOptions<any>> = {
14
+ }: Partial<TranslateProps>): Partial<TranslateProps> {
15
+ const options: Required<TranslateOptions> = {
16
16
  ns: ns!,
17
17
  noWrap: noWrap!,
18
18
  orEmpty: orEmpty!,
19
+ };
20
+ return {
21
+ ...options,
19
22
  params: {
20
23
  ...rest,
21
- ...params,
22
24
  },
23
25
  };
24
- return options;
25
26
  }
26
27
 
27
- export const getTranslateParams: TFnType<any, TranslateProps<any>> = (
28
+ export const getTranslateProps: TFnType<any, TranslateProps<any>> = (
28
29
  keyOrProps,
29
30
  ...params
30
31
  ) => {
@@ -1,5 +1,5 @@
1
- import { Tolgee } from '../Tolgee';
2
- import { BackendInterface, TolgeePlugin } from '../types';
1
+ import { TolgeeCore } from '../TolgeeCore';
2
+ import { BackendMiddleware, TolgeePlugin } from '../types';
3
3
 
4
4
  const data = {
5
5
  en: {
@@ -12,13 +12,13 @@ const data = {
12
12
  },
13
13
  } as any;
14
14
 
15
- const backendNormal: BackendInterface = {
15
+ const backendNormal: BackendMiddleware = {
16
16
  getRecord({ language, namespace = '' }) {
17
17
  return data[language]?.[namespace];
18
18
  },
19
19
  };
20
20
 
21
- const backendDev: BackendInterface = {
21
+ const backendDev: BackendMiddleware = {
22
22
  getRecord() {
23
23
  return Promise.resolve({ cancel: 'Dev' });
24
24
  },
@@ -32,7 +32,7 @@ const backendPlugin: TolgeePlugin = (tolgee, tools) => {
32
32
 
33
33
  describe('backend plugins', () => {
34
34
  it('uses plugin to fetch', async () => {
35
- const tolgee = Tolgee()
35
+ const tolgee = TolgeeCore()
36
36
  .use(backendPlugin)
37
37
  .init({
38
38
  ns: ['common', 'test'],
@@ -41,7 +41,7 @@ describe('backend plugins', () => {
41
41
  await tolgee.run();
42
42
  expect(tolgee.t({ key: 'cancel', ns: 'common' })).toEqual('Cancel');
43
43
  tolgee.stop();
44
- tolgee.init({ apiUrl: 'asdfasdf', apiKey: 'test' });
44
+ tolgee.overrideCredentials({ apiUrl: 'asdfasdf', apiKey: 'test' });
45
45
  await tolgee.run();
46
46
  expect(tolgee.t({ key: 'cancel', ns: 'common' })).toEqual('Dev');
47
47
  });