fix(rewrite): Use Math.min instead of max, remove logs

This commit is contained in:
tecc 2023-09-20 01:57:10 +02:00
parent bc2abe50fa
commit e854a89303
No known key found for this signature in database
GPG Key ID: 622EEC5BAE5EBD3A
2 changed files with 14 additions and 7 deletions

View File

@ -363,24 +363,31 @@ export class Locale {
thirdMorphemeThreeForms = thirdMorpheme.map((x) => `[-${x}]`);
}
for (let istr in firstMorpheme) {
const i = istr as unknown as number;
for (let i = 0; i < firstMorpheme.length; i++) {
let firstPart = firstMorpheme[i];
let secondPart =
secondMorpheme[Math.max(i, secondMorpheme.length - 1)];
secondMorpheme[Math.min(i, secondMorpheme.length - 1)];
if (
firstPart === secondPart &&
thirdMorpheme.length &&
!this.config.pronouns.threeForms
) {
secondPart =
thirdMorpheme[Math.max(i, thirdMorpheme.length - 1)];
thirdMorpheme[Math.min(i, thirdMorpheme.length - 1)];
}
let variant = firstPart + "/" + secondPart;
if (this.config.pronouns.threeForms) {
variant += "/" + thirdMorphemeThreeForms[i];
variant +=
"/" +
thirdMorphemeThreeForms[
Math.min(i, thirdMorphemeThreeForms.length - 1)
];
} else if (pronoun.thirdForm) {
variant += "/" + thirdFormMorpheme[i];
variant +=
"/" +
thirdFormMorpheme[
Math.min(i, thirdFormMorpheme.length - 1)
];
}
variants.add(variant);

View File

@ -77,7 +77,7 @@ export const plugin = async function (app: AppInstance) {
let found = locale.pronoun(key);
if (found == null) {
found = parsePronounFromParts(keyParts, locale.morphemes);
req.log.info(`${JSON.stringify(keyParts)} - ${found}`);
// req.log.info(`${JSON.stringify(keyParts)} - ${found}`);
}
if (found == null) {
return replyError(reply, ApiError.UNKNOWN_PRONOUN);