summaryrefslogtreecommitdiff
path: root/ext/js/language
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/language')
-rw-r--r--ext/js/language/translator.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 845d53d5..0d26b2f0 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -289,6 +289,7 @@ export class Translator {
return false;
}
+ /** @type {Map<string, number>} */
const frequencyCounter = new Map();
for (const element of array1) {
@@ -400,6 +401,7 @@ export class Translator {
* @returns {Map<string, import('translation-internal').DatabaseDeinflection[]>}
*/
_groupDeinflectionsByTerm(deinflections) {
+ /** @type {Map<string, import('translation-internal').DatabaseDeinflection[]>} */
const result = new Map();
for (const deinflection of deinflections) {
const {deinflectedText} = deinflection;
@@ -455,7 +457,7 @@ export class Translator {
/** @type {import('translation-internal').DatabaseDeinflection[]} */
const deinflections = [];
const used = new Set();
- /** @type {Map<string, import('core').SafeAny>} */
+ /** @type {import('translation-internal').TextCache} */
const sourceCache = new Map(); // For reusing text processors' outputs
for (
@@ -498,14 +500,15 @@ export class Translator {
/**
* @param {import('language').TextProcessorWithId<unknown>[]} textProcessors
- * @param {Map<string, unknown>} processorVariant
+ * @param {import('translation-internal').TextProcessorVariant} processorVariant
* @param {string} text
- * @param {Map<string, import('core').SafeAny>} textCache
+ * @param {import('translation-internal').TextCache} textCache
* @returns {string}
*/
_applyTextProcessors(textProcessors, processorVariant, text, textCache) {
for (const {id, textProcessor: {process}} of textProcessors) {
const setting = processorVariant.get(id);
+
let level1 = textCache.get(text);
if (!level1) {
level1 = new Map();
@@ -522,7 +525,7 @@ export class Translator {
text = process(text, setting);
level2.set(setting, text);
} else {
- text = level2.get(setting);
+ text = level2.get(setting) || '';
}
}
@@ -681,6 +684,7 @@ export class Translator {
/** @type {import('dictionary-database').TermExactRequest[]} */
const termList = [];
const targetList = [];
+ /** @type {Map<string, {groups: import('translator').DictionaryEntryGroup[]}>} */
const targetMap = new Map();
for (const group of groupedDictionaryEntries) {
@@ -1362,10 +1366,10 @@ export class Translator {
/**
* @param {Map<string, unknown[]>} arrayVariants
- * @returns {Map<string, unknown>[]}
+ * @returns {import('translation-internal').TextProcessorVariant[]}
*/
_getArrayVariants(arrayVariants) {
- /** @type {Map<string, unknown>[]} */
+ /** @type {import('translation-internal').TextProcessorVariant[]} */
const results = [];
const variantKeys = [...arrayVariants.keys()];
const entryVariantLengths = [];
@@ -1376,7 +1380,7 @@ export class Translator {
const totalVariants = entryVariantLengths.reduce((acc, length) => acc * length, 1);
for (let variantIndex = 0; variantIndex < totalVariants; ++variantIndex) {
- /** @type {Map<string, unknown>} */
+ /** @type {import('translation-internal').TextProcessorVariant}} */
const variant = new Map();
let remainingIndex = variantIndex;
@@ -2076,6 +2080,7 @@ export class Translator {
* @param {boolean} ascending
*/
_updateSortFrequencies(dictionaryEntries, dictionary, ascending) {
+ /** @type {Map<number, number>} */
const frequencyMap = new Map();
for (const dictionaryEntry of dictionaryEntries) {
const {definitions, frequencies} = dictionaryEntry;