From 095d696d0c4f321062dc8cb95119df6f4d504c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Vukovi=C4=87?= Date: Sun, 1 Dec 2024 18:06:27 +0100 Subject: [PATCH] [FR] add apostrophe preprocessor (#1635) --- .eslintrc.json | 1 + .../language/fr/french-text-preprocessors.js | 34 +++++++++++++++++++ ext/js/language/language-descriptors.js | 6 +++- types/ext/language-descriptors.d.ts | 4 ++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 ext/js/language/fr/french-text-preprocessors.js diff --git a/.eslintrc.json b/.eslintrc.json index 1eb1278c1..60c0415e3 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -638,6 +638,7 @@ "ext/js/language/de/german-transforms.js", "ext/js/language/en/english-transforms.js", "ext/js/language/es/spanish-transforms.js", + "ext/js/language/fr/french-text-preprocessors.js", "ext/js/language/ja/japanese-text-preprocessors.js", "ext/js/language/ja/japanese-transforms.js", "ext/js/language/ja/japanese-wanakana.js", diff --git a/ext/js/language/fr/french-text-preprocessors.js b/ext/js/language/fr/french-text-preprocessors.js new file mode 100644 index 000000000..ffc0ca761 --- /dev/null +++ b/ext/js/language/fr/french-text-preprocessors.js @@ -0,0 +1,34 @@ +/* + * 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 . + */ + + +/** @type {import('language').BidirectionalConversionPreprocessor} */ +export const apostropheVariants = { + name: 'Search for apostrophe variants', + description: '\' → ’ and vice versa', + options: ['off', 'direct', 'inverse'], + process: (str, setting) => { + switch (setting) { + case 'off': + return str; + case 'direct': + return str.replace(/'/g, '’'); + case 'inverse': + return str.replace(/’/g, '\''); + } + }, +}; diff --git a/ext/js/language/language-descriptors.js b/ext/js/language/language-descriptors.js index 15db9a58e..81799d08d 100644 --- a/ext/js/language/language-descriptors.js +++ b/ext/js/language/language-descriptors.js @@ -21,6 +21,7 @@ import {eszettPreprocessor} from './de/german-text-preprocessors.js'; import {germanTransforms} from './de/german-transforms.js'; import {englishTransforms} from './en/english-transforms.js'; import {spanishTransforms} from './es/spanish-transforms.js'; +import {apostropheVariants} from './fr/french-text-preprocessors.js'; import { alphabeticToHiragana, alphanumericWidthVariants, @@ -138,7 +139,10 @@ const languageDescriptors = [ iso639_3: 'fra', name: 'French', exampleText: 'lire', - textPreprocessors: capitalizationPreprocessors, + textPreprocessors: { + ...capitalizationPreprocessors, + apostropheVariants, + }, }, { iso: 'grc', diff --git a/types/ext/language-descriptors.d.ts b/types/ext/language-descriptors.d.ts index f07ddcc18..f48e1e6d5 100644 --- a/types/ext/language-descriptors.d.ts +++ b/types/ext/language-descriptors.d.ts @@ -108,7 +108,9 @@ type AllTextProcessors = { pre: CapitalizationPreprocessors; }; fr: { - pre: CapitalizationPreprocessors; + pre: CapitalizationPreprocessors & { + apostropheVariants: BidirectionalConversionPreprocessor; + }; }; grc: { pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor;