diff --git a/ext/data/schemas/options-schema.json b/ext/data/schemas/options-schema.json index 4c97764c38..dedf600b10 100644 --- a/ext/data/schemas/options-schema.json +++ b/ext/data/schemas/options-schema.json @@ -790,9 +790,9 @@ }, "additionalProperties": { "type": "object", - "required": ["textTransformations"], + "required": ["textPreprocessors"], "properties": { - "textTransformations": { + "textPreprocessors": { "type": "object", "propertyNames": { "type": "string" @@ -806,7 +806,7 @@ }, "default": { "ja": { - "textTransformations": { + "textPreprocessors": { "convertHalfWidthCharacters": "false", "convertNumericCharacters": "false", "convertAlphabeticCharacters": "false", diff --git a/ext/js/background/backend.js b/ext/js/background/backend.js index 588e360602..4bc9956b80 100644 --- a/ext/js/background/backend.js +++ b/ext/js/background/backend.js @@ -34,7 +34,7 @@ import {DictionaryDatabase} from '../dictionary/dictionary-database.js'; import {Environment} from '../extension/environment.js'; import {ObjectPropertyAccessor} from '../general/object-property-accessor.js'; import {distributeFuriganaInflected, isCodePointJapanese, isStringPartiallyJapanese, convertKatakanaToHiragana as jpConvertKatakanaToHiragana} from '../language/ja/japanese.js'; -import {getLanguages, getTextTransformations} from '../language/language-util.js'; +import {getLanguages, getTextPreprocessors} from '../language/language-util.js'; import {Translator} from '../language/translator.js'; import {AudioDownloader} from '../media/audio-downloader.js'; import {getFileExtensionFromAudioMediaType, getFileExtensionFromImageMediaType} from '../media/media-util.js'; @@ -186,7 +186,7 @@ export class Backend { ['findAnkiNotes', this._onApiFindAnkiNotes.bind(this)], ['openCrossFramePort', this._onApiOpenCrossFramePort.bind(this)], ['getLanguages', this._onApiGetLanguages.bind(this)], - ['getTextTransformations', this._onApiGetTextTransformations.bind(this)] + ['getTextPreprocessors', this._onApiGetTextPreprocessors.bind(this)] ]); /* eslint-enable no-multi-spaces */ @@ -915,9 +915,9 @@ export class Backend { return getLanguages(); } - /** @type {import('api').ApiHandler<'getTextTransformations'>} */ - _onApiGetTextTransformations({language}) { - return getTextTransformations(language); + /** @type {import('api').ApiHandler<'getTextPreprocessors'>} */ + _onApiGetTextPreprocessors({language}) { + return getTextPreprocessors(language); } // Command handlers @@ -2384,7 +2384,7 @@ export class Backend { searchResolution } } = options; - const textTransformationsOptions = options.languages[language].textTransformations || {}; + const textPreprocessorsOptions = options.languages[language].textPreprocessors || {}; const textReplacements = this._getTranslatorTextReplacements(textReplacementsOptions); let excludeDictionaryDefinitions = null; if (mode === 'merge' && !enabledDictionaryMap.has(mainDictionary)) { @@ -2410,7 +2410,7 @@ export class Backend { enabledDictionaryMap, excludeDictionaryDefinitions, language, - textTransformationsOptions + textPreprocessorsOptions }; } diff --git a/ext/js/comm/api.js b/ext/js/comm/api.js index 369bbc3d87..5a962c7a61 100644 --- a/ext/js/comm/api.js +++ b/ext/js/comm/api.js @@ -369,11 +369,11 @@ export class API { } /** - * @param {import('api').ApiParam<'getTextTransformations', 'language'>} language - * @returns {Promise>} + * @param {import('api').ApiParam<'getTextPreprocessors', 'language'>} language + * @returns {Promise>} */ - getTextTransformations(language) { - return this._invoke('getTextTransformations', {language}); + getTextPreprocessors(language) { + return this._invoke('getTextPreprocessors', {language}); } // Utilities diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js index 5a45ba3215..8ffc1145cc 100644 --- a/ext/js/data/options-util.js +++ b/ext/js/data/options-util.js @@ -1135,11 +1135,11 @@ export class OptionsUtil { /** * - Added general.language. - * - Modularized text transformations. + * - Modularized text preprocessors. * @type {import('options-util').UpdateFunction} */ _updateVersion25(options) { - const textTransformations = [ + const textPreprocessors = [ 'convertHalfWidthCharacters', 'convertNumericCharacters', 'convertAlphabeticCharacters', @@ -1153,13 +1153,13 @@ export class OptionsUtil { profileOptions.languages = { ja: { - textTransformations: {} + textPreprocessors: {} } }; - for (const transformation of textTransformations) { - profileOptions.languages.ja.textTransformations[transformation] = profileOptions.translation[transformation]; - delete profileOptions.translation[transformation]; + for (const preprocessor of textPreprocessors) { + profileOptions.languages.ja.textPreprocessors[preprocessor] = profileOptions.translation[preprocessor]; + delete profileOptions.translation[preprocessor]; } } } diff --git a/ext/js/language/en/text-transformations.js b/ext/js/language/en/text-preprocessors.js similarity index 86% rename from ext/js/language/en/text-transformations.js rename to ext/js/language/en/text-preprocessors.js index cb35c01368..1de0801a7b 100755 --- a/ext/js/language/en/text-transformations.js +++ b/ext/js/language/en/text-preprocessors.js @@ -15,9 +15,9 @@ * along with this program. If not, see . */ -import {capitalizeFirstLetter, decapitalize} from '../text-transformations.js'; +import {capitalizeFirstLetter, decapitalize} from '../text-preprocessors.js'; -export const textTransformations = [ +export const textPreprocessors = [ decapitalize, capitalizeFirstLetter ]; \ No newline at end of file diff --git a/ext/js/language/ja/text-transformations.js b/ext/js/language/ja/text-preprocessors.js similarity index 86% rename from ext/js/language/ja/text-transformations.js rename to ext/js/language/ja/text-preprocessors.js index efa62bdf71..9bdd7a988b 100755 --- a/ext/js/language/ja/text-transformations.js +++ b/ext/js/language/ja/text-preprocessors.js @@ -15,11 +15,11 @@ * along with this program. If not, see . */ -import {basicTextTransformationOptions} from '../text-transformations.js'; +import {basicTextPreprocessorOptions} from '../text-preprocessors.js'; import {convertAlphabeticToKana} from './japanese-wanakana.js'; import {collapseEmphaticSequences, convertHalfWidthKanaToFullWidth, convertHiraganaToKatakana, convertKatakanaToHiragana, convertNumericToFullWidth} from './japanese.js'; -/** @type {import('language').TextTransformation}*/ +/** @type {import('language').TextPreprocessor}*/ const collapseEmphaticSequencesTransform = { id: 'collapseEmphaticSequences', name: 'Collapse emphatic character sequences', @@ -38,41 +38,41 @@ const collapseEmphaticSequencesTransform = { } }; -/** @type {import('language').TextTransformation[]} */ -export const textTransformations = [ +/** @type {import('language').TextPreprocessor[]} */ +export const textPreprocessors = [ { id: 'convertHalfWidthCharacters', name: 'Convert half width characters to full width', description: 'ヨミチャン → ヨミチャン', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting, sourceMap) => setting ? convertHalfWidthKanaToFullWidth(str, sourceMap) : str }, { id: 'convertNumericCharacters', name: 'Convert numeric characters to full width', description: '1234 → 1234', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting) => setting ? convertNumericToFullWidth(str) : str }, { id: 'convertAlphabeticCharacters', name: 'Convert alphabetic characters to hiragana', description: 'yomichan → よみちゃん', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting, sourceMap) => setting ? convertAlphabeticToKana(str, sourceMap) : str }, { id: 'convertHiraganaToKatakana', name: 'Convert hiragana to katakana', description: 'よみちゃん → ヨミチャン', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting) => setting ? convertHiraganaToKatakana(str) : str }, { id: 'convertKatakanaToHiragana', name: 'Convert katakana to hiragana', description: 'ヨミチャン → よみちゃん', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting) => setting ? convertKatakanaToHiragana(str) : str }, collapseEmphaticSequencesTransform diff --git a/ext/js/language/language-util.js b/ext/js/language/language-util.js index 511ff949bd..d1bd66a694 100644 --- a/ext/js/language/language-util.js +++ b/ext/js/language/language-util.js @@ -24,10 +24,10 @@ export function getLanguages() { /** * @param {string} iso - * @returns {import('language').TextTransformation[]} + * @returns {import('language').TextPreprocessor[]} */ -export function getTextTransformations(iso) { - return languages.get(iso)?.textTransformations || []; +export function getTextPreprocessors(iso) { + return languages.get(iso)?.textPreprocessors || []; } diff --git a/ext/js/language/languages.js b/ext/js/language/languages.js index 397ecbeed7..999d7766ce 100755 --- a/ext/js/language/languages.js +++ b/ext/js/language/languages.js @@ -15,8 +15,8 @@ * along with this program. If not, see . */ -import {textTransformations as textTransformationsEN} from './en/text-transformations.js'; -import {textTransformations as textTransformationsJA} from './ja/text-transformations.js'; +import {textPreprocessors as textPreprocessorsEN} from './en/text-preprocessors.js'; +import {textPreprocessors as textPreprocessorsJA} from './ja/text-preprocessors.js'; /** @type {Map} */ export const languages = new Map([ @@ -25,14 +25,14 @@ export const languages = new Map([ iso: 'ja', flag: '🇯🇵', exampleText: '読め', - textTransformations: textTransformationsJA + textPreprocessors: textPreprocessorsJA }], ['en', { name: 'English', iso: 'en', flag: '🇬🇧', exampleText: 'read', - textTransformations: textTransformationsEN + textPreprocessors: textPreprocessorsEN }] ]); diff --git a/ext/js/language/text-transformations.js b/ext/js/language/text-preprocessors.js similarity index 80% rename from ext/js/language/text-transformations.js rename to ext/js/language/text-preprocessors.js index ed7778f156..daf43abdc2 100755 --- a/ext/js/language/text-transformations.js +++ b/ext/js/language/text-preprocessors.js @@ -15,28 +15,28 @@ * along with this program. If not, see . */ -/** @type {import('language').TextTransformationOption[]} */ -export const basicTextTransformationOptions = [ +/** @type {import('language').TextPreprocessorOption[]} */ +export const basicTextPreprocessorOptions = [ ['false', 'Disabled', [false]], ['true', 'Enabled', [true]], ['variant', 'Use both variants', [false, true]] ]; -/** @type {import('language').TextTransformation} */ +/** @type {import('language').TextPreprocessor} */ export const decapitalize = { id: 'decapitalize', name: 'Decapitalize text', description: 'CAPITALIZED TEXT → capitalized text', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting) => setting ? str.toLowerCase() : str }; -/** @type {import('language').TextTransformation} */ +/** @type {import('language').TextPreprocessor} */ export const capitalizeFirstLetter = { id: 'capitalizeFirstLetter', name: 'Capitalize first letter', description: 'lowercase text → Lowercase text', - options: basicTextTransformationOptions, + options: basicTextPreprocessorOptions, transform: (str, setting) => setting ? str.charAt(0).toUpperCase() + str.slice(1) : str }; diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js index 63e6b3d3ee..b965164667 100644 --- a/ext/js/language/translator.js +++ b/ext/js/language/translator.js @@ -20,7 +20,7 @@ import {applyTextReplacement} from '../general/regex-util.js'; import {TextSourceMap} from '../general/text-source-map.js'; import {isCodePointJapanese} from './ja/japanese.js'; import {LanguageTransformer} from './language-transformer.js'; -import {getTextTransformations} from './language-util.js'; +import {getTextPreprocessors} from './language-util.js'; /** * Class which finds term and kanji dictionary entries for text. */ @@ -414,7 +414,7 @@ export class Translator { } } - // Deinflections and text transformations + // Deinflections and text preprocessing /** * @param {string} text @@ -422,16 +422,16 @@ export class Translator { * @returns {import('translation-internal').DatabaseDeinflection[]} */ _getAlgorithmDeinflections(text, options) { - const textTransformations = this._getTextTransformations(options); + const textPreprocessors = this._getTextPreprocessors(options); - const textTransformationsVectorSpace = new Map(); - for (const [id, transformation] of textTransformations) { - textTransformationsVectorSpace.set(id, this._getTextTransformationVariants(transformation)); + const textPreprocessorsVectorSpace = new Map(); + for (const [id, preprocessors] of textPreprocessors) { + textPreprocessorsVectorSpace.set(id, this._getTextPreprocessorVariants(preprocessors)); } const variantVectorSpace = new Map([ ['textReplacements', this._getTextReplacementsVariants(options)], - ...textTransformationsVectorSpace + ...textPreprocessorsVectorSpace ]); /** @type {import('translation-internal').DatabaseDeinflection[]} */ @@ -448,8 +448,8 @@ export class Translator { text2 = this._applyTextReplacements(text2, sourceMap, textReplacements); } - for (const {transformation} of textTransformations.values()) { - const {id, transform} = transformation; + for (const {preprocessor} of textPreprocessors.values()) { + const {id, transform} = preprocessor; const setting = arrayVariant.get(id); text2 = transform(text2, setting, sourceMap); } @@ -492,27 +492,27 @@ export class Translator { /** * @param {import('translation').FindTermsOptions} options - * @returns {Map} + * @returns {Map} */ - _getTextTransformations(options) { - const {textTransformationsOptions, language} = options; - const textTransformationsData = getTextTransformations(language); + _getTextPreprocessors(options) { + const {textPreprocessorsOptions, language} = options; + const textPreprocessorsData = getTextPreprocessors(language); - /** @type {Map} */ - const textTransformations = new Map(); + /** @type {Map} */ + const textPreprocessors = new Map(); - for (const transformation of textTransformationsData) { - const {id} = transformation; - const value = textTransformationsOptions[id]; + for (const preprocessor of textPreprocessorsData) { + const {id} = preprocessor; + const value = textPreprocessorsOptions[id]; if (value) { - textTransformations.set(id, { - transformation, + textPreprocessors.set(id, { + preprocessor, setting: value }); } } - return textTransformations; + return textPreprocessors; } /** @@ -544,11 +544,11 @@ export class Translator { } /** - * @param {import('translation-internal').TextTransformation} transformation + * @param {import('translation-internal').TextPreprocessor} preprocessor * @returns {unknown[]} */ - _getTextTransformationVariants(transformation) { - const {setting, transformation: {options}} = transformation; + _getTextPreprocessorVariants(preprocessor) { + const {setting, preprocessor: {options}} = preprocessor; for (const [optionValue, , optionSetting] of options) { if (optionValue === setting) { return optionSetting; diff --git a/ext/js/pages/settings/languages-controller.js b/ext/js/pages/settings/languages-controller.js index d90095d831..befda65a15 100755 --- a/ext/js/pages/settings/languages-controller.js +++ b/ext/js/pages/settings/languages-controller.js @@ -63,7 +63,7 @@ export class LanguagesController { value: { ...options.languages, [language]: { - textTransformations: {} + textPreprocessors: {} } } }]); diff --git a/ext/js/pages/settings/settings-main.js b/ext/js/pages/settings/settings-main.js index 232d90e2a7..5583ee232e 100644 --- a/ext/js/pages/settings/settings-main.js +++ b/ext/js/pages/settings/settings-main.js @@ -49,7 +49,7 @@ import {SettingsDisplayController} from './settings-display-controller.js'; import {SortFrequencyDictionaryController} from './sort-frequency-dictionary-controller.js'; import {StatusFooter} from './status-footer.js'; import {StorageController} from './storage-controller.js'; -import {TextTransformationsController} from './text-transformations-controller.js'; +import {TextPreprocessorsController} from './text-preprocessors-controller.js'; import {TranslationTextReplacementsController} from './translation-text-replacements-controller.js'; /** @@ -148,8 +148,8 @@ async function main() { const languagesController = new LanguagesController(settingsController); languagesController.prepare(); - const textTransformationsController = new TextTransformationsController(settingsController); - textTransformationsController.prepare(); + const textPreprocessorsController = new TextPreprocessorsController(settingsController); + textPreprocessorsController.prepare(); const translationTextReplacementsController = new TranslationTextReplacementsController(settingsController); translationTextReplacementsController.prepare(); diff --git a/ext/js/pages/settings/text-transformations-controller.js b/ext/js/pages/settings/text-preprocessors-controller.js similarity index 67% rename from ext/js/pages/settings/text-transformations-controller.js rename to ext/js/pages/settings/text-preprocessors-controller.js index 011979f42e..6fda50625e 100755 --- a/ext/js/pages/settings/text-transformations-controller.js +++ b/ext/js/pages/settings/text-preprocessors-controller.js @@ -18,7 +18,7 @@ import {querySelectorNotNull} from '../../dom/query-selector.js'; -export class TextTransformationsController { +export class TextPreprocessorsController { /** * @param {import('./settings-controller.js').SettingsController} settingsController */ @@ -26,9 +26,9 @@ export class TextTransformationsController { /** @type {import('./settings-controller.js').SettingsController} */ this._settingsController = settingsController; /** @type {HTMLSelectElement} */ - this._container = querySelectorNotNull(document, '#text-transformations'); - /** @type {import('language').TextTransformation[]}*/ - this._transformations = []; + this._container = querySelectorNotNull(document, '#text-preprocessors'); + /** @type {import('language').TextPreprocessor[]}*/ + this._preprocessors = []; /** @type {string} */ this._language = ''; } @@ -58,39 +58,39 @@ export class TextTransformationsController { this._language = options.general.language; this._clearSettingsItems(); - this._transformations = await this._settingsController.application.api.getTextTransformations(this._language); + this._preprocessors = await this._settingsController.application.api.getTextPreprocessors(this._language); this._renderSettingsItems(); } /** */ _clearSettingsItems() { - const settingsItems = document.querySelectorAll('.text-transformation'); - for (const transformation of settingsItems) { - transformation.remove(); + const settingsItems = document.querySelectorAll('.text-preprocessor'); + for (const preprocessor of settingsItems) { + preprocessor.remove(); } } /** */ _renderSettingsItems() { - for (const transformation of this._transformations) { - const settingsItem = this._createSettingsItem(transformation); + for (const preprocessor of this._preprocessors) { + const settingsItem = this._createSettingsItem(preprocessor); this._container.appendChild(settingsItem); } } /** - * @param {import('language').TextTransformation} transformation + * @param {import('language').TextPreprocessor} preprocessor * @returns {HTMLElement} */ - _createSettingsItem(transformation) { + _createSettingsItem(preprocessor) { const settingsItem = document.createElement('div'); - settingsItem.classList.add('settings-item', 'text-transformation'); + settingsItem.classList.add('settings-item', 'text-preprocessor'); const innerWrappableDiv = document.createElement('div'); innerWrappableDiv.classList.add('settings-item-inner', 'settings-item-inner-wrappable'); - innerWrappableDiv.appendChild(this._createLeftSide(transformation)); - innerWrappableDiv.appendChild(this._createRightSide(transformation)); + innerWrappableDiv.appendChild(this._createLeftSide(preprocessor)); + innerWrappableDiv.appendChild(this._createRightSide(preprocessor)); settingsItem.appendChild(innerWrappableDiv); @@ -98,63 +98,63 @@ export class TextTransformationsController { } /** - * @param {import('language').TextTransformation} transformation + * @param {import('language').TextPreprocessor} preprocessor * @returns {HTMLElement} */ - _createLeftSide(transformation) { + _createLeftSide(preprocessor) { const leftSide = document.createElement('div'); leftSide.classList.add('settings-item-left'); - leftSide.appendChild(this._createLabel(transformation)); - leftSide.appendChild(this._createDescription(transformation)); + leftSide.appendChild(this._createLabel(preprocessor)); + leftSide.appendChild(this._createDescription(preprocessor)); return leftSide; } /** - * @param {import('language').TextTransformation} transformation + * @param {import('language').TextPreprocessor} preprocessor * @returns {HTMLElement} */ - _createLabel(transformation) { + _createLabel(preprocessor) { const label = document.createElement('div'); label.classList.add('settings-item-label'); - label.textContent = transformation.name; + label.textContent = preprocessor.name; return label; } /** - * @param {import('language').TextTransformation} transformation + * @param {import('language').TextPreprocessor} preprocessor * @returns {HTMLElement} */ - _createDescription(transformation) { + _createDescription(preprocessor) { const description = document.createElement('div'); description.classList.add('settings-item-description'); - description.textContent = transformation.description; + description.textContent = preprocessor.description; return description; } /** - * @param {import('language').TextTransformation} transformation + * @param {import('language').TextPreprocessor} preprocessor * @returns {HTMLElement} */ - _createRightSide(transformation) { + _createRightSide(preprocessor) { const rightSide = document.createElement('div'); rightSide.classList.add('settings-item-right'); - rightSide.appendChild(this._createSelect(transformation)); + rightSide.appendChild(this._createSelect(preprocessor)); return rightSide; } /** - * @param {import('language').TextTransformation} transformation + * @param {import('language').TextPreprocessor} preprocessor * @returns {HTMLSelectElement} */ - _createSelect(transformation) { + _createSelect(preprocessor) { const select = document.createElement('select'); - select.setAttribute('data-setting', `languages.${this._language}.textTransformations.${transformation.id}`); + select.setAttribute('data-setting', `languages.${this._language}.textPreprocessors.${preprocessor.id}`); - for (const [optionValue, optionLabel] of transformation.options) { + for (const [optionValue, optionLabel] of preprocessor.options) { const optionElement = document.createElement('option'); optionElement.value = optionValue; optionElement.textContent = optionLabel; diff --git a/ext/settings.html b/ext/settings.html index 623909326f..4d2ec4f26c 100644 --- a/ext/settings.html +++ b/ext/settings.html @@ -222,7 +222,7 @@

Yomitan Settings

- @@ -1526,7 +1526,7 @@

Yomitan Settings

-
+
Dictionary search resolution
diff --git a/test/data/anki-note-builder-test-results.json b/test/data/anki-note-builder-test-results.json index 733a8029ac..3fbaada289 100644 --- a/test/data/anki-note-builder-test-results.json +++ b/test/data/anki-note-builder-test-results.json @@ -3263,7 +3263,7 @@ ] }, { - "name": "Test text transformations - convertNumericCharacters", + "name": "Test text preprocessors - convertNumericCharacters", "results": [ { "audio": "", @@ -3303,7 +3303,7 @@ ] }, { - "name": "Test text transformations - convertAlphabeticCharacters", + "name": "Test text preprocessors - convertAlphabeticCharacters", "results": [ { "audio": "", @@ -3378,7 +3378,7 @@ ] }, { - "name": "Test text transformations - convertKatakanaToHiragana", + "name": "Test text preprocessors - convertKatakanaToHiragana", "results": [ { "audio": "", @@ -3453,7 +3453,7 @@ ] }, { - "name": "Test text transformations - convertHiraganaToKatakana", + "name": "Test text preprocessors - convertHiraganaToKatakana", "results": [ { "audio": "", @@ -3493,7 +3493,7 @@ ] }, { - "name": "Test text transformations - convertHalfWidthCharacters, convertKatakanaToHiragana", + "name": "Test text preprocessors - convertHalfWidthCharacters, convertKatakanaToHiragana", "results": [ { "audio": "", @@ -3568,7 +3568,7 @@ ] }, { - "name": "Test text transformations - collapseEmphaticSequences", + "name": "Test text preprocessors - collapseEmphaticSequences", "results": [ { "audio": "", @@ -3608,7 +3608,7 @@ ] }, { - "name": "Test text transformations - capitalizeFirstLetter", + "name": "Test text preprocessors - capitalizeFirstLetter", "results": [ { "audio": "", @@ -3648,7 +3648,7 @@ ] }, { - "name": "Test text transformations - decapitalize", + "name": "Test text preprocessors - decapitalize", "results": [ { "audio": "", diff --git a/test/data/translator-test-inputs.json b/test/data/translator-test-inputs.json index 9160288719..abb0ee7b83 100644 --- a/test/data/translator-test-inputs.json +++ b/test/data/translator-test-inputs.json @@ -22,7 +22,7 @@ "sortFrequencyDictionaryOrder": "descending", "removeNonJapaneseCharacters": true, "language": "ja", - "textTransformationsOptions": { + "textPreprocessorsOptions": { "convertHalfWidthCharacters": "false", "convertNumericCharacters": "false", "convertAlphabeticCharacters": "false", @@ -364,7 +364,7 @@ "options": "default" }, { - "name": "Test text transformations - convertNumericCharacters", + "name": "Test text preprocessors - convertNumericCharacters", "func": "findTerms", "mode": "split", "text": "39", @@ -372,7 +372,7 @@ "default", { "type": "terms", - "textTransformationsOptions": { + "textPreprocessorsOptions": { "convertNumericCharacters": "true" }, "removeNonJapaneseCharacters": false @@ -380,7 +380,7 @@ ] }, { - "name": "Test text transformations - convertAlphabeticCharacters", + "name": "Test text preprocessors - convertAlphabeticCharacters", "func": "findTerms", "mode": "split", "text": "utsu", @@ -389,14 +389,14 @@ { "type": "terms", "removeNonJapaneseCharacters": false, - "textTransformationsOptions": { + "textPreprocessorsOptions": { "convertAlphabeticCharacters": "true" } } ] }, { - "name": "Test text transformations - convertKatakanaToHiragana", + "name": "Test text preprocessors - convertKatakanaToHiragana", "func": "findTerms", "mode": "split", "text": "ウツ", @@ -404,14 +404,14 @@ "default", { "type": "terms", - "textTransformationsOptions": { + "textPreprocessorsOptions": { "convertKatakanaToHiragana": "true" } } ] }, { - "name": "Test text transformations - convertHiraganaToKatakana", + "name": "Test text preprocessors - convertHiraganaToKatakana", "func": "findTerms", "mode": "split", "text": "てきすと", @@ -419,14 +419,14 @@ "default", { "type": "terms", - "textTransformationsOptions": { + "textPreprocessorsOptions": { "convertHiraganaToKatakana": "true" } } ] }, { - "name": "Test text transformations - convertHalfWidthCharacters, convertKatakanaToHiragana", + "name": "Test text preprocessors - convertHalfWidthCharacters, convertKatakanaToHiragana", "func": "findTerms", "mode": "split", "text": "ウツ", @@ -434,7 +434,7 @@ "default", { "type": "terms", - "textTransformationsOptions": { + "textPreprocessorsOptions": { "convertHalfWidthCharacters": "true", "convertKatakanaToHiragana": "true" } @@ -442,7 +442,7 @@ ] }, { - "name": "Test text transformations - collapseEmphaticSequences", + "name": "Test text preprocessors - collapseEmphaticSequences", "func": "findTerms", "mode": "split", "text": "すっっごーーい", @@ -450,14 +450,14 @@ "default", { "type": "terms", - "textTransformationsOptions": { + "textPreprocessorsOptions": { "collapseEmphaticSequences": "full" } } ] }, { - "name": "Test text transformations - capitalizeFirstLetter", + "name": "Test text preprocessors - capitalizeFirstLetter", "func": "findTerms", "mode": "split", "text": "english", @@ -467,14 +467,14 @@ "type": "terms", "language": "en", "removeNonJapaneseCharacters": false, - "textTransformationsOptions": { + "textPreprocessorsOptions": { "capitalizeFirstLetter": "true" } } ] }, { - "name": "Test text transformations - decapitalize", + "name": "Test text preprocessors - decapitalize", "func": "findTerms", "mode": "split", "text": "LANGUAGE", @@ -484,7 +484,7 @@ "type": "terms", "language": "en", "removeNonJapaneseCharacters": false, - "textTransformationsOptions": { + "textPreprocessorsOptions": { "decapitalize": "true" } } diff --git a/test/data/translator-test-results-note-data1.json b/test/data/translator-test-results-note-data1.json index 0ff57d3467..639a9d96dc 100644 --- a/test/data/translator-test-results-note-data1.json +++ b/test/data/translator-test-results-note-data1.json @@ -30028,7 +30028,7 @@ ] }, { - "name": "Test text transformations - convertNumericCharacters", + "name": "Test text preprocessors - convertNumericCharacters", "noteDataList": [ { "marker": "{marker}", @@ -30129,7 +30129,7 @@ ] }, { - "name": "Test text transformations - convertAlphabeticCharacters", + "name": "Test text preprocessors - convertAlphabeticCharacters", "noteDataList": [ { "marker": "{marker}", @@ -30760,7 +30760,7 @@ ] }, { - "name": "Test text transformations - convertKatakanaToHiragana", + "name": "Test text preprocessors - convertKatakanaToHiragana", "noteDataList": [ { "marker": "{marker}", @@ -31391,7 +31391,7 @@ ] }, { - "name": "Test text transformations - convertHiraganaToKatakana", + "name": "Test text preprocessors - convertHiraganaToKatakana", "noteDataList": [ { "marker": "{marker}", @@ -31543,7 +31543,7 @@ ] }, { - "name": "Test text transformations - convertHalfWidthCharacters, convertKatakanaToHiragana", + "name": "Test text preprocessors - convertHalfWidthCharacters, convertKatakanaToHiragana", "noteDataList": [ { "marker": "{marker}", @@ -32174,7 +32174,7 @@ ] }, { - "name": "Test text transformations - collapseEmphaticSequences", + "name": "Test text preprocessors - collapseEmphaticSequences", "noteDataList": [ { "marker": "{marker}", @@ -32295,7 +32295,7 @@ ] }, { - "name": "Test text transformations - capitalizeFirstLetter", + "name": "Test text preprocessors - capitalizeFirstLetter", "noteDataList": [ { "marker": "{marker}", @@ -32408,7 +32408,7 @@ ] }, { - "name": "Test text transformations - decapitalize", + "name": "Test text preprocessors - decapitalize", "noteDataList": [ { "marker": "{marker}", diff --git a/test/data/translator-test-results.json b/test/data/translator-test-results.json index 4129ae1034..5f394c4e7c 100644 --- a/test/data/translator-test-results.json +++ b/test/data/translator-test-results.json @@ -16978,7 +16978,7 @@ ] }, { - "name": "Test text transformations - convertNumericCharacters", + "name": "Test text preprocessors - convertNumericCharacters", "originalTextLength": 2, "dictionaryEntries": [ { @@ -17043,7 +17043,7 @@ ] }, { - "name": "Test text transformations - convertAlphabeticCharacters", + "name": "Test text preprocessors - convertAlphabeticCharacters", "originalTextLength": 4, "dictionaryEntries": [ { @@ -17389,7 +17389,7 @@ ] }, { - "name": "Test text transformations - convertKatakanaToHiragana", + "name": "Test text preprocessors - convertKatakanaToHiragana", "originalTextLength": 2, "dictionaryEntries": [ { @@ -17735,7 +17735,7 @@ ] }, { - "name": "Test text transformations - convertHiraganaToKatakana", + "name": "Test text preprocessors - convertHiraganaToKatakana", "originalTextLength": 4, "dictionaryEntries": [ { @@ -17844,7 +17844,7 @@ ] }, { - "name": "Test text transformations - convertHalfWidthCharacters, convertKatakanaToHiragana", + "name": "Test text preprocessors - convertHalfWidthCharacters, convertKatakanaToHiragana", "originalTextLength": 2, "dictionaryEntries": [ { @@ -18190,7 +18190,7 @@ ] }, { - "name": "Test text transformations - collapseEmphaticSequences", + "name": "Test text preprocessors - collapseEmphaticSequences", "originalTextLength": 7, "dictionaryEntries": [ { @@ -18269,7 +18269,7 @@ ] }, { - "name": "Test text transformations - capitalizeFirstLetter", + "name": "Test text preprocessors - capitalizeFirstLetter", "originalTextLength": 7, "dictionaryEntries": [ { @@ -18350,7 +18350,7 @@ ] }, { - "name": "Test text transformations - decapitalize", + "name": "Test text preprocessors - decapitalize", "originalTextLength": 8, "dictionaryEntries": [ { diff --git a/test/options-util.test.js b/test/options-util.test.js index b2f32f9415..5dcc37546d 100644 --- a/test/options-util.test.js +++ b/test/options-util.test.js @@ -414,7 +414,7 @@ function createProfileOptionsUpdatedTestData1() { }, languages: { ja: { - textTransformations: { + textPreprocessors: { convertHalfWidthCharacters: 'false', convertNumericCharacters: 'false', convertAlphabeticCharacters: 'false', diff --git a/test/utilities/translator.js b/test/utilities/translator.js index 8773ea34ca..7211a30df5 100644 --- a/test/utilities/translator.js +++ b/test/utilities/translator.js @@ -126,7 +126,7 @@ export function createFindTermsOptions(dictionaryName, optionsPresets, optionsAr excludeDictionaryDefinitions, searchResolution, language, - textTransformationsOptions + textPreprocessorsOptions } = preset; return { @@ -140,7 +140,7 @@ export function createFindTermsOptions(dictionaryName, optionsPresets, optionsAr enabledDictionaryMap, excludeDictionaryDefinitions: Array.isArray(excludeDictionaryDefinitions) ? new Set(excludeDictionaryDefinitions) : null, searchResolution: typeof searchResolution !== 'undefined' ? searchResolution : 'letter', - textTransformationsOptions: typeof textTransformationsOptions !== 'undefined' ? textTransformationsOptions : {}, + textPreprocessorsOptions: typeof textPreprocessorsOptions !== 'undefined' ? textPreprocessorsOptions : {}, language: typeof language !== 'undefined' ? language : 'ja' }; } diff --git a/types/ext/api.d.ts b/types/ext/api.d.ts index b8c53c7681..ed2d0321a9 100644 --- a/types/ext/api.d.ts +++ b/types/ext/api.d.ts @@ -385,11 +385,11 @@ type ApiSurface = { params: void; return: Language.Language[]; }; - getTextTransformations: { + getTextPreprocessors: { params: { language: string; }; - return: Language.TextTransformation[]; + return: Language.TextPreprocessor[]; }; }; diff --git a/types/ext/language.d.ts b/types/ext/language.d.ts index 58f6e19069..79aed18d8d 100644 --- a/types/ext/language.d.ts +++ b/types/ext/language.d.ts @@ -17,17 +17,17 @@ import {TextSourceMap} from '../../ext/js/general/text-source-map.js'; -export type TextTransformationOption = [ +export type TextPreprocessorOption = [ value: string, label: string, option: T[], ]; -export type TextTransformation = { +export type TextPreprocessor = { id: string; name: string; description: string; - options: TextTransformationOption[]; + options: TextPreprocessorOption[]; transform: (str: string, setting: T, sourceMap?: TextSourceMap) => string; }; @@ -36,7 +36,7 @@ export type Language = { iso: string; flag: string; exampleText: string; - textTransformations: TextTransformation[]; + textPreprocessors: TextPreprocessor[]; }; export type LanguageMap = Map; \ No newline at end of file diff --git a/types/ext/settings.d.ts b/types/ext/settings.d.ts index 3f38d40698..623f66b1d7 100644 --- a/types/ext/settings.d.ts +++ b/types/ext/settings.d.ts @@ -343,12 +343,12 @@ export type AccessibilityOptions = { forceGoogleDocsHtmlRendering: boolean; }; -export type TextTransformationsOptions = { +export type TextPreprocessorsOptions = { [id: string]: string; }; export type LanguageOptions = { - textTransformations?: TextTransformationsOptions; + textPreprocessors?: TextPreprocessorsOptions; }; export type LanguageOptionsObjectMap = { diff --git a/types/ext/translation-internal.d.ts b/types/ext/translation-internal.d.ts index 13064b7d8b..971a44f35b 100644 --- a/types/ext/translation-internal.d.ts +++ b/types/ext/translation-internal.d.ts @@ -49,7 +49,7 @@ export type DatabaseDeinflection = { databaseEntries: DictionaryDatabase.TermEntry[]; }; -export type TextTransformation = { - transformation: Language.TextTransformation; +export type TextPreprocessor = { + preprocessor: Language.TextPreprocessor; setting: string; }; diff --git a/types/ext/translation.d.ts b/types/ext/translation.d.ts index 150fe0ee9d..94ed8c7091 100644 --- a/types/ext/translation.d.ts +++ b/types/ext/translation.d.ts @@ -17,7 +17,7 @@ */ import type * as Dictionary from './dictionary'; -import type {SearchResolution, TextTransformationsOptions} from 'settings'; +import type {SearchResolution, TextPreprocessorsOptions} from 'settings'; // Kanji @@ -100,7 +100,7 @@ export type FindTermsOptions = { /** * Which variants of the search text should be looked up. */ - textTransformationsOptions: TextTransformationsOptions; + textPreprocessorsOptions: TextPreprocessorsOptions; /** * ISO-639 code of the language. */ diff --git a/types/test/translator.d.ts b/types/test/translator.d.ts index 901218d3cc..0ba234b4c4 100644 --- a/types/test/translator.d.ts +++ b/types/test/translator.d.ts @@ -16,7 +16,7 @@ */ import type {FindTermsMatchType, FindTermsSortOrder, FindKanjiDictionary, FindTermDictionary} from '../ext/translation'; -import type {SearchResolution, TextTransformationsOptions} from '../ext/settings'; +import type {SearchResolution, TextPreprocessorsOptions} from '../ext/settings'; import type {FindTermsMode} from 'translator'; import type {DictionaryEntry} from 'dictionary'; import type {NoteData} from 'anki-templates'; @@ -49,7 +49,7 @@ export type FindTermsOptionsPreset = { excludeDictionaryDefinitions?: string[] | null; searchResolution?: SearchResolution; language?: string; - textTransformationsOptions?: TextTransformationsOptions; + textPreprocessorsOptions?: TextPreprocessorsOptions; }; export type OptionsType = OptionsPreset['type'];