Skip to content

Commit

Permalink
add apostrophe preprocessor
Browse files Browse the repository at this point in the history
<rikaitan.link>MDk1ZDY5NmQwYzRmMzIxMDYyZGM4Y2I5NTExOWRmNmY0ZDUwNGMwMAo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Dec 3, 2024
1 parent 617707a commit f27a7de
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
34 changes: 34 additions & 0 deletions ext/js/language/fr/french-text-preprocessors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/


/** @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, '\'');
}
},
};
6 changes: 5 additions & 1 deletion ext/js/language/language-descriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -138,7 +139,10 @@ const languageDescriptors = [
iso639_3: 'fra',
name: 'French',
exampleText: 'lire',
textPreprocessors: capitalizationPreprocessors,
textPreprocessors: {
...capitalizationPreprocessors,
apostropheVariants,
},
},
{
iso: 'grc',
Expand Down
4 changes: 3 additions & 1 deletion types/ext/language-descriptors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ type AllTextProcessors = {
pre: CapitalizationPreprocessors;
};
fr: {
pre: CapitalizationPreprocessors;
pre: CapitalizationPreprocessors & {
apostropheVariants: BidirectionalConversionPreprocessor;
};
};
grc: {
pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor;
Expand Down

0 comments on commit f27a7de

Please sign in to comment.