summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/data/schemas/dictionary-kanji-meta-bank-v3-schema.json2
-rw-r--r--ext/data/schemas/dictionary-term-meta-bank-v3-schema.json4
-rw-r--r--ext/js/language/translator.js16
3 files changed, 17 insertions, 5 deletions
diff --git a/ext/data/schemas/dictionary-kanji-meta-bank-v3-schema.json b/ext/data/schemas/dictionary-kanji-meta-bank-v3-schema.json
index 62479026..49f7c813 100644
--- a/ext/data/schemas/dictionary-kanji-meta-bank-v3-schema.json
+++ b/ext/data/schemas/dictionary-kanji-meta-bank-v3-schema.json
@@ -17,7 +17,7 @@
"description": "Type of data. \"freq\" corresponds to frequency information."
},
{
- "type": ["string", "number"],
+ "type": ["number"],
"description": "Data for the character."
}
]
diff --git a/ext/data/schemas/dictionary-term-meta-bank-v3-schema.json b/ext/data/schemas/dictionary-term-meta-bank-v3-schema.json
index 8eb9d343..206e7152 100644
--- a/ext/data/schemas/dictionary-term-meta-bank-v3-schema.json
+++ b/ext/data/schemas/dictionary-term-meta-bank-v3-schema.json
@@ -28,7 +28,7 @@
{
"oneOf": [
{
- "type": ["string", "number"],
+ "type": ["number"],
"description": "Frequency information for the term."
},
{
@@ -44,7 +44,7 @@
"description": "Reading for the term."
},
"frequency": {
- "type": ["string", "number"],
+ "type": ["number"],
"description": "Frequency information for the term."
}
}
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index 1abf9f4e..056ff3a7 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -866,7 +866,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
hasReading,
- frequency
+ this._convertFrequency(frequency)
));
}
}
@@ -920,7 +920,7 @@ class Translator {
dictionaryIndex,
dictionaryPriority,
character,
- data
+ this._convertFrequency(data)
));
}
break;
@@ -971,6 +971,18 @@ class Translator {
});
}
+ _convertFrequency(value) {
+ switch (typeof value) {
+ case 'number':
+ return value;
+ case 'string':
+ value = Number.parseFloat(value);
+ return Number.isFinite(value) ? value : 0;
+ default:
+ return 0;
+ }
+ }
+
// Helpers
_getNameBase(name) {