aboutsummaryrefslogtreecommitdiff
path: root/types/ext/language.d.ts
blob: ccc668af996fd5a069ba77fdf9b67b4ccdc0729d (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
/*
 * Copyright (C) 2024  Yomitan 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 {LanguageTransformDescriptor} from './language-transformer.js';

export type TextProcessorOptions<T = unknown> = T[];

export type TextProcessorFunction<T = unknown> = (str: string, setting: T) => string;

/**
 * Text pre- and post-processors are used during the translation process to create alternate versions of the input text to search for.
 * This is helpful when the input text doesn't exactly match the term or expression found in the database.
 * When a language has multiple processors, the translator will generate variants of the text by applying all combinations of the processors.
 */
export type TextProcessor<T = unknown> = {
    name: string;
    description: string;
    options: TextProcessorOptions<T>;
    process: TextProcessorFunction<T>;
};

export type ReadingNormalizer = (str: string) => string;

export type BidirectionalPreprocessorOptions = 'off' | 'direct' | 'inverse';

export type BidirectionalConversionPreprocessor = TextProcessor<BidirectionalPreprocessorOptions>;

export type LanguageAndProcessors = {
    iso: string;
    textPreprocessors?: TextProcessorWithId<unknown>[];
    textPostprocessors?: TextProcessorWithId<unknown>[];
};

export type LanguageAndReadingNormalizer = {
    iso: string;
    readingNormalizer: ReadingNormalizer;
};

export type LanguageAndTransforms = {
    iso: string;
    languageTransforms: LanguageTransformDescriptor;
};

export type TextProcessorWithId<T = unknown> = {
    id: string;
    textProcessor: TextProcessor<T>;
};

export type LanguageSummary = {
    name: string;
    iso: string;
    iso639_3: string;
    exampleText: string;
};