From 50a9bbbbc8567b5244973f7b571cc01e2dfb2e6b Mon Sep 17 00:00:00 2001 From: Jason Ojisan Date: Thu, 9 Jan 2025 14:01:21 +0100 Subject: [PATCH] add preprocessor for ae and oe diphthongs * [la] add latin ae diphtong preprocessor * lint * add oe diphtong * lint YmM2MmI4YjVjZTNkYTBlYzg1OGEwYjUzY2U5ZGRjZGU4NjdhOTVjNQo= --- .../language/la/latin-text-preprocessors.js | 39 +++++++++++++++++++ ext/js/language/language-descriptors.js | 2 + types/ext/language-descriptors.d.ts | 4 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 ext/js/language/la/latin-text-preprocessors.js diff --git a/ext/js/language/la/latin-text-preprocessors.js b/ext/js/language/la/latin-text-preprocessors.js new file mode 100644 index 0000000000..36586f5a64 --- /dev/null +++ b/ext/js/language/la/latin-text-preprocessors.js @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 Ajatt-Tools and contributors + * + * 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 . + */ + +/** @type {import('language').BidirectionalConversionPreprocessor} */ +export const processDiphtongs = { + name: 'Convert æ to ae', + description: 'æ → ae, Æ → AE, œ → oe, Œ → OE', + options: ['off', 'direct', 'inverse'], + process: (str, setting) => { + switch (setting) { + case 'off': + return str; + case 'direct': + return str.replace(/æ/g, 'ae') + .replace(/Æ/g, 'AE') + .replace(/œ/g, 'oe') + .replace(/Œ/g, 'OE'); + case 'inverse': + return str.replace(/ae/g, 'æ') + .replace(/AE/g, 'Æ') + .replace(/oe/g, 'œ') + .replace(/OE/g, 'Œ'); + } + }, +}; diff --git a/ext/js/language/language-descriptors.js b/ext/js/language/language-descriptors.js index 1fd967e1dd..bdb9e2eb52 100644 --- a/ext/js/language/language-descriptors.js +++ b/ext/js/language/language-descriptors.js @@ -37,6 +37,7 @@ import {japaneseTransforms} from './ja/japanese-transforms.js'; import {isStringPartiallyJapanese} from './ja/japanese.js'; import {disassembleHangul, reassembleHangul} from './ko/korean-text-processors.js'; import {koreanTransforms} from './ko/korean-transforms.js'; +import {processDiphtongs} from './la/latin-text-preprocessors.js'; import {latinTransforms} from './la/latin-transforms.js'; import {removeRussianDiacritics, yoToE} from './ru/russian-text-preprocessors.js'; import {oldIrishTransforms} from './sga/old-irish-transforms.js'; @@ -206,6 +207,7 @@ const languageDescriptors = [ textPreprocessors: { ...capitalizationPreprocessors, removeAlphabeticDiacritics, + processDiphtongs, }, languageTransforms: latinTransforms, }, diff --git a/types/ext/language-descriptors.d.ts b/types/ext/language-descriptors.d.ts index 50c97d96ec..e1229a711c 100644 --- a/types/ext/language-descriptors.d.ts +++ b/types/ext/language-descriptors.d.ts @@ -129,7 +129,9 @@ type AllTextProcessors = { pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor; }; la: { - pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor; + pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor & { + processDiphtongs: BidirectionalConversionPreprocessor; + }; }; lo: Record; lv: {