-
Notifications
You must be signed in to change notification settings - Fork 62
/
index.ts
124 lines (112 loc) · 2.62 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { NativeModules, Platform } from 'react-native';
export enum TranslateLanguage {
AFRIKAANS = 'af',
ALBANIAN = 'sq',
ARABIC = 'ar',
BELARUSIAN = 'be',
BULGARIAN = 'bg',
BENGALI = 'bn',
CATALAN = 'ca',
CHINESE = 'zh',
CROATIAN = 'hr',
CZECH = 'cs',
DANISH = 'da',
DUTCH = 'nl',
ENGLISH = 'en',
ESPERANTO = 'eo',
ESTONIAN = 'et',
FINNISH = 'fi',
FRENCH = 'fr',
GALICIAN = 'gl',
GEORGIAN = 'ka',
GERMAN = 'de',
GREEK = 'el',
GUJARATI = 'gu',
HAITIAN_CREOLE = 'ht',
HEBREW = 'he',
HINDI = 'hi',
HUNGARIAN = 'hu',
ICELANDIC = 'is',
INDONESIAN = 'id',
IRISH = 'ga',
ITALIAN = 'it',
JAPANESE = 'ja',
KANNADA = 'kn',
KOREAN = 'ko',
LITHUANIAN = 'lt',
LATVIAN = 'lv',
MACEDONIAN = 'mk',
MARATHI = 'mr',
MALAY = 'ms',
MALTESE = 'mt',
NORWEGIAN = 'no',
PERSIAN = 'fa',
POLISH = 'pl',
PORTUGUESE = 'pt',
ROMANIAN = 'ro',
RUSSIAN = 'ru',
SLOVAK = 'sk',
SLOVENIAN = 'sl',
SPANISH = 'es',
SWEDISH = 'sv',
SWAHILI = 'sw',
TAGALOG = 'tl',
TAMIL = 'ta',
TELUGU = 'te',
THAI = 'th',
TURKISH = 'tr',
UKRAINIAN = 'uk',
URDU = 'ur',
VIETNAMESE = 'vi',
WELSH = 'cy',
}
export interface TranslateTextResult {}
export interface TranslateTextOptions {
/** Text to translate */
text: string;
/** Source language (Language code to translate from) */
sourceLanguage: TranslateLanguage;
/** Target language (Language code to translate to) */
targetLanguage: TranslateLanguage;
/**
* Whether or not to download the model if needed
*
* @default false
*/
downloadModelIfNeeded?: boolean;
/**
* Whether or not to download model *only using WiFi*
*
* @requires `downloadModelIfNeeded` to be `true`
* @default false
*/
requireWifi?: boolean;
/**
* Whether or not to download model *only while charging*
*
* **Note:** _This will only work on Android >= 24_
*
* @requires `downloadModelIfNeeded` to be `true`
* @default false
*/
requireCharging?: boolean;
}
interface ITranslateText {
translate: (options: TranslateTextOptions) => Promise<TranslateTextResult>;
}
const LINKING_ERROR =
`The package '@react-native-ml-kit/translate-text' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';
const TranslateText: ITranslateText = NativeModules.TranslateText
? NativeModules.TranslateText
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
export default TranslateText;