Skip to content

Commit

Permalink
add preprocessor for ae and oe diphthongs
Browse files Browse the repository at this point in the history
* [la] add latin ae diphtong preprocessor

* lint

* add oe diphtong

* lint

<rikaitan.link>YmM2MmI4YjVjZTNkYTBlYzg1OGEwYjUzY2U5ZGRjZGU4NjdhOTVjNQo=</rikaitan.link>
  • Loading branch information
jason-ojisan committed Jan 9, 2025
1 parent 963fa1f commit 50a9bbb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
39 changes: 39 additions & 0 deletions ext/js/language/la/latin-text-preprocessors.js
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

/** @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, 'Œ');
}
},
};
2 changes: 2 additions & 0 deletions ext/js/language/language-descriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -206,6 +207,7 @@ const languageDescriptors = [
textPreprocessors: {
...capitalizationPreprocessors,
removeAlphabeticDiacritics,
processDiphtongs,
},
languageTransforms: latinTransforms,
},
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 @@ -129,7 +129,9 @@ type AllTextProcessors = {
pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor;
};
la: {
pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor;
pre: CapitalizationPreprocessors & AlphabeticDiacriticsProcessor & {
processDiphtongs: BidirectionalConversionPreprocessor;
};
};
lo: Record<string, never>;
lv: {
Expand Down

0 comments on commit 50a9bbb

Please sign in to comment.