@tolgee/web 4.9.3-rc.128edeb.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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/tolgee-backend-fetch.cjs.min.js +2 -0
- package/dist/tolgee-backend-fetch.cjs.min.js.map +1 -0
- package/dist/tolgee-backend-fetch.esm.min.mjs +2 -0
- package/dist/tolgee-backend-fetch.esm.min.mjs.map +1 -0
- package/dist/tolgee-backend-fetch.umd.min.js +2 -0
- package/dist/tolgee-backend-fetch.umd.min.js.map +1 -0
- package/dist/tolgee-context-ui.cjs.min.js +143 -0
- package/dist/tolgee-context-ui.cjs.min.js.map +1 -0
- package/dist/tolgee-context-ui.esm.min.mjs +143 -0
- package/dist/tolgee-context-ui.esm.min.mjs.map +1 -0
- package/dist/tolgee-context-ui.umd.min.js +143 -0
- package/dist/tolgee-context-ui.umd.min.js.map +1 -0
- package/dist/tolgee-in-context-tools.cjs.min.js +143 -0
- package/dist/tolgee-in-context-tools.cjs.min.js.map +1 -0
- package/dist/tolgee-in-context-tools.esm.min.mjs +143 -0
- package/dist/tolgee-in-context-tools.esm.min.mjs.map +1 -0
- package/dist/tolgee-in-context-tools.umd.min.js +143 -0
- package/dist/tolgee-in-context-tools.umd.min.js.map +1 -0
- package/dist/tolgee-invisible-observer.cjs.min.js +2 -0
- package/dist/tolgee-invisible-observer.cjs.min.js.map +1 -0
- package/dist/tolgee-invisible-observer.esm.min.mjs +2 -0
- package/dist/tolgee-invisible-observer.esm.min.mjs.map +1 -0
- package/dist/tolgee-invisible-observer.umd.min.js +2 -0
- package/dist/tolgee-invisible-observer.umd.min.js.map +1 -0
- package/dist/tolgee-language-detector.cjs.min.js +2 -0
- package/dist/tolgee-language-detector.cjs.min.js.map +1 -0
- package/dist/tolgee-language-detector.esm.min.mjs +2 -0
- package/dist/tolgee-language-detector.esm.min.mjs.map +1 -0
- package/dist/tolgee-language-detector.umd.min.js +2 -0
- package/dist/tolgee-language-detector.umd.min.js.map +1 -0
- package/dist/tolgee-language-storage.cjs.min.js +2 -0
- package/dist/tolgee-language-storage.cjs.min.js.map +1 -0
- package/dist/tolgee-language-storage.esm.min.mjs +2 -0
- package/dist/tolgee-language-storage.esm.min.mjs.map +1 -0
- package/dist/tolgee-language-storage.umd.min.js +2 -0
- package/dist/tolgee-language-storage.umd.min.js.map +1 -0
- package/dist/tolgee-text-observer.cjs.min.js +2 -0
- package/dist/tolgee-text-observer.cjs.min.js.map +1 -0
- package/dist/tolgee-text-observer.esm.min.mjs +2 -0
- package/dist/tolgee-text-observer.esm.min.mjs.map +1 -0
- package/dist/tolgee-text-observer.umd.min.js +2 -0
- package/dist/tolgee-text-observer.umd.min.js.map +1 -0
- package/dist/tolgee-web-tolgee.cjs.min.js +2 -0
- package/dist/tolgee-web-tolgee.cjs.min.js.map +1 -0
- package/dist/tolgee-web-tolgee.esm.min.mjs +2 -0
- package/dist/tolgee-web-tolgee.esm.min.mjs.map +1 -0
- package/dist/tolgee-web-tolgee.umd.min.js +2 -0
- package/dist/tolgee-web-tolgee.umd.min.js.map +1 -0
- package/dist/tolgee-web.cjs.js +27076 -0
- package/dist/tolgee-web.cjs.js.map +1 -0
- package/dist/tolgee-web.cjs.min.js +143 -0
- package/dist/tolgee-web.cjs.min.js.map +1 -0
- package/dist/tolgee-web.esm.js +27052 -0
- package/dist/tolgee-web.esm.js.map +1 -0
- package/dist/tolgee-web.esm.min.mjs +143 -0
- package/dist/tolgee-web.esm.min.mjs.map +1 -0
- package/dist/tolgee-web.umd.js +27082 -0
- package/dist/tolgee-web.umd.js.map +1 -0
- package/dist/tolgee-web.umd.min.js +143 -0
- package/dist/tolgee-web.umd.min.js.map +1 -0
- package/lib/BackendFetch.d.ts +4 -0
- package/lib/BrowserExtensionPlugin/BrowserExtensionPlugin.d.ts +8 -0
- package/lib/BrowserExtensionPlugin/constants.d.ts +3 -0
- package/lib/BrowserExtensionPlugin/loadInContextLib.d.ts +1 -0
- package/lib/ContextUi.d.ts +2 -0
- package/lib/DevBackend.d.ts +2 -0
- package/lib/DevTools.d.ts +3 -0
- package/lib/InContextTools.d.ts +2 -0
- package/lib/InvisibleObserver.d.ts +2 -0
- package/lib/LanguageDetector.d.ts +3 -0
- package/lib/LanguageStorage.d.ts +3 -0
- package/lib/TextObserver.d.ts +2 -0
- package/lib/WebTolgee.d.ts +3 -0
- package/lib/constants.d.ts +5 -0
- package/lib/index.d.ts +5 -0
- package/lib/observers/general/DomHelper.d.ts +4 -0
- package/lib/observers/general/ElementHighlighter.d.ts +10 -0
- package/lib/observers/general/ElementMeta.d.ts +3 -0
- package/lib/observers/general/ElementRegistry.d.ts +11 -0
- package/lib/observers/general/ElementStore.d.ts +10 -0
- package/lib/observers/general/GeneralObserver.d.ts +12 -0
- package/lib/observers/general/MouseEventHandler.d.ts +13 -0
- package/lib/observers/general/NodeHandler.d.ts +6 -0
- package/lib/observers/general/helpers.d.ts +7 -0
- package/lib/observers/invisible/InvisibleWrapper.d.ts +2 -0
- package/lib/observers/invisible/ValueMemory.d.ts +5 -0
- package/lib/observers/invisible/encoderPolyfill.d.ts +8 -0
- package/lib/observers/invisible/secret.d.ts +6 -0
- package/lib/observers/text/TextWrapper.d.ts +8 -0
- package/lib/observers/text/helpers.d.ts +3 -0
- package/lib/tools/decodeApiKey.d.ts +1 -0
- package/lib/tools/extension.d.ts +28 -0
- package/lib/typedIndex.d.ts +11 -0
- package/lib/types.d.ts +28 -0
- package/lib/ui/KeyContextMenu/KeyContextMenu.d.ts +19 -0
- package/lib/ui/KeyDialog/KeyDialog.d.ts +23 -0
- package/lib/ui/KeyDialog/KeyForm.d.ts +2 -0
- package/lib/ui/KeyDialog/LanguageSelect.d.ts +2 -0
- package/lib/ui/KeyDialog/NewWindow.d.ts +2 -0
- package/lib/ui/KeyDialog/NsSelect.d.ts +9 -0
- package/lib/ui/KeyDialog/ScreenshotGallery/ExtensionPrompt.d.ts +6 -0
- package/lib/ui/KeyDialog/ScreenshotGallery/ScreenshotDetail.d.ts +8 -0
- package/lib/ui/KeyDialog/ScreenshotGallery/ScreenshotDropzone.d.ts +6 -0
- package/lib/ui/KeyDialog/ScreenshotGallery/ScreenshotGallery.d.ts +2 -0
- package/lib/ui/KeyDialog/ScreenshotGallery/ScreenshotThumbnail.d.ts +8 -0
- package/lib/ui/KeyDialog/ScreenshotGallery/utils.d.ts +3 -0
- package/lib/ui/KeyDialog/TranslationDialog.d.ts +2 -0
- package/lib/ui/KeyDialog/TranslationDialogContextProvider.d.ts +128 -0
- package/lib/ui/KeyDialog/TranslationDialogWrapper.d.ts +2 -0
- package/lib/ui/KeyDialog/TranslationFields.d.ts +2 -0
- package/lib/ui/KeyDialog/languageHelpers.d.ts +12 -0
- package/lib/ui/KeyDialog/tools.d.ts +3 -0
- package/lib/ui/ThemeProvider.d.ts +2 -0
- package/lib/ui/client/QueryProvider.d.ts +12 -0
- package/lib/ui/client/apiSchema.generated.d.ts +3283 -0
- package/lib/ui/client/client.d.ts +5 -0
- package/lib/ui/client/types.d.ts +58 -0
- package/lib/ui/client/useQueryApi.d.ts +84 -0
- package/lib/ui/common/BodyEnd.d.ts +13 -0
- package/lib/ui/common/FieldTitle.d.ts +2 -0
- package/lib/ui/common/LoadingButton.d.ts +7 -0
- package/lib/ui/index.d.ts +13 -0
- package/lib/ui/tools/createProvider.d.ts +5 -0
- package/lib/ui/tools/isLanguagePermitted.d.ts +1 -0
- package/lib/ui/tools/sleep.d.ts +1 -0
- package/package.json +91 -0
- package/src/BackendFetch.ts +64 -0
- package/src/BrowserExtensionPlugin/BrowserExtensionPlugin.ts +98 -0
- package/src/BrowserExtensionPlugin/constants.ts +3 -0
- package/src/BrowserExtensionPlugin/loadInContextLib.ts +32 -0
- package/src/ContextUi.ts +7 -0
- package/src/DevBackend.ts +30 -0
- package/src/DevTools.ts +9 -0
- package/src/InContextTools.ts +20 -0
- package/src/InvisibleObserver.ts +16 -0
- package/src/LanguageDetector.test.ts +19 -0
- package/src/LanguageDetector.ts +32 -0
- package/src/LanguageStorage.ts +23 -0
- package/src/TextObserver.ts +45 -0
- package/src/WebTolgee.ts +8 -0
- package/src/__test__/browser.extension.test.ts +70 -0
- package/src/__test__/observer.test.ts +13 -0
- package/src/__test__/testObserver.ts +106 -0
- package/src/__test__/testRetranslate.ts +47 -0
- package/src/constants.ts +12 -0
- package/src/index.ts +8 -0
- package/src/observers/general/DomHelper.ts +46 -0
- package/src/observers/general/ElementHighlighter.ts +72 -0
- package/src/observers/general/ElementMeta.ts +17 -0
- package/src/observers/general/ElementRegistry.ts +159 -0
- package/src/observers/general/ElementStore.ts +34 -0
- package/src/observers/general/GeneralObserver.ts +133 -0
- package/src/observers/general/MouseEventHandler.ts +199 -0
- package/src/observers/general/NodeHandler.ts +39 -0
- package/src/observers/general/helpers.ts +65 -0
- package/src/observers/invisible/InvisibleWrapper.test.ts +17 -0
- package/src/observers/invisible/InvisibleWrapper.ts +96 -0
- package/src/observers/invisible/ValueMemory.test.ts +25 -0
- package/src/observers/invisible/ValueMemory.ts +20 -0
- package/src/observers/invisible/encoderPolyfill.ts +96 -0
- package/src/observers/invisible/secret.test.ts +61 -0
- package/src/observers/invisible/secret.ts +68 -0
- package/src/observers/text/TextWrapper.ts +258 -0
- package/src/observers/text/helpers.ts +56 -0
- package/src/tools/decodeApiKey.test.ts +14 -0
- package/src/tools/decodeApiKey.ts +74 -0
- package/src/tools/extension.test.ts +159 -0
- package/src/tools/extension.ts +119 -0
- package/src/typedIndex.ts +13 -0
- package/src/types.ts +33 -0
- package/src/ui/KeyContextMenu/KeyContextMenu.test.ts +51 -0
- package/src/ui/KeyContextMenu/KeyContextMenu.tsx +108 -0
- package/src/ui/KeyDialog/KeyDialog.tsx +67 -0
- package/src/ui/KeyDialog/KeyForm.tsx +208 -0
- package/src/ui/KeyDialog/LanguageSelect.tsx +78 -0
- package/src/ui/KeyDialog/NewWindow.tsx +106 -0
- package/src/ui/KeyDialog/NsSelect.tsx +67 -0
- package/src/ui/KeyDialog/ScreenshotGallery/ExtensionPrompt.tsx +97 -0
- package/src/ui/KeyDialog/ScreenshotGallery/ScreenshotDetail.tsx +33 -0
- package/src/ui/KeyDialog/ScreenshotGallery/ScreenshotDropzone.tsx +138 -0
- package/src/ui/KeyDialog/ScreenshotGallery/ScreenshotGallery.tsx +240 -0
- package/src/ui/KeyDialog/ScreenshotGallery/ScreenshotThumbnail.tsx +113 -0
- package/src/ui/KeyDialog/ScreenshotGallery/utils.ts +17 -0
- package/src/ui/KeyDialog/TranslationDialog.tsx +14 -0
- package/src/ui/KeyDialog/TranslationDialogContextProvider.tsx +464 -0
- package/src/ui/KeyDialog/TranslationDialogWrapper.tsx +44 -0
- package/src/ui/KeyDialog/TranslationFields.tsx +113 -0
- package/src/ui/KeyDialog/languageHelpers.ts +18 -0
- package/src/ui/KeyDialog/tools.ts +30 -0
- package/src/ui/ThemeProvider.tsx +71 -0
- package/src/ui/client/QueryProvider.tsx +38 -0
- package/src/ui/client/apiSchema.generated.ts +3281 -0
- package/src/ui/client/client.ts +155 -0
- package/src/ui/client/types.ts +113 -0
- package/src/ui/client/useQueryApi.ts +121 -0
- package/src/ui/common/BodyEnd.tsx +44 -0
- package/src/ui/common/FieldTitle.tsx +9 -0
- package/src/ui/common/LoadingButton.tsx +45 -0
- package/src/ui/index.ts +88 -0
- package/src/ui/screenshots/ScreenshotPreview.tsx +18 -0
- package/src/ui/tools/createProvider.tsx +54 -0
- package/src/ui/tools/isLanguagePermitted.ts +14 -0
- package/src/ui/tools/sleep.ts +2 -0
- package/types/index.d.ts +9 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { paths } from './apiSchema.generated';
|
|
2
|
+
import { GlobalOptions } from './QueryProvider';
|
|
3
|
+
import { RequestParamsType, ResponseContent } from './types';
|
|
4
|
+
export declare const addProjectIdToUrl: (url: string) => string;
|
|
5
|
+
export declare function client<Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths>(url: Url, method: Method, request: RequestParamsType<Url, Method, Paths>, options: GlobalOptions): Promise<ResponseContent<Url, Method, Paths>>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { paths } from './apiSchema.generated';
|
|
2
|
+
declare type ExcludeAk<T extends Record<string, Record<string, any>>> = Omit<T, 'query'> & {
|
|
3
|
+
query?: Omit<T['query'], 'ak'>;
|
|
4
|
+
};
|
|
5
|
+
export declare type RequestParamsType<Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths> = ExcludeAk<Omit<OperationSchema<Url, Method, Paths>['parameters'], 'header'>> & OperationSchema<Url, Method, Paths>['requestBody'];
|
|
6
|
+
export declare type ResponseContent<Url extends keyof Paths, Method extends keyof Paths[Url], Paths> = OperationSchema<Url, Method, Paths>['responses'][200] extends NotNullAnyContent ? OperationSchema<Url, Method, Paths>['responses'][200]['content']['*/*'] : OperationSchema<Url, Method, Paths>['responses'][200] extends NotNullJsonHalContent ? OperationSchema<Url, Method, Paths>['responses'][200]['content']['application/hal+json'] : OperationSchema<Url, Method, Paths>['responses'][200] extends NotNullJsonContent ? OperationSchema<Url, Method, Paths>['responses'][200]['content']['application/json'] : OperationSchema<Url, Method, Paths>['responses'][201] extends NotNullAnyContent ? OperationSchema<Url, Method, Paths>['responses'][201]['content']['*/*'] : void;
|
|
7
|
+
declare type NotNullAnyContent = {
|
|
8
|
+
content: {
|
|
9
|
+
'*/*': any;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
declare type NotNullJsonHalContent = {
|
|
13
|
+
content: {
|
|
14
|
+
'application/hal+json': any;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare type NotNullJsonContent = {
|
|
18
|
+
content: {
|
|
19
|
+
'application/json': any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
declare type ResponseType = {
|
|
23
|
+
200?: {
|
|
24
|
+
content?: {
|
|
25
|
+
'*/*'?: any;
|
|
26
|
+
'application/json'?: any;
|
|
27
|
+
'application/hal+json'?: any;
|
|
28
|
+
};
|
|
29
|
+
} | unknown;
|
|
30
|
+
201?: {
|
|
31
|
+
content?: {
|
|
32
|
+
'*/*'?: any;
|
|
33
|
+
};
|
|
34
|
+
} | unknown;
|
|
35
|
+
};
|
|
36
|
+
declare type OperationSchemaType = {
|
|
37
|
+
requestBody?: {
|
|
38
|
+
content?: {
|
|
39
|
+
'multipart/form-data'?: {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
};
|
|
42
|
+
'application/json'?: any;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
parameters?: {
|
|
46
|
+
path?: {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
49
|
+
query?: {
|
|
50
|
+
[key: string]: {
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
} | any;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
responses: ResponseType;
|
|
56
|
+
};
|
|
57
|
+
declare type OperationSchema<Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths> = Paths[Url][Method] extends OperationSchemaType ? Paths[Url][Method] : never;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { RequestOptions } from 'https';
|
|
3
|
+
import { UseQueryOptions, Query, QueryClient, UseMutationOptions } from 'react-query';
|
|
4
|
+
import { paths } from './apiSchema.generated';
|
|
5
|
+
import { RequestParamsType, ResponseContent } from './types';
|
|
6
|
+
export declare type QueryProps<Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths> = {
|
|
7
|
+
url: Url;
|
|
8
|
+
method: Method;
|
|
9
|
+
fetchOptions?: RequestOptions;
|
|
10
|
+
options?: UseQueryOptions<ResponseContent<Url, Method, Paths>>;
|
|
11
|
+
} & RequestParamsType<Url, Method, Paths>;
|
|
12
|
+
export declare const useApiQuery: <Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths>(props: QueryProps<Url, Method, Paths>) => import("react-query").UseQueryResult<ResponseContent<Url, Method, Paths>, any>;
|
|
13
|
+
export declare type MutationProps<Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths> = {
|
|
14
|
+
url: Url;
|
|
15
|
+
method: Method;
|
|
16
|
+
fetchOptions?: RequestOptions;
|
|
17
|
+
options?: UseMutationOptions<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>>;
|
|
18
|
+
invalidatePrefix?: string;
|
|
19
|
+
};
|
|
20
|
+
export declare const useApiMutation: <Url extends keyof Paths, Method extends keyof Paths[Url], Paths = paths>(props: MutationProps<Url, Method, Paths>) => {
|
|
21
|
+
mutate: import("react-query").UseMutateFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
22
|
+
mutateAsync: import("react-query").UseMutateAsyncFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
23
|
+
data: undefined;
|
|
24
|
+
error: null;
|
|
25
|
+
isError: false;
|
|
26
|
+
isIdle: true;
|
|
27
|
+
isLoading: false;
|
|
28
|
+
isSuccess: false;
|
|
29
|
+
status: "idle";
|
|
30
|
+
reset: () => void;
|
|
31
|
+
context: unknown;
|
|
32
|
+
failureCount: number;
|
|
33
|
+
isPaused: boolean;
|
|
34
|
+
variables: RequestParamsType<Url, Method, Paths> | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
mutate: import("react-query").UseMutateFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
37
|
+
mutateAsync: import("react-query").UseMutateAsyncFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
38
|
+
data: undefined;
|
|
39
|
+
error: null;
|
|
40
|
+
isError: false;
|
|
41
|
+
isIdle: false;
|
|
42
|
+
isLoading: true;
|
|
43
|
+
isSuccess: false;
|
|
44
|
+
status: "loading";
|
|
45
|
+
reset: () => void;
|
|
46
|
+
context: unknown;
|
|
47
|
+
failureCount: number;
|
|
48
|
+
isPaused: boolean;
|
|
49
|
+
variables: RequestParamsType<Url, Method, Paths> | undefined;
|
|
50
|
+
} | {
|
|
51
|
+
mutate: import("react-query").UseMutateFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
52
|
+
mutateAsync: import("react-query").UseMutateAsyncFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
53
|
+
data: undefined;
|
|
54
|
+
error: any;
|
|
55
|
+
isError: true;
|
|
56
|
+
isIdle: false;
|
|
57
|
+
isLoading: false;
|
|
58
|
+
isSuccess: false;
|
|
59
|
+
status: "error";
|
|
60
|
+
reset: () => void;
|
|
61
|
+
context: unknown;
|
|
62
|
+
failureCount: number;
|
|
63
|
+
isPaused: boolean;
|
|
64
|
+
variables: RequestParamsType<Url, Method, Paths> | undefined;
|
|
65
|
+
} | {
|
|
66
|
+
mutate: import("react-query").UseMutateFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
67
|
+
mutateAsync: import("react-query").UseMutateAsyncFunction<ResponseContent<Url, Method, Paths>, any, RequestParamsType<Url, Method, Paths>, unknown>;
|
|
68
|
+
data: ResponseContent<Url, Method, Paths>;
|
|
69
|
+
error: null;
|
|
70
|
+
isError: false;
|
|
71
|
+
isIdle: false;
|
|
72
|
+
isLoading: false;
|
|
73
|
+
isSuccess: true;
|
|
74
|
+
status: "success";
|
|
75
|
+
reset: () => void;
|
|
76
|
+
context: unknown;
|
|
77
|
+
failureCount: number;
|
|
78
|
+
isPaused: boolean;
|
|
79
|
+
variables: RequestParamsType<Url, Method, Paths> | undefined;
|
|
80
|
+
};
|
|
81
|
+
export declare const matchUrlPrefix: (prefix: string) => {
|
|
82
|
+
predicate: (query: Query) => boolean;
|
|
83
|
+
};
|
|
84
|
+
export declare const invalidateUrlPrefix: (queryClient: QueryClient, prefix: string) => Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare class BodyEnd extends React.PureComponent<{
|
|
3
|
+
document?: Document;
|
|
4
|
+
}> {
|
|
5
|
+
_popup: HTMLElement | null;
|
|
6
|
+
get document(): Document;
|
|
7
|
+
get devTools(): HTMLElement | ShadowRoot;
|
|
8
|
+
componentDidMount(): void;
|
|
9
|
+
componentDidUpdate(): void;
|
|
10
|
+
componentWillUnmount(): void;
|
|
11
|
+
_render(): void;
|
|
12
|
+
render(): null;
|
|
13
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const ScFieldTitle: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FallbackNSTranslation, UiProps, UiInterface, UiKeyOption } from '@tolgee/core';
|
|
2
|
+
export declare class UI implements UiInterface {
|
|
3
|
+
private props;
|
|
4
|
+
private viewerComponent;
|
|
5
|
+
private keyContextMenu;
|
|
6
|
+
constructor(props: UiProps);
|
|
7
|
+
renderViewer(key: string, defaultValue: string | undefined, ns: FallbackNSTranslation): void;
|
|
8
|
+
getKey(props: {
|
|
9
|
+
openEvent: MouseEvent;
|
|
10
|
+
keys: Map<string, string | undefined>;
|
|
11
|
+
}): Promise<string | undefined>;
|
|
12
|
+
handleElementClick(event: MouseEvent, keysAndDefaults: UiKeyOption[]): Promise<void>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type DispatchType<ActionType, DispatchReturn> = (action: ActionType) => DispatchReturn;
|
|
3
|
+
declare type SelectorType<StateType, ReturnType> = (state: StateType) => ReturnType;
|
|
4
|
+
export declare const createProvider: <StateType, ActionType, DispatchReturn, ProviderProps>(body: (props: ProviderProps) => [state: StateType, dispatch: DispatchType<ActionType, DispatchReturn>]) => readonly [React.FC<ProviderProps>, () => DispatchType<ActionType, DispatchReturn>, <SelectorReturn>(selector: SelectorType<StateType, SelectorReturn>) => SelectorReturn];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isLanguagePermitted: (language: string, permittedLanguages: number[] | undefined, allLanguages?: any[]) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const sleep: (ms: number) => Promise<unknown>;
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tolgee/web",
|
|
3
|
+
"version": "4.9.3-rc.128edeb.0",
|
|
4
|
+
"description": "Tolgee for web",
|
|
5
|
+
"main": "./dist/tolgee-web.cjs.js",
|
|
6
|
+
"module": "./dist/tolgee-web.esm.js",
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"directories": {
|
|
10
|
+
"lib": "lib",
|
|
11
|
+
"test": "test"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c rollup.config.js && tsc --project tsconfig.prod.json",
|
|
15
|
+
"clean": "rm -rf build build-e2e dist dist-e2e lib",
|
|
16
|
+
"test": "jest --config ./jest.config.js --collect-coverage",
|
|
17
|
+
"develop": "concurrently \"rollup -c rollup.dev.js -w\" \"tsc --watch --preserveWatchOutput --project tsconfig.prod.json\" ",
|
|
18
|
+
"schema": "openapi-typescript http://localhost:8202/v3/api-docs/Accessible%20with%20API%20key --output ./src/ui/client/apiSchema.generated.ts"
|
|
19
|
+
},
|
|
20
|
+
"author": "Tolgee",
|
|
21
|
+
"license": "BSD-3-Clause",
|
|
22
|
+
"files": [
|
|
23
|
+
"types/**/*",
|
|
24
|
+
"lib/**/*",
|
|
25
|
+
"dist/**/*",
|
|
26
|
+
"src/**/*",
|
|
27
|
+
"index.js"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@tolgee/core": "4.9.3-rc.128edeb.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@babel/preset-typescript": "^7.18.6",
|
|
34
|
+
"@emotion/react": "^11.10.4",
|
|
35
|
+
"@emotion/styled": "^11.10.4",
|
|
36
|
+
"@mui/icons-material": "^5.10.3",
|
|
37
|
+
"@mui/material": "^5.10.4",
|
|
38
|
+
"@rollup/plugin-commonjs": "^22.0.2",
|
|
39
|
+
"@rollup/plugin-node-resolve": "14.0.0",
|
|
40
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
41
|
+
"@rollup/plugin-typescript": "8.5.0",
|
|
42
|
+
"@testing-library/dom": "^8.7.2",
|
|
43
|
+
"@testing-library/jest-dom": "^5.11.4",
|
|
44
|
+
"@types/jest": "^27.0.2",
|
|
45
|
+
"@types/node": "^17.0.8",
|
|
46
|
+
"@types/react": "^17.0.30",
|
|
47
|
+
"@types/react-dom": "^17.0.1",
|
|
48
|
+
"clsx": "^1.1.1",
|
|
49
|
+
"concurrently": "7.4.0",
|
|
50
|
+
"jest": "^27.2.4",
|
|
51
|
+
"jest-fetch-mock": "^3.0.3",
|
|
52
|
+
"openapi-typescript": "^4.3.0",
|
|
53
|
+
"react": "^17.0.1",
|
|
54
|
+
"react-dom": "^17.0.1",
|
|
55
|
+
"react-dropzone": "^11.4.2",
|
|
56
|
+
"react-query": "^3.39.2",
|
|
57
|
+
"rollup": "2.79.0",
|
|
58
|
+
"rollup-plugin-bundle-size": "^1.0.3",
|
|
59
|
+
"rollup-plugin-replace": "2.2.0",
|
|
60
|
+
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
61
|
+
"rollup-plugin-terser": "7.0.2",
|
|
62
|
+
"rollup-plugin-visualizer": "^5.8.1",
|
|
63
|
+
"ts-jest": "^27.0.5",
|
|
64
|
+
"ts-loader": "^9.2.6",
|
|
65
|
+
"typescript": "4.8.3",
|
|
66
|
+
"use-context-selector": "^1.4.1"
|
|
67
|
+
},
|
|
68
|
+
"repository": {
|
|
69
|
+
"type": "git",
|
|
70
|
+
"url": "git+https://github.com/tolgee/tolgee-js.git"
|
|
71
|
+
},
|
|
72
|
+
"exports": {
|
|
73
|
+
"require": "./dist/tolgee-web.cjs.js",
|
|
74
|
+
"import": "./dist/tolgee-web.esm.js"
|
|
75
|
+
},
|
|
76
|
+
"keywords": [
|
|
77
|
+
"localization",
|
|
78
|
+
"languages",
|
|
79
|
+
"internationalization",
|
|
80
|
+
"framework",
|
|
81
|
+
"localize"
|
|
82
|
+
],
|
|
83
|
+
"bugs": {
|
|
84
|
+
"url": "https://github.com/tolgee/tolgee-js/issues"
|
|
85
|
+
},
|
|
86
|
+
"homepage": "https://github.com/tolgee/tolgee-js#readme",
|
|
87
|
+
"gitHead": "a22312d123c766ce751e5d629ff352e4a1fbe6c2",
|
|
88
|
+
"publishConfig": {
|
|
89
|
+
"access": "public"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { BackendInterface, TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
import { GetPath, BackendOptions } from './types';
|
|
3
|
+
|
|
4
|
+
const trimSlashes = (path: string) => {
|
|
5
|
+
if (path.endsWith('/')) {
|
|
6
|
+
return path.slice(0, -1);
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const defaultGetPath: GetPath = ({ namespace, language, prefix }) => {
|
|
12
|
+
if (namespace) {
|
|
13
|
+
return `${trimSlashes(prefix)}/${language}/${namespace}.json`;
|
|
14
|
+
} else {
|
|
15
|
+
return `${trimSlashes(prefix)}/${language}.json`;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const defaultGetData = (r: Response) => r.json();
|
|
20
|
+
|
|
21
|
+
const DEFAULT_OPTIONS = {
|
|
22
|
+
prefix: '/i18n',
|
|
23
|
+
getPath: defaultGetPath,
|
|
24
|
+
getData: defaultGetData,
|
|
25
|
+
headers: {
|
|
26
|
+
Accept: 'application/json',
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const BackendFetchCreator = (
|
|
31
|
+
options?: Partial<BackendOptions>
|
|
32
|
+
): BackendInterface => {
|
|
33
|
+
const { prefix, getPath, getData, headers, ...fetchOptions }: BackendOptions =
|
|
34
|
+
{
|
|
35
|
+
...DEFAULT_OPTIONS,
|
|
36
|
+
...options,
|
|
37
|
+
headers: {
|
|
38
|
+
...DEFAULT_OPTIONS.headers,
|
|
39
|
+
...options?.headers,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
getRecord({ namespace, language }) {
|
|
44
|
+
const path = getPath({
|
|
45
|
+
namespace,
|
|
46
|
+
language,
|
|
47
|
+
prefix,
|
|
48
|
+
});
|
|
49
|
+
return fetch(path, { headers, ...fetchOptions }).then((r) => {
|
|
50
|
+
if (!r.ok) {
|
|
51
|
+
throw new Error(`${r.url} ${r.status}`);
|
|
52
|
+
}
|
|
53
|
+
return getData(r);
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const BackendFetch =
|
|
60
|
+
(options?: Partial<BackendOptions>): TolgeePlugin =>
|
|
61
|
+
(tolgee, tools) => {
|
|
62
|
+
tools.addBackend(BackendFetchCreator(options));
|
|
63
|
+
return tolgee;
|
|
64
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
import { Handshaker } from '../tools/extension';
|
|
3
|
+
import { loadInContextLib } from './loadInContextLib';
|
|
4
|
+
|
|
5
|
+
export const API_KEY_LOCAL_STORAGE = '__tolgee_apiKey';
|
|
6
|
+
export const API_URL_LOCAL_STORAGE = '__tolgee_apiUrl';
|
|
7
|
+
|
|
8
|
+
function getCredentials() {
|
|
9
|
+
const apiKey = sessionStorage.getItem(API_KEY_LOCAL_STORAGE) || undefined;
|
|
10
|
+
const apiUrl = sessionStorage.getItem(API_URL_LOCAL_STORAGE) || undefined;
|
|
11
|
+
|
|
12
|
+
if (!apiKey || !apiUrl) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
apiKey,
|
|
18
|
+
apiUrl,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function clearSessionStorage() {
|
|
23
|
+
sessionStorage.removeItem(API_KEY_LOCAL_STORAGE);
|
|
24
|
+
sessionStorage.removeItem(API_URL_LOCAL_STORAGE);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function onDocumentReady(callback: () => void) {
|
|
28
|
+
// in case the document is already rendered
|
|
29
|
+
if (document.readyState !== 'loading') {
|
|
30
|
+
Promise.resolve().then(() => {
|
|
31
|
+
callback();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
// modern browsers
|
|
35
|
+
else if (document.addEventListener) {
|
|
36
|
+
document.addEventListener('DOMContentLoaded', callback);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type BrowserExtensionProps = {
|
|
41
|
+
noReload?: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let BrowserExtensionPlugin = (): TolgeePlugin => (tolgee) => tolgee;
|
|
45
|
+
|
|
46
|
+
if (typeof window !== 'undefined') {
|
|
47
|
+
BrowserExtensionPlugin = (): TolgeePlugin => (tolgee) => {
|
|
48
|
+
const handshaker = Handshaker();
|
|
49
|
+
const getConfig = () =>
|
|
50
|
+
({
|
|
51
|
+
// prevent extension downloading ui library
|
|
52
|
+
uiPresent: true,
|
|
53
|
+
uiVersion: undefined,
|
|
54
|
+
// tolgee mode
|
|
55
|
+
mode: tolgee.isDev() ? 'development' : 'production',
|
|
56
|
+
// pass credentials
|
|
57
|
+
config: {
|
|
58
|
+
apiUrl: tolgee.getInitialOptions().apiUrl || '',
|
|
59
|
+
apiKey: tolgee.getInitialOptions().apiKey || '',
|
|
60
|
+
},
|
|
61
|
+
} as const);
|
|
62
|
+
|
|
63
|
+
const getTolgeePlugin = async (): Promise<TolgeePlugin> => {
|
|
64
|
+
const InContextTools = await loadInContextLib(
|
|
65
|
+
process.env.TOLGEE_UI_VERSION || 'rc'
|
|
66
|
+
);
|
|
67
|
+
return (tolgee) => {
|
|
68
|
+
const credentials = getCredentials()!;
|
|
69
|
+
tolgee.use(InContextTools(credentials));
|
|
70
|
+
return tolgee;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
tolgee.on('running', ({ value: isRunning }) => {
|
|
75
|
+
if (isRunning) {
|
|
76
|
+
onDocumentReady(() => {
|
|
77
|
+
handshaker.update(getConfig()).catch(clearSessionStorage);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const credentials = getCredentials();
|
|
83
|
+
if (credentials) {
|
|
84
|
+
getTolgeePlugin()
|
|
85
|
+
.then((plugin) => {
|
|
86
|
+
tolgee.use(plugin);
|
|
87
|
+
})
|
|
88
|
+
.catch(() => {
|
|
89
|
+
// eslint-disable-next-line no-console
|
|
90
|
+
console.error('Tolgee: Failed to load in-context tools');
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return tolgee;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { BrowserExtensionPlugin };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { InContextTools } from '../InContextTools';
|
|
2
|
+
import {
|
|
3
|
+
IN_CONTEXT_FILE,
|
|
4
|
+
IN_CONTEXT_UMD_NAME,
|
|
5
|
+
IN_CONTEXT_EXPORT_NAME,
|
|
6
|
+
} from './constants';
|
|
7
|
+
|
|
8
|
+
const CDN_URL = 'https://cdn.jsdelivr.net/npm';
|
|
9
|
+
|
|
10
|
+
function injectScript(src: string) {
|
|
11
|
+
return new Promise<void>((resolve, reject) => {
|
|
12
|
+
const script = document.createElement('script');
|
|
13
|
+
script.src = src;
|
|
14
|
+
script.addEventListener('load', () => resolve());
|
|
15
|
+
script.addEventListener('error', (e) => reject(e.error));
|
|
16
|
+
document.body.appendChild(script);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let injectPromise = null as any as Promise<typeof InContextTools>;
|
|
21
|
+
|
|
22
|
+
export function loadInContextLib(version?: string) {
|
|
23
|
+
if (!injectPromise) {
|
|
24
|
+
injectPromise = injectScript(
|
|
25
|
+
`${CDN_URL}/@tolgee/web@${version || 'latest'}/dist/${IN_CONTEXT_FILE}`
|
|
26
|
+
).then(() => {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return window[IN_CONTEXT_UMD_NAME][IN_CONTEXT_EXPORT_NAME];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return injectPromise;
|
|
32
|
+
}
|
package/src/ContextUi.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BackendDevInterface, TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
import { getProjectIdFromApiKey } from './tools/decodeApiKey';
|
|
3
|
+
|
|
4
|
+
const DevBackendCreator = (): BackendDevInterface => ({
|
|
5
|
+
getRecord({ apiUrl, apiKey, language, namespace, projectId }) {
|
|
6
|
+
if (namespace) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const pId = getProjectIdFromApiKey(apiKey) ?? projectId;
|
|
10
|
+
const url =
|
|
11
|
+
pId !== undefined
|
|
12
|
+
? `${apiUrl}/v2/projects/${pId}/translations/${language}`
|
|
13
|
+
: `${apiUrl}/v2/projects/translations/${language}`;
|
|
14
|
+
|
|
15
|
+
return fetch(url, {
|
|
16
|
+
headers: { 'X-API-Key': apiKey || '' },
|
|
17
|
+
}).then((r) => {
|
|
18
|
+
if (r.ok) {
|
|
19
|
+
return r.json().then((data) => data[language]);
|
|
20
|
+
} else {
|
|
21
|
+
throw new Error(r.statusText);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const DevBackend = (): TolgeePlugin => (tolgee, tools) => {
|
|
28
|
+
tools.setDevBackend(DevBackendCreator());
|
|
29
|
+
return tolgee;
|
|
30
|
+
};
|
package/src/DevTools.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DevCredentials, TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
import { InvisibleObserver } from './InvisibleObserver';
|
|
3
|
+
import { DevBackend } from './DevBackend';
|
|
4
|
+
import { ContextUi } from './ContextUi';
|
|
5
|
+
|
|
6
|
+
export const InContextTools =
|
|
7
|
+
(overrideCredentials?: DevCredentials): TolgeePlugin =>
|
|
8
|
+
(tolgee, tools) => {
|
|
9
|
+
tolgee.use(DevBackend());
|
|
10
|
+
if (!tools.hasObserver()) {
|
|
11
|
+
tolgee.use(InvisibleObserver());
|
|
12
|
+
}
|
|
13
|
+
if (!tools.hasUi()) {
|
|
14
|
+
tolgee.use(ContextUi());
|
|
15
|
+
}
|
|
16
|
+
if (overrideCredentials) {
|
|
17
|
+
tools.overrideCredentials(overrideCredentials);
|
|
18
|
+
}
|
|
19
|
+
return tolgee;
|
|
20
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ObserverInterface, TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
import { GeneralObserver } from './observers/general/GeneralObserver';
|
|
3
|
+
import { InvisibleWrapper } from './observers/invisible/InvisibleWrapper';
|
|
4
|
+
|
|
5
|
+
const InvisibleObserverCreator =
|
|
6
|
+
(): ObserverInterface =>
|
|
7
|
+
({ onClick, options }) => {
|
|
8
|
+
const wrapper = InvisibleWrapper();
|
|
9
|
+
const observer = GeneralObserver(wrapper, options, onClick);
|
|
10
|
+
return { ...observer, retranslate: () => {}, outputNotFormattable: false };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const InvisibleObserver = (): TolgeePlugin => (tolgee, tools) => {
|
|
14
|
+
tools.setObserver(InvisibleObserverCreator());
|
|
15
|
+
return tolgee;
|
|
16
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
jest.autoMockOff();
|
|
2
|
+
import { LanguageDetectorCreator } from './LanguageDetector';
|
|
3
|
+
|
|
4
|
+
describe('language detector', () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
const languageGetter = jest.spyOn(window.navigator, 'language', 'get');
|
|
7
|
+
languageGetter.mockReturnValue('cs-CZ');
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it('detects language', () => {
|
|
11
|
+
const detector = LanguageDetectorCreator();
|
|
12
|
+
|
|
13
|
+
const result = detector.getLanguage({
|
|
14
|
+
availableLanguages: ['cs', 'sk'],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
expect(result).toEqual('cs');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LanguageDetectorInterface, TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
|
|
3
|
+
export const LanguageDetectorCreator = (): LanguageDetectorInterface => {
|
|
4
|
+
return {
|
|
5
|
+
getLanguage({ availableLanguages }) {
|
|
6
|
+
if (typeof window !== 'undefined' && availableLanguages) {
|
|
7
|
+
const preferred = window.navigator.language;
|
|
8
|
+
const exactMatch = availableLanguages.find((l) => l === preferred);
|
|
9
|
+
if (exactMatch) {
|
|
10
|
+
return exactMatch;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const getTwoLetters = (fullTag: string) =>
|
|
14
|
+
fullTag.replace(/^(.+?)(-.*)?$/, '$1');
|
|
15
|
+
|
|
16
|
+
const preferredTwoLetter = getTwoLetters(window.navigator.language);
|
|
17
|
+
const twoLetterMatch = availableLanguages.find(
|
|
18
|
+
(l) => getTwoLetters(l) === preferredTwoLetter
|
|
19
|
+
);
|
|
20
|
+
if (twoLetterMatch) {
|
|
21
|
+
return twoLetterMatch;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const LanguageDetector = (): TolgeePlugin => (tolgee, tools) => {
|
|
30
|
+
tools.setLanguageDetector(LanguageDetectorCreator());
|
|
31
|
+
return tolgee;
|
|
32
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { LanguageStorageInterface, TolgeePlugin } from '@tolgee/core';
|
|
2
|
+
|
|
3
|
+
const CURRENT_LANGUAGE_LOCAL_STORAGE_KEY = '__tolgee_currentLanguage';
|
|
4
|
+
|
|
5
|
+
export const LanguageStorageCreator = (): LanguageStorageInterface => {
|
|
6
|
+
return {
|
|
7
|
+
getLanguage() {
|
|
8
|
+
const storedLanguage = localStorage.getItem(
|
|
9
|
+
CURRENT_LANGUAGE_LOCAL_STORAGE_KEY
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
return storedLanguage || undefined;
|
|
13
|
+
},
|
|
14
|
+
setLanguage(language: string) {
|
|
15
|
+
localStorage.setItem(CURRENT_LANGUAGE_LOCAL_STORAGE_KEY, language);
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const LanguageStorage = (): TolgeePlugin => (tolgee, tools) => {
|
|
21
|
+
tools.setLanguageStorage(LanguageStorageCreator());
|
|
22
|
+
return tolgee;
|
|
23
|
+
};
|