From 2e9ea19207a7410f929bb908759d48cb2340f29c Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sun, 25 Feb 2024 11:20:44 -0500 Subject: "isJapanese" check move (#730) * Move isStringPartiallyJapanese out of ClipboardMonitor * Create isStringPartiallyJapanese function * Add textMayBeTranslatable * Rename API function * Rename internal function * Add helper * Update translatable check * Pass language to TextScanner * Pass language explicitly * Use textMayBeTranslatable * No redundant translatable check * Update eslint * Remove double newline * Collapse * Rename --- types/ext/api.d.ts | 3 ++- types/ext/application.d.ts | 2 +- types/ext/display.d.ts | 1 + types/ext/language-descriptors.d.ts | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) (limited to 'types') diff --git a/types/ext/api.d.ts b/types/ext/api.d.ts index 16321722..9a922fb0 100644 --- a/types/ext/api.d.ts +++ b/types/ext/api.d.ts @@ -344,9 +344,10 @@ type ApiSurface = { params: void; return: true; }; - textHasJapaneseCharacters: { + isTextLookupWorthy: { params: { text: string; + language: string; }; return: boolean; }; diff --git a/types/ext/application.d.ts b/types/ext/application.d.ts index 96f76714..8d80894d 100644 --- a/types/ext/application.d.ts +++ b/types/ext/application.d.ts @@ -41,7 +41,7 @@ export type ApiSurface = { searchDisplayControllerUpdateSearchQuery: { params: { text: string; - animate?: boolean; + animate: boolean; }; return: void; }; diff --git a/types/ext/display.d.ts b/types/ext/display.d.ts index 61e1aac5..7f4d8966 100644 --- a/types/ext/display.d.ts +++ b/types/ext/display.d.ts @@ -129,6 +129,7 @@ export type QueryParserOptions = { readingMode: Settings.ParsingReadingMode; useInternalParser: boolean; useMecabParser: boolean; + language: string; scanning: TextScannerTypes.Options; }; diff --git a/types/ext/language-descriptors.d.ts b/types/ext/language-descriptors.d.ts index 319a3ca5..ca457721 100644 --- a/types/ext/language-descriptors.d.ts +++ b/types/ext/language-descriptors.d.ts @@ -18,10 +18,19 @@ import type {TextPreprocessor, BidirectionalConversionPreprocessor} from './language'; import type {SafeAny} from './core'; +export type IsTextLookupWorthyFunction = (text: string) => boolean; + type LanguageDescriptor = { iso: TIso; name: string; exampleText: string; + /** + * An optional function which returns whether or not a given string may be translatable. + * This is used as a filter for several situations, such as whether the clipboard monitor + * window should activate when text is copied to the clipboard. + * If no value is provided, `true` is assumed for all inputs. + */ + isTextLookupWorthy?: IsTextLookupWorthyFunction; textPreprocessors: TTextPreprocessorDescriptor; }; -- cgit v1.2.3