Skip to content

Commit

Permalink
feat: comparative and superlative adjectives declension
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Mar 3, 2024
1 parent ad2679a commit b93d7a2
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
40 changes: 27 additions & 13 deletions src/components/Modals/DetailModal/DetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import {
getPronounType,
getVerbDetails,
isAnimated,
isComparative,
isIndeclinable,
isPlural,
isSingular,
isSuperlative,
} from 'utils/wordDetails';

import { LineSelector } from 'components/LineSelector';
Expand All @@ -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;
Expand Down Expand Up @@ -96,28 +104,34 @@ class DetailModalInternal extends Component<IDetailModalInternal> {
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) {
Expand Down Expand Up @@ -185,7 +199,7 @@ class DetailModalInternal extends Component<IDetailModalInternal> {
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);
Expand All @@ -212,7 +226,7 @@ class DetailModalInternal extends Component<IDetailModalInternal> {
private formatStr(str: string): string {
if (str === '') {
return '';
} else if (str === null) {
} else if (str == null) {
return '&mdash;';
} else if (str.match(/&\w+;/g)) {
return str;
Expand Down Expand Up @@ -360,8 +374,8 @@ class DetailModalInternal extends Component<IDetailModalInternal> {
);
}

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);
Expand Down
19 changes: 17 additions & 2 deletions src/translations/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -1712,7 +1727,7 @@
},
"comparative": {
"en": "comparative",
"isv": "sravniteljna",
"isv": "sravniteljny",
"ru": "сравнительная",
"uk": "вищий",
"be": "вышэйшая",
Expand All @@ -1727,7 +1742,7 @@
},
"superlative": {
"en": "superlative",
"isv": "superlativna",
"isv": "superlativny",
"ru": "превосходная",
"uk": "найвищий",
"be": "найвышэйшая",
Expand Down
10 changes: 9 additions & 1 deletion src/utils/wordDetails/wordDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export function getGender(details: string): Gender {
if (arr.includes('m/f')) {
return 'masculineOrFeminine';
}

return 'neuter';
}

Expand All @@ -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 {
Expand Down

0 comments on commit b93d7a2

Please sign in to comment.