aboutsummaryrefslogtreecommitdiff
path: root/types/ext/translation.d.ts
blob: 2e4d1a660dd56bbae4826f321129abaac9bb1ab6 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 2023-2024  Yomitan Authors
 * Copyright (C) 2022  Yomichan Authors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import type * as Dictionary from './dictionary';
import type {SearchResolution} from 'settings';

// Kanji

/**
 * An options object for use with `Translator.findKanji`.
 */
export type FindKanjiOptions = {
    /**
     * The mapping of dictionaries to search for kanji in.
     * The key is the dictionary name.
     */
    enabledDictionaryMap: KanjiEnabledDictionaryMap;
    /**
     * Whether or not non-Japanese characters should be searched.
     */
    removeNonJapaneseCharacters: boolean;
};

/**
 * Details about a dictionary.
 */
export type FindKanjiDictionary = {
    /**
     * The index of the dictionary
     */
    index: number;
    /**
     * The priority of the dictionary
     */
    priority: number;
};

// Terms

/**
 * An options object for use with `Translator.findTerms`.
 */
export type FindTermsOptions = {
    /**
     * The matching type for looking up terms.
     */
    matchType: FindTermsMatchType;
    /**
     * Whether or not deinflection should be performed.
     */
    deinflect: boolean;
    /**
     * The name of the primary dictionary to search.
     */
    mainDictionary: string;
    /**
     * The name of the frequency dictionary used for sorting
     */
    sortFrequencyDictionary: string | null;
    /**
     * The order used when using a sorting dictionary.
     */
    sortFrequencyDictionaryOrder: FindTermsSortOrder;
    /**
     * Whether or not non-Japanese characters should be searched.
     */
    removeNonJapaneseCharacters: boolean;
    /**
     * An iterable sequence of text replacements to be applied during the term lookup process.
     */
    textReplacements: FindTermsTextReplacements;
    /**
     * The mapping of dictionaries to search for terms in.
     * The key is the dictionary name.
     */
    enabledDictionaryMap: TermEnabledDictionaryMap;
    /**
     * A set of dictionary names which should have definitions removed.
     */
    excludeDictionaryDefinitions: Set<string> | null;
    /**
     * Whether every substring should be searched for, or only whole words.
     */
    searchResolution: SearchResolution;
    /**
     * ISO-639 code of the language.
     */
    language: string;
};

/**
 * The matching type for looking up terms.
 */
export type FindTermsMatchType = Dictionary.TermSourceMatchType;

/**
 * A sorting order to use when finding terms.
 */
export type FindTermsSortOrder = 'ascending' | 'descending';

/**
 * Information about how text should be replaced when looking up terms.
 */
export type FindTermsTextReplacement = {
    /**
     * The pattern to replace.
     */
    pattern: RegExp;
    /**
     * The replacement string. This can contain special sequences, such as `$&`.
     */
    replacement: string;
};

/**
 * Multiple text replacements.
 */
export type FindTermsTextReplacements = (FindTermsTextReplacement[] | null)[];

/**
 * Details about a dictionary.
 */
export type FindTermDictionary = {
    /**
     * The index of the dictionary
     */
    index: number;
    /**
     * The priority of the dictionary
     */
    priority: number;
    /**
     * Whether or not secondary term searches are allowed for this dictionary.
     */
    allowSecondarySearches: boolean;
    /**
     * Whether this dictionary's part of speech rules should be used to filter results.
     */
    partsOfSpeechFilter: boolean;
    /**
     * Whether to use the deinflections from this dictionary.
     */
    useDeinflections: boolean;
};

export type TermEnabledDictionaryMap = Map<string, FindTermDictionary>;

export type KanjiEnabledDictionaryMap = Map<string, FindKanjiDictionary>;