From b93d7a2ec79ef808d69608c179dbd3b1493a961b Mon Sep 17 00:00:00 2001 From: Yaroslav Serhieiev Date: Sun, 14 Jan 2024 12:37:24 +0200 Subject: [PATCH] feat: comparative and superlative adjectives declension --- .../Modals/DetailModal/DetailModal.tsx | 40 +++++++++++++------ src/translations/data.json | 19 ++++++++- src/utils/wordDetails/wordDetails.ts | 10 ++++- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/components/Modals/DetailModal/DetailModal.tsx b/src/components/Modals/DetailModal/DetailModal.tsx index 2f63bfde..e062474b 100644 --- a/src/components/Modals/DetailModal/DetailModal.tsx +++ b/src/components/Modals/DetailModal/DetailModal.tsx @@ -18,9 +18,11 @@ import { getPronounType, getVerbDetails, isAnimated, + isComparative, isIndeclinable, isPlural, isSingular, + isSuperlative, } from 'utils/wordDetails'; import { LineSelector } from 'components/LineSelector'; @@ -29,7 +31,13 @@ import { Text } from 'components/Text'; import './DetailModal.scss'; -import { conjugationVerb, declensionAdjective, declensionNoun, declensionNumeral, declensionPronoun } from '@interslavic/utils'; +import { + conjugationVerb, + declensionAdjective, + declensionNoun, + declensionNumeral, + declensionPronoun +} from '@interslavic/utils'; interface IDetailModalInternal { close: () => void; @@ -96,28 +104,34 @@ class DetailModalInternal extends Component { private renderTitle(pos: string) { const { details, word, add } = this.props; const arr = [t(pos)]; - const animated = isAnimated(details); - const gender = getGender(details); - const plural = isPlural(details); - const singular = isSingular(details); - const indeclinable = isIndeclinable(details); + switch (pos) { case 'noun': { + const gender = getGender(details); + const animated = isAnimated(details); arr.push(t('noun-' + gender)); if (gender.match(/masculine/)) { arr.push(t(animated ? 'noun-animated' : 'noun-inanimate')); } - if (indeclinable) { + if (isIndeclinable(details)) { arr.push(t('noun-indeclinable')); } - if (plural) { + if (isPlural(details)) { arr.push(t('noun-plural')); } - if (singular) { + if (isSingular(details)) { arr.push(t('noun-singular')); } break; } + case 'adjective': { + if (isComparative(details)) { + arr.push(t('comparative') + ' ' + t('degree')); + } else if (isSuperlative(details)) { + arr.push(t('superlative') + ' ' + t('degree')); + } + break; + } case 'verb': { const verbDetails = getVerbDetails(details); if (verbDetails) { @@ -185,7 +199,7 @@ class DetailModalInternal extends Component { wordComponent = this.renderNounDetails(word, add, details); break; case 'adjective': - wordComponent = this.renderAdjectiveDetails(word); + wordComponent = this.renderAdjectiveDetails(word, details); break; case 'verb': wordComponent = this.renderVerbDetails(word, add); @@ -212,7 +226,7 @@ class DetailModalInternal extends Component { private formatStr(str: string): string { if (str === '') { return ''; - } else if (str === null) { + } else if (str == null) { return '—'; } else if (str.match(/&\w+;/g)) { return str; @@ -360,8 +374,8 @@ class DetailModalInternal extends Component { ); } - private renderAdjectiveDetails(word) { - const { singular, plural, comparison } = declensionAdjective(word, ''); + private renderAdjectiveDetails(word, details) { + const { singular, plural, comparison } = declensionAdjective(word, '', details); const tableDataSingular = this.getAdjectiveSingularCasesTable(singular); const tableDataPlural = this.getAdjectivePluralCasesTable(plural); diff --git a/src/translations/data.json b/src/translations/data.json index da257b76..133d8faf 100644 --- a/src/translations/data.json +++ b/src/translations/data.json @@ -1695,6 +1695,21 @@ "mk": "Степени на споредување", "bg": "Степени за сравнение" }, + "degree": { + "en": "degree", + "isv": "stupenj", + "ru": "степень", + "uk": "ступінь", + "be": "ступень", + "pl": "stopień", + "cs": "stupeň", + "sk": "stupeň", + "sl": "stopnja", + "hr": "stupanj", + "sr": "степен", + "mk": "степен", + "bg": "степен" + }, "positive": { "en": "positive", "isv": "pozitivna", @@ -1712,7 +1727,7 @@ }, "comparative": { "en": "comparative", - "isv": "sravniteljna", + "isv": "sravniteljny", "ru": "сравнительная", "uk": "вищий", "be": "вышэйшая", @@ -1727,7 +1742,7 @@ }, "superlative": { "en": "superlative", - "isv": "superlativna", + "isv": "superlativny", "ru": "превосходная", "uk": "найвищий", "be": "найвышэйшая", diff --git a/src/utils/wordDetails/wordDetails.ts b/src/utils/wordDetails/wordDetails.ts index 3e07c68b..1979cd38 100644 --- a/src/utils/wordDetails/wordDetails.ts +++ b/src/utils/wordDetails/wordDetails.ts @@ -146,7 +146,7 @@ export function getGender(details: string): Gender { if (arr.includes('m/f')) { return 'masculineOrFeminine'; } - + return 'neuter'; } @@ -170,6 +170,14 @@ export function isIndeclinable(details: string): boolean { return getArr(details).includes('indecl'); } +export function isComparative(details: string): boolean { + return getArr(details).includes('comp'); +} + +export function isSuperlative(details: string): boolean { + return getArr(details).includes('sup'); +} + // Numerals export function getNumeralType(details: string): string {