@tolgee/core 5.7.0-prerelease.fa761114.0 → 5.7.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.
- package/dist/tolgee.cjs.js.map +1 -1
- package/dist/tolgee.cjs.min.js.map +1 -1
- package/dist/tolgee.esm.js.map +1 -1
- package/dist/tolgee.esm.min.js.map +1 -1
- package/dist/tolgee.esm.min.mjs.map +1 -1
- package/dist/tolgee.esm.mjs.map +1 -1
- package/dist/tolgee.umd.js.map +1 -1
- package/dist/tolgee.umd.min.js.map +1 -1
- package/lib/Controller/Controller.d.ts +3 -55
- package/lib/Controller/Plugins/Plugins.d.ts +1 -1
- package/lib/TolgeeCore.d.ts +6 -6
- package/lib/types/general.d.ts +7 -7
- package/package.json +2 -2
- package/src/TolgeeCore.ts +12 -2
- package/src/types/general.ts +16 -7
package/lib/TolgeeCore.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TolgeeOptions, TolgeePlugin, DevCredentials } from './types';
|
|
1
|
+
import { TolgeeOptions, TolgeePlugin, DevCredentials, TFnType, DefaultParamType, TranslationKey } from './types';
|
|
2
2
|
declare const createTolgee: (options: TolgeeOptions) => Readonly<{
|
|
3
3
|
/**
|
|
4
4
|
* Listen to tolgee events.
|
|
@@ -119,7 +119,7 @@ declare const createTolgee: (options: TolgeeOptions) => Readonly<{
|
|
|
119
119
|
* Returns translated and formatted key.
|
|
120
120
|
* If Observer is present and tolgee is running, wraps result to be identifiable in the DOM.
|
|
121
121
|
*/
|
|
122
|
-
t:
|
|
122
|
+
t: TFnType<DefaultParamType, string, TranslationKey>;
|
|
123
123
|
/**
|
|
124
124
|
* Highlight keys that match selection.
|
|
125
125
|
*/
|
|
@@ -132,9 +132,7 @@ declare const createTolgee: (options: TolgeeOptions) => Readonly<{
|
|
|
132
132
|
apiKey?: string | undefined;
|
|
133
133
|
projectId?: string | number | undefined;
|
|
134
134
|
language?: string | undefined;
|
|
135
|
-
defaultLanguage?: string | undefined;
|
|
136
|
-
* Turn off/on events emitting. Is on by default.
|
|
137
|
-
*/
|
|
135
|
+
defaultLanguage?: string | undefined;
|
|
138
136
|
availableLanguages?: string[] | undefined;
|
|
139
137
|
fallbackLanguage?: import("./types").FallbackLanguageOption;
|
|
140
138
|
ns?: string[] | undefined;
|
|
@@ -178,7 +176,9 @@ declare const createTolgee: (options: TolgeeOptions) => Readonly<{
|
|
|
178
176
|
*/
|
|
179
177
|
updateOptions(options?: TolgeeOptions): void;
|
|
180
178
|
}>;
|
|
181
|
-
export declare type TolgeeInstance = ReturnType<typeof createTolgee
|
|
179
|
+
export declare type TolgeeInstance = Omit<ReturnType<typeof createTolgee>, 't'> & {
|
|
180
|
+
t: TFnType<DefaultParamType, string, TranslationKey>;
|
|
181
|
+
};
|
|
182
182
|
export declare type TolgeeChainer = {
|
|
183
183
|
/**
|
|
184
184
|
* Add plugin, plugins are applied when `init` method is called.
|
package/lib/types/general.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare type FallbackGeneral = undefined | false | string | string[];
|
|
2
2
|
export declare type NsType = string;
|
|
3
|
-
export declare type
|
|
3
|
+
export declare type TranslationKey = string & Record<never, never>;
|
|
4
4
|
export declare type NsFallback = undefined | NsType | NsType[];
|
|
5
5
|
export declare type FallbackLanguageObject = Record<string, FallbackGeneral>;
|
|
6
6
|
export declare type FallbackLanguageOption = FallbackGeneral | FallbackLanguageObject;
|
|
@@ -13,8 +13,8 @@ export declare type TranslateOptions = {
|
|
|
13
13
|
noWrap?: boolean;
|
|
14
14
|
orEmpty?: boolean;
|
|
15
15
|
};
|
|
16
|
-
export declare type TranslateProps<T = DefaultParamType> = {
|
|
17
|
-
key:
|
|
16
|
+
export declare type TranslateProps<T = DefaultParamType, K extends string = TranslationKey> = {
|
|
17
|
+
key: K;
|
|
18
18
|
defaultValue?: string;
|
|
19
19
|
params?: TranslateParams<T>;
|
|
20
20
|
} & TranslateOptions;
|
|
@@ -25,10 +25,10 @@ declare type PropType<TObj> = TObj[keyof TObj];
|
|
|
25
25
|
export declare type CombinedOptions<T> = TranslateOptions & {
|
|
26
26
|
[key: string]: T | PropType<TranslateOptions>;
|
|
27
27
|
};
|
|
28
|
-
export declare type TFnType<T = DefaultParamType, R = string> = {
|
|
29
|
-
(key:
|
|
30
|
-
(key:
|
|
31
|
-
(props: TranslateProps<T>): R;
|
|
28
|
+
export declare type TFnType<T = DefaultParamType, R = string, K extends string = TranslationKey> = {
|
|
29
|
+
(key: K, defaultValue?: string, options?: CombinedOptions<T>): R;
|
|
30
|
+
(key: K, options?: CombinedOptions<T>): R;
|
|
31
|
+
(props: TranslateProps<T, K>): R;
|
|
32
32
|
};
|
|
33
33
|
export declare type KeyAndNamespacesInternal = Pick<TranslatePropsInternal, 'key' | 'ns'>;
|
|
34
34
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tolgee/core",
|
|
3
|
-
"version": "5.7.0
|
|
3
|
+
"version": "5.7.0",
|
|
4
4
|
"description": "Library providing ability to translate messages directly in context of developed application.",
|
|
5
5
|
"main": "./dist/tolgee.cjs.js",
|
|
6
6
|
"module": "./dist/tolgee.esm.js",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"access": "public"
|
|
68
68
|
},
|
|
69
69
|
"sideEffects": false,
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "b8b2b67da494535658940856596359ebc27df7c1"
|
|
71
71
|
}
|
package/src/TolgeeCore.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Controller } from './Controller/Controller';
|
|
2
2
|
import { combineOptions } from './Controller/State/initState';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
TolgeeOptions,
|
|
5
|
+
TolgeePlugin,
|
|
6
|
+
DevCredentials,
|
|
7
|
+
TFnType,
|
|
8
|
+
DefaultParamType,
|
|
9
|
+
TranslationKey,
|
|
10
|
+
} from './types';
|
|
4
11
|
|
|
5
12
|
const createTolgee = (options: TolgeeOptions) => {
|
|
6
13
|
const controller = Controller({
|
|
@@ -214,7 +221,10 @@ const createTolgee = (options: TolgeeOptions) => {
|
|
|
214
221
|
return tolgee;
|
|
215
222
|
};
|
|
216
223
|
|
|
217
|
-
export type TolgeeInstance = ReturnType<typeof createTolgee
|
|
224
|
+
export type TolgeeInstance = Omit<ReturnType<typeof createTolgee>, 't'> & {
|
|
225
|
+
// enabling generics (when inferred they are lost)
|
|
226
|
+
t: TFnType<DefaultParamType, string, TranslationKey>;
|
|
227
|
+
};
|
|
218
228
|
|
|
219
229
|
export type TolgeeChainer = {
|
|
220
230
|
/**
|
package/src/types/general.ts
CHANGED
|
@@ -2,7 +2,9 @@ export type FallbackGeneral = undefined | false | string | string[];
|
|
|
2
2
|
|
|
3
3
|
export type NsType = string;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// This prevents typescript to optimize this to 'string'
|
|
6
|
+
// this type needs to be overritable everywhere
|
|
7
|
+
export type TranslationKey = string & Record<never, never>;
|
|
6
8
|
|
|
7
9
|
export type NsFallback = undefined | NsType | NsType[];
|
|
8
10
|
|
|
@@ -22,8 +24,11 @@ export type TranslateOptions = {
|
|
|
22
24
|
orEmpty?: boolean;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
|
-
export type TranslateProps<
|
|
26
|
-
|
|
27
|
+
export type TranslateProps<
|
|
28
|
+
T = DefaultParamType,
|
|
29
|
+
K extends string = TranslationKey
|
|
30
|
+
> = {
|
|
31
|
+
key: K;
|
|
27
32
|
defaultValue?: string;
|
|
28
33
|
params?: TranslateParams<T>;
|
|
29
34
|
} & TranslateOptions;
|
|
@@ -38,10 +43,14 @@ export type CombinedOptions<T> = TranslateOptions & {
|
|
|
38
43
|
[key: string]: T | PropType<TranslateOptions>;
|
|
39
44
|
};
|
|
40
45
|
|
|
41
|
-
export type TFnType<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
export type TFnType<
|
|
47
|
+
T = DefaultParamType,
|
|
48
|
+
R = string,
|
|
49
|
+
K extends string = TranslationKey
|
|
50
|
+
> = {
|
|
51
|
+
(key: K, defaultValue?: string, options?: CombinedOptions<T>): R;
|
|
52
|
+
(key: K, options?: CombinedOptions<T>): R;
|
|
53
|
+
(props: TranslateProps<T, K>): R;
|
|
45
54
|
};
|
|
46
55
|
|
|
47
56
|
export type KeyAndNamespacesInternal = Pick<
|