aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authorStefanVukovic99 <stefanvukovic44@gmail.com>2024-04-21 17:15:08 +0200
committerGitHub <noreply@github.com>2024-04-21 15:15:08 +0000
commit07258ecc35c1a05aa1581a54c9f47a40ce3d76c9 (patch)
tree0a73bc6c1224710906ef3cded2a19399fc626f12 /types
parent22904d166d5ea33667458ccd0fde36e77d0ff65d (diff)
rework text processors (#793)24.4.21.0
* rework text processors * rename text-preprocessors file * Fix search header left margins on small screens (#839) * Refocuses search input on backspace (#840) Fixes #775. Note that this behavior gets overridden if backspace is set as a shortcut action. * Change hotkey triggering condition to account for IME usage (#837) _isKeyCharacterInput only worked when not using an IME, as inside of an IME when a keydown event is fired, the key is reported as "Process", which does not have a key.length equal to 1. This resulted in hotkeys being triggered while typing, which this commit fixes. --------- Co-authored-by: James Maa <jmaa@berkeley.edu> Co-authored-by: Kuuuube <61125188+Kuuuube@users.noreply.github.com> Co-authored-by: Andrew Thomas Sartor <andrew@sartor.net>
Diffstat (limited to 'types')
-rw-r--r--types/ext/language-descriptors.d.ts145
-rw-r--r--types/ext/language.d.ts26
-rw-r--r--types/ext/translation-internal.d.ts12
3 files changed, 124 insertions, 59 deletions
diff --git a/types/ext/language-descriptors.d.ts b/types/ext/language-descriptors.d.ts
index 6674b28c..37da106c 100644
--- a/types/ext/language-descriptors.d.ts
+++ b/types/ext/language-descriptors.d.ts
@@ -15,13 +15,17 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type {TextPreprocessor, BidirectionalConversionPreprocessor} from './language';
+import type {TextProcessor, BidirectionalConversionPreprocessor} from './language';
import type {LanguageTransformDescriptor} from './language-transformer';
import type {SafeAny} from './core';
export type IsTextLookupWorthyFunction = (text: string) => boolean;
-type LanguageDescriptor<TIso extends string, TTextPreprocessorDescriptor extends TextPreprocessorDescriptor> = {
+type LanguageDescriptor<
+ TIso extends string,
+ TTextPreprocessorDescriptor extends TextProcessorDescriptor = Record<string, never>,
+ TTextPostprocessorDescriptor extends TextProcessorDescriptor = Record<string, never>,
+> = {
iso: TIso;
name: string;
exampleText: string;
@@ -32,75 +36,126 @@ type LanguageDescriptor<TIso extends string, TTextPreprocessorDescriptor extends
* If no value is provided, `true` is assumed for all inputs.
*/
isTextLookupWorthy?: IsTextLookupWorthyFunction;
- textPreprocessors: TTextPreprocessorDescriptor;
+ textPreprocessors?: TTextPreprocessorDescriptor;
+ textPostprocessors?: TTextPostprocessorDescriptor;
languageTransforms?: LanguageTransformDescriptor;
};
-type TextPreprocessorDescriptor = {
- [key: string]: TextPreprocessor<SafeAny>;
+type TextProcessorDescriptor = {
+ [key: string]: TextProcessor<SafeAny>;
};
type LanguageDescriptorObjectMap = {
- [key in keyof AllTextPreprocessors]: LanguageDescriptor<key, AllTextPreprocessors[key]>;
+ [key in keyof AllTextProcessors]: LanguageDescriptor<
+ key,
+ AllTextProcessors[key] extends {pre: TextProcessorDescriptor} ? AllTextProcessors[key]['pre'] : Record<string, never>,
+ AllTextProcessors[key] extends {post: TextProcessorDescriptor} ? AllTextProcessors[key]['post'] : Record<string, never>
+ >;
};
export type LanguageDescriptorAny = LanguageDescriptorObjectMap[keyof LanguageDescriptorObjectMap];
type CapitalizationPreprocessors = {
- capitalizeFirstLetter: TextPreprocessor<boolean>;
- decapitalize: TextPreprocessor<boolean>;
+ capitalizeFirstLetter: TextProcessor<boolean>;
+ decapitalize: TextProcessor<boolean>;
};
/**
- * This is a mapping of the iso tag to all of the preprocessors for that language.
+ * This is a mapping of the iso tag to all of the text processors for that language.
* Any new language should be added to this object.
*/
-type AllTextPreprocessors = {
+type AllTextProcessors = {
ar: {
- removeArabicScriptDiacritics: TextPreprocessor<boolean>;
+ pre: {
+ removeArabicScriptDiacritics: TextProcessor<boolean>;
+ };
};
- de: CapitalizationPreprocessors & {
- eszettPreprocessor: BidirectionalConversionPreprocessor;
+ de: {
+ pre: CapitalizationPreprocessors & {
+ eszettPreprocessor: BidirectionalConversionPreprocessor;
+ };
+ };
+ el: {
+ pre: CapitalizationPreprocessors;
+ };
+ en: {
+ pre: CapitalizationPreprocessors;
+ };
+ es: {
+ pre: CapitalizationPreprocessors;
};
- el: CapitalizationPreprocessors;
- en: CapitalizationPreprocessors;
- es: CapitalizationPreprocessors;
fa: {
- removeArabicScriptDiacritics: TextPreprocessor<boolean>;
+ pre: {
+ removeArabicScriptDiacritics: TextProcessor<boolean>;
+ };
+ };
+ fr: {
+ pre: CapitalizationPreprocessors;
+ };
+ grc: {
+ pre: CapitalizationPreprocessors & {
+ removeAlphabeticDiacritics: TextProcessor<boolean>;
+ };
};
- fr: CapitalizationPreprocessors;
- grc: CapitalizationPreprocessors & {
- removeAlphabeticDiacritics: TextPreprocessor<boolean>;
+ hu: {
+ pre: CapitalizationPreprocessors;
};
- hu: CapitalizationPreprocessors;
- id: CapitalizationPreprocessors;
- it: CapitalizationPreprocessors;
- la: CapitalizationPreprocessors & {
- removeAlphabeticDiacritics: TextPreprocessor<boolean>;
+ id: {
+ pre: CapitalizationPreprocessors;
+ };
+ it: {
+ pre: CapitalizationPreprocessors;
+ };
+ la: {
+ pre: CapitalizationPreprocessors & {
+ removeAlphabeticDiacritics: TextProcessor<boolean>;
+ };
};
ja: {
- convertHalfWidthCharacters: TextPreprocessor<boolean>;
- convertNumericCharacters: TextPreprocessor<boolean>;
- convertAlphabeticCharacters: TextPreprocessor<boolean>;
- convertHiraganaToKatakana: BidirectionalConversionPreprocessor;
- collapseEmphaticSequences: TextPreprocessor<[collapseEmphatic: boolean, collapseEmphaticFull: boolean]>;
+ pre: {
+ convertHalfWidthCharacters: TextProcessor<boolean>;
+ convertNumericCharacters: TextProcessor<boolean>;
+ convertAlphabeticCharacters: TextProcessor<boolean>;
+ convertHiraganaToKatakana: BidirectionalConversionPreprocessor;
+ collapseEmphaticSequences: TextProcessor<[collapseEmphatic: boolean, collapseEmphaticFull: boolean]>;
+ };
};
km: Record<string, never>;
- pl: CapitalizationPreprocessors;
- pt: CapitalizationPreprocessors;
- ro: CapitalizationPreprocessors;
- ru: CapitalizationPreprocessors & {
- yoToE: TextPreprocessor<boolean>;
- removeRussianDiacritics: TextPreprocessor<boolean>;
- };
- sga: CapitalizationPreprocessors & {
- removeAlphabeticDiacritics: TextPreprocessor<boolean>;
- };
- sh: CapitalizationPreprocessors;
- sq: CapitalizationPreprocessors;
- sv: CapitalizationPreprocessors;
+ pl: {
+ pre: CapitalizationPreprocessors;
+ };
+ pt: {
+ pre: CapitalizationPreprocessors;
+ };
+ ro: {
+ pre: CapitalizationPreprocessors;
+ };
+ ru: {
+ pre: CapitalizationPreprocessors & {
+ yoToE: TextProcessor<boolean>;
+ removeRussianDiacritics: TextProcessor<boolean>;
+ };
+ };
+ sga: {
+ pre: CapitalizationPreprocessors & {
+ removeAlphabeticDiacritics: TextProcessor<boolean>;
+ };
+ };
+ sh: {
+ pre: CapitalizationPreprocessors;
+ };
+ sq: {
+ pre: CapitalizationPreprocessors;
+ };
+ sv: {
+ pre: CapitalizationPreprocessors;
+ };
th: Record<string, never>;
- tr: CapitalizationPreprocessors;
- vi: CapitalizationPreprocessors;
+ tr: {
+ pre: CapitalizationPreprocessors;
+ };
+ vi: {
+ pre: CapitalizationPreprocessors;
+ };
zh: Record<string, never>;
};
diff --git a/types/ext/language.d.ts b/types/ext/language.d.ts
index 8fa6f0e7..c708f6e7 100644
--- a/types/ext/language.d.ts
+++ b/types/ext/language.d.ts
@@ -15,32 +15,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-import type {TextSourceMap} from '../../ext/js/general/text-source-map.js';
import type {LanguageTransformDescriptor} from './language-transformer.js';
-export type TextPreprocessorOptions<T = unknown> = T[];
+export type TextProcessorOptions<T = unknown> = T[];
-export type TextPreprocessorFunction<T = unknown> = (str: string, setting: T, sourceMap: TextSourceMap) => string;
+export type TextProcessorFunction<T = unknown> = (str: string, setting: T) => string;
/**
- * Text preprocessors are used during the translation process to create alternate versions of the input text to search for.
+ * 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 preprocessors, the translator will generate variants of the text by applying all combinations of the preprocessors.
+ * When a language has multiple processors, the translator will generate variants of the text by applying all combinations of the processors.
*/
-export type TextPreprocessor<T = unknown> = {
+export type TextProcessor<T = unknown> = {
name: string;
description: string;
- options: TextPreprocessorOptions<T>;
- process: TextPreprocessorFunction<T>;
+ options: TextProcessorOptions<T>;
+ process: TextProcessorFunction<T>;
};
export type BidirectionalPreprocessorOptions = 'off' | 'direct' | 'inverse';
-export type BidirectionalConversionPreprocessor = TextPreprocessor<BidirectionalPreprocessorOptions>;
+export type BidirectionalConversionPreprocessor = TextProcessor<BidirectionalPreprocessorOptions>;
-export type LanguageAndPreprocessors = {
+export type LanguageAndProcessors = {
iso: string;
- textPreprocessors: TextPreprocessorWithId<unknown>[];
+ textPreprocessors?: TextProcessorWithId<unknown>[];
+ textPostprocessors?: TextProcessorWithId<unknown>[];
};
export type LanguageAndTransforms = {
@@ -48,9 +48,9 @@ export type LanguageAndTransforms = {
languageTransforms: LanguageTransformDescriptor;
};
-export type TextPreprocessorWithId<T = unknown> = {
+export type TextProcessorWithId<T = unknown> = {
id: string;
- textPreprocessor: TextPreprocessor<T>;
+ textProcessor: TextProcessor<T>;
};
export type LanguageSummary = {
diff --git a/types/ext/translation-internal.d.ts b/types/ext/translation-internal.d.ts
index 7006221e..00056562 100644
--- a/types/ext/translation-internal.d.ts
+++ b/types/ext/translation-internal.d.ts
@@ -49,4 +49,14 @@ export type DatabaseDeinflection = {
databaseEntries: DictionaryDatabase.TermEntry[];
};
-export type PreprocessorOptionsSpace = Map<string, Language.TextPreprocessorOptions<unknown>>;
+export type TextProcessorOptionsSpace = Map<string, Language.TextProcessorOptions<unknown>>;
+
+export type TextProcessorMap = Map<
+ string,
+ {
+ textPreprocessors: Language.TextProcessorWithId<unknown>[];
+ preprocessorOptionsSpace: TextProcessorOptionsSpace;
+ textPostprocessors: Language.TextProcessorWithId<unknown>[];
+ postprocessorOptionsSpace: TextProcessorOptionsSpace;
+ }
+>;