blob: ce3f5fba897ec016bc31bf336a3b027c30bdbfdd (
plain)
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
|
export type Result<T> = { ok: T } | { error: string };
export type AsyncRes<T> = Promise<Result<T>>;
// Language object structure for API responses
export interface State {
user: { name: string; id: number } | null;
}
export interface Language {
code: string;
name: string;
nativeName?: string;
supportsSource?: boolean;
supportsTarget?: boolean;
}
// Common interface for all translation services
export interface TranslationService {
endpoint: string;
translate(
text: string,
sourceLang: string,
targetLang: string,
): AsyncRes<string>;
getSupportedLanguages(): AsyncRes<Language[]>;
detect?: (text: string) => Promise<string>;
transliterate?: (
text: string[],
lang: string,
fromScript: string,
toScript: string,
) => AsyncRes<string>;
}
// Service credentials interface
export interface TranslationCredentials {
apiKey: string;
region?: string;
endpoint?: string;
projectId?: string;
}
// Translation error class for consistent error handling
export class TranslationError extends Error {
public statusCode: number;
public provider: string;
constructor(message: string, statusCode: number = 500, provider: string) {
super(message);
this.name = "TranslationError";
this.statusCode = statusCode;
this.provider = provider;
}
}
// Translation request tracking for rate limiting and analytics
export interface TranslationRequest {
id: string;
timestamp: number;
userId: string;
provider: string;
source: string;
target: string;
characters: number;
success: boolean;
processingTimeMs: number;
}
export type WordData = {
spelling: string;
lang: string;
ipa: string;
meanings: Meaning[];
references?: any;
};
export type Meaning = {
pos: string; // part of speech;
meaning: string[];
etymology: string;
references?: any;
};
export type Paged<T> = { results: T; page: number };
// export type Paged<T> = T & { page: number };
export type AddWord = {
spelling: string;
lang: string;
syllables?: number;
frequency?: number;
prosody?: string;
type: "word" | "expression" | "syllable";
ipa?: string;
confidence?: number;
};
export type AddSense = {
id?: number;
parent_id: number | bigint;
spelling: string;
etymology?: string;
pos?: string;
ipa?: string;
prosody?: string;
senses?: string;
forms?: string;
related?: string;
confidence?: number;
};
|