@guttools/translation-tool 0.0.0-stage → 0.1.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/index.cjs +756 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +735 -0
- package/package.json +38 -4
- package/README.md +0 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
interface Language {
|
|
5
|
+
code: string;
|
|
6
|
+
name: string;
|
|
7
|
+
native: string;
|
|
8
|
+
rtl?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const LANGUAGES: Language[];
|
|
11
|
+
|
|
12
|
+
interface TranslateProviderProps {
|
|
13
|
+
/** Public key from the dashboard, e.g. "pk_live_abc123". */
|
|
14
|
+
projectKey: string;
|
|
15
|
+
/** Language the site is written in. Defaults to "en". */
|
|
16
|
+
sourceLang?: string;
|
|
17
|
+
/** Language codes offered in the dropdown. Defaults to every supported language. */
|
|
18
|
+
languages?: string[];
|
|
19
|
+
/** Pick the visitor's browser language on their first visit. Defaults to false. */
|
|
20
|
+
detectBrowserLanguage?: boolean;
|
|
21
|
+
/** Override the translation server URL. */
|
|
22
|
+
apiUrl?: string;
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
interface TranslateContextValue {
|
|
26
|
+
lang: string;
|
|
27
|
+
sourceLang: string;
|
|
28
|
+
languages: Language[];
|
|
29
|
+
setLang: (code: string) => void;
|
|
30
|
+
loading: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function TranslateProvider({ projectKey, sourceLang, languages, detectBrowserLanguage, apiUrl, children, }: TranslateProviderProps): react.JSX.Element;
|
|
33
|
+
declare function useTranslate(): TranslateContextValue;
|
|
34
|
+
|
|
35
|
+
interface LanguageSelectProps {
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
"aria-label"?: string;
|
|
39
|
+
}
|
|
40
|
+
/** A native <select> of every enabled language. Style it like any select. */
|
|
41
|
+
declare function LanguageSelect({ className, style, "aria-label": ariaLabel }: LanguageSelectProps): react.JSX.Element;
|
|
42
|
+
|
|
43
|
+
interface EngineOptions {
|
|
44
|
+
projectKey: string;
|
|
45
|
+
apiUrl: string;
|
|
46
|
+
sourceLang: string;
|
|
47
|
+
}
|
|
48
|
+
declare class TranslationEngine {
|
|
49
|
+
private opts;
|
|
50
|
+
private lang;
|
|
51
|
+
private dicts;
|
|
52
|
+
private dictLoads;
|
|
53
|
+
private bundlesFetched;
|
|
54
|
+
private bundleWait;
|
|
55
|
+
private textSlots;
|
|
56
|
+
private attrSlots;
|
|
57
|
+
private pending;
|
|
58
|
+
private inflight;
|
|
59
|
+
private failed;
|
|
60
|
+
private flushTimer;
|
|
61
|
+
private saveTimer;
|
|
62
|
+
private observer;
|
|
63
|
+
private path;
|
|
64
|
+
private generation;
|
|
65
|
+
constructor(opts: EngineOptions);
|
|
66
|
+
get language(): string;
|
|
67
|
+
/** Switch the page to `lang`. Resolves once cached strings are applied. */
|
|
68
|
+
setLanguage(lang: string): Promise<void>;
|
|
69
|
+
/** Called on client-side navigation so the next page's bundle is fetched. */
|
|
70
|
+
onNavigate(): void;
|
|
71
|
+
stop(): void;
|
|
72
|
+
private connect;
|
|
73
|
+
private disconnect;
|
|
74
|
+
private onMutations;
|
|
75
|
+
private scan;
|
|
76
|
+
private visitText;
|
|
77
|
+
private visitAttrs;
|
|
78
|
+
private visitAttr;
|
|
79
|
+
private applySlot;
|
|
80
|
+
/** Re-run lookups for every slot still showing source text. */
|
|
81
|
+
private reapply;
|
|
82
|
+
private restoreAll;
|
|
83
|
+
private prune;
|
|
84
|
+
private dictKey;
|
|
85
|
+
private ensureDict;
|
|
86
|
+
private merge;
|
|
87
|
+
private fetchBundle;
|
|
88
|
+
private scheduleFlush;
|
|
89
|
+
private flush;
|
|
90
|
+
private sendBatch;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type EngineOptions, LANGUAGES, type Language, LanguageSelect, type LanguageSelectProps, TranslateProvider, type TranslateProviderProps, TranslationEngine, useTranslate };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
interface Language {
|
|
5
|
+
code: string;
|
|
6
|
+
name: string;
|
|
7
|
+
native: string;
|
|
8
|
+
rtl?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare const LANGUAGES: Language[];
|
|
11
|
+
|
|
12
|
+
interface TranslateProviderProps {
|
|
13
|
+
/** Public key from the dashboard, e.g. "pk_live_abc123". */
|
|
14
|
+
projectKey: string;
|
|
15
|
+
/** Language the site is written in. Defaults to "en". */
|
|
16
|
+
sourceLang?: string;
|
|
17
|
+
/** Language codes offered in the dropdown. Defaults to every supported language. */
|
|
18
|
+
languages?: string[];
|
|
19
|
+
/** Pick the visitor's browser language on their first visit. Defaults to false. */
|
|
20
|
+
detectBrowserLanguage?: boolean;
|
|
21
|
+
/** Override the translation server URL. */
|
|
22
|
+
apiUrl?: string;
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
}
|
|
25
|
+
interface TranslateContextValue {
|
|
26
|
+
lang: string;
|
|
27
|
+
sourceLang: string;
|
|
28
|
+
languages: Language[];
|
|
29
|
+
setLang: (code: string) => void;
|
|
30
|
+
loading: boolean;
|
|
31
|
+
}
|
|
32
|
+
declare function TranslateProvider({ projectKey, sourceLang, languages, detectBrowserLanguage, apiUrl, children, }: TranslateProviderProps): react.JSX.Element;
|
|
33
|
+
declare function useTranslate(): TranslateContextValue;
|
|
34
|
+
|
|
35
|
+
interface LanguageSelectProps {
|
|
36
|
+
className?: string;
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
"aria-label"?: string;
|
|
39
|
+
}
|
|
40
|
+
/** A native <select> of every enabled language. Style it like any select. */
|
|
41
|
+
declare function LanguageSelect({ className, style, "aria-label": ariaLabel }: LanguageSelectProps): react.JSX.Element;
|
|
42
|
+
|
|
43
|
+
interface EngineOptions {
|
|
44
|
+
projectKey: string;
|
|
45
|
+
apiUrl: string;
|
|
46
|
+
sourceLang: string;
|
|
47
|
+
}
|
|
48
|
+
declare class TranslationEngine {
|
|
49
|
+
private opts;
|
|
50
|
+
private lang;
|
|
51
|
+
private dicts;
|
|
52
|
+
private dictLoads;
|
|
53
|
+
private bundlesFetched;
|
|
54
|
+
private bundleWait;
|
|
55
|
+
private textSlots;
|
|
56
|
+
private attrSlots;
|
|
57
|
+
private pending;
|
|
58
|
+
private inflight;
|
|
59
|
+
private failed;
|
|
60
|
+
private flushTimer;
|
|
61
|
+
private saveTimer;
|
|
62
|
+
private observer;
|
|
63
|
+
private path;
|
|
64
|
+
private generation;
|
|
65
|
+
constructor(opts: EngineOptions);
|
|
66
|
+
get language(): string;
|
|
67
|
+
/** Switch the page to `lang`. Resolves once cached strings are applied. */
|
|
68
|
+
setLanguage(lang: string): Promise<void>;
|
|
69
|
+
/** Called on client-side navigation so the next page's bundle is fetched. */
|
|
70
|
+
onNavigate(): void;
|
|
71
|
+
stop(): void;
|
|
72
|
+
private connect;
|
|
73
|
+
private disconnect;
|
|
74
|
+
private onMutations;
|
|
75
|
+
private scan;
|
|
76
|
+
private visitText;
|
|
77
|
+
private visitAttrs;
|
|
78
|
+
private visitAttr;
|
|
79
|
+
private applySlot;
|
|
80
|
+
/** Re-run lookups for every slot still showing source text. */
|
|
81
|
+
private reapply;
|
|
82
|
+
private restoreAll;
|
|
83
|
+
private prune;
|
|
84
|
+
private dictKey;
|
|
85
|
+
private ensureDict;
|
|
86
|
+
private merge;
|
|
87
|
+
private fetchBundle;
|
|
88
|
+
private scheduleFlush;
|
|
89
|
+
private flush;
|
|
90
|
+
private sendBatch;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { type EngineOptions, LANGUAGES, type Language, LanguageSelect, type LanguageSelectProps, TranslateProvider, type TranslateProviderProps, TranslationEngine, useTranslate };
|