Skip to content

Commit

Permalink
i18n: translatable pos
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Nov 19, 2024
1 parent a2ad8bd commit 0a88b82
Show file tree
Hide file tree
Showing 11 changed files with 1,071 additions and 150 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 5 additions & 66 deletions src/components/Modals/DetailModal/DetailModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { t } from 'translations';
import { hideModalDialog, setAlphabetTypeAction } from 'actions';
import { IMainState } from 'reducers';

import { expandAbbr } from "utils/abbreviations";
import { getCaseTips } from 'utils/getCaseTips';
import { getCyrillic } from 'utils/getCyrillic';
import { getGlagolitic } from 'utils/getGlagolitic';
Expand All @@ -17,13 +18,10 @@ import {
getNumeralType,
getPartOfSpeech,
getPronounType,
getVerbDetails,
isAnimated,
isComparative,
isIndeclinable,
isPlural,
isSingular,
isSuperlative,
} from 'utils/wordDetails';

import { LineSelector } from 'components/LineSelector';
Expand Down Expand Up @@ -59,12 +57,14 @@ class DetailModalInternal extends Component<IDetailModalInternal> {
return null;
}

const pos = getPartOfSpeech(this.props.details);
const { word, add, details } = this.props;

return (
<>
<div className="modal-dialog__header">
{this.renderTitle(pos)}
<span className="modal-dialog__header-title">
{this.formatStr(word)} {this.formatStr(add)} <span className="details">({expandAbbr(details)})</span>
</span>
<button
className="modal-dialog__header-close"
onClick={this.props.close}
Expand Down Expand Up @@ -102,67 +102,6 @@ class DetailModalInternal extends Component<IDetailModalInternal> {
);
}

private renderTitle(pos: string) {
const { details, word, add } = this.props;
const arr = [t(pos)];

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 (isIndeclinable(details)) {
arr.push(t('noun-indeclinable'));
}
if (isPlural(details)) {
arr.push(t('noun-plural'));
}
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) {
arr.push(...verbDetails.map((e) => t('verb-' + e)));
}
break;
}
case 'numeral': {
const numeralType = getNumeralType(details);
if (numeralType) {
arr.push(t('numeral-' + numeralType));
}
break;
}
case 'pronoun': {
const pronounType = getPronounType(details);
if (pronounType) {
arr.push(t('pronoun-' + pronounType));
}
break;
}
}

return (
<span className="modal-dialog__header-title">
{this.formatStr(word)} {this.formatStr(add)} <span className="details">({arr.join(', ')})</span>
</span>
);
}

private renderBody() {
const fieldIsv = this.props.word;
const fieldAddition = this.props.add;
Expand Down
18 changes: 12 additions & 6 deletions src/components/ResultsCard/ResultsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import { useCaseQuestions } from 'hooks/useCaseQuestions';
import { useIntersect } from 'hooks/useIntersect';
import { useLang } from 'hooks/useLang';
import { useShortCardView } from 'hooks/useShortCardView';
import { expandAbbr, translateAbbr } from "utils/abbreviations";
import { estimateIntelligibility, hasIntelligibilityIssues } from "utils/intelligibilityIssues";
import { removeBrackets } from "utils/removeBrackets";
import { toQueryString } from 'utils/toQueryString';
import { getPartOfSpeech } from 'utils/wordDetails';
import { wordHasForms } from 'utils/wordHasForms';

import { Clipboard } from 'components/Clipboard';

import { removeBrackets } from "../../utils/removeBrackets";

import './ResultsCard.scss';

import ErrorIcon from './images/error-icon.svg';
Expand Down Expand Up @@ -93,7 +93,7 @@ function renderOriginal(item, alphabets, caseQuestions, index) {
{caseInfo && <> <span className="caseInfo">({caseInfo})</span></>}
</span>
);
})}
})}
{!caseQuestions && item.caseInfo &&
<> <span className="caseInfo">(+{t(`case${item.caseInfo.slice(1)}`)})</span></>
}
Expand Down Expand Up @@ -221,12 +221,16 @@ export const ResultsCard =
{item.to === 'isv' && short && (
<>
&nbsp;
<span className="results-card__details">{item.details}</span>
<abbr title={expandAbbr(item.details)} className="results-card__details">
{translateAbbr(item.details)}
</abbr>
</>
)}
</div>
{!short && (
<span className="results-card__details">{item.details}</span>
<abbr title={expandAbbr(item.details)} className="results-card__details">
{translateAbbr(item.details)}
</abbr>
)}
<div className="results-card__bottom">
<div className="results-card__original">
Expand All @@ -240,7 +244,9 @@ export const ResultsCard =
/>
) : renderOriginal(item, alphabets, caseQuestions, index)}
{item.to !== 'isv' && short && (
<span className="results-card__details">{item.details}</span>
<abbr title={expandAbbr(item.details)} className="results-card__details">
{translateAbbr(item.details)}
</abbr>
)}
</div>
<div className="results-card__actions">
Expand Down
Loading

0 comments on commit 0a88b82

Please sign in to comment.