commit 5ef6d667d0e02e6a847ff799b123f784a4ce01c1
parent b2d0352275a0e9875a62316816eaec4f88ebb86a
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Sun, 28 Feb 2021 18:54:05 -0800
Fix issue with getLang method
Diffstat:
4 files changed, 47 insertions(+), 27 deletions(-)
diff --git a/js/global.js b/js/global.js
@@ -23,20 +23,6 @@ function SetTheme(darkTheme = null) {
/**
- * Read a peice of text.
- * @param {String} text - The text to read.
- * @param {String} label - The language of the text.
- */
-function Read(text, label)
-{
- var msg = new SpeechSynthesisUtterance(text);
- msg.lang = getLang(label);
- window.speechSynthesis.speak(msg);
-}
-
-
-
-/**
* Load settings from localStorage.
* @returns {Object} The settings.
*/
diff --git a/js/quizzer.js b/js/quizzer.js
@@ -229,13 +229,25 @@ let quizzer = Vue.component("quizzer", {
* @returns {String} - The language code ("en", "es", etc.)
*/
getLang: function(label) {
- if (label.toLowerCase().includes("spanish")) {
- return "es";
+ if (label.toLowerCase().includes("english") || label.toLowerCase().includes("type") || label.toLowerCase().includes("category")) {
+ return "en";
}
else {
- return "en";
+ return "es";
}
},
+
+ /**
+ * Read a peice of text.
+ * @param {String} text - The text to read.
+ * @param {String} label - The language of the text.
+ */
+ Read: function(text, label)
+ {
+ var msg = new SpeechSynthesisUtterance(text);
+ msg.lang = this.getLang(label);
+ window.speechSynthesis.speak(msg);
+ },
},
computed: {
diff --git a/js/reference.js b/js/reference.js
@@ -26,15 +26,27 @@ let referenceTables = Vue.component("referenceTables", {
* @returns {String} - The language code ("en", "es", etc.)
*/
getLang: function(label) {
- if (label.toLowerCase().includes("spanish")) {
- return "es";
+ if (label.toLowerCase().includes("english") || label.toLowerCase().includes("type") || label.toLowerCase().includes("category")) {
+ return "en";
}
else {
- return "en";
+ return "es";
}
},
/**
+ * Read a peice of text.
+ * @param {String} text - The text to read.
+ * @param {String} label - The language of the text.
+ */
+ Read: function(text, label)
+ {
+ var msg = new SpeechSynthesisUtterance(text);
+ msg.lang = this.getLang(label);
+ window.speechSynthesis.speak(msg);
+ },
+
+ /**
* Handle a keyup event (implements keyboard shortcuts).
* @param {object} e - The event args.
*/
diff --git a/tests/test.quizzer.js b/tests/test.quizzer.js
@@ -554,19 +554,29 @@ describe("Quizzer", function() {
});
describe("GetLang method", function() {
- it("Should return English by default", function() {
- expect(Quizzer.getLang("")).to.equal("en");
- expect(Quizzer.getLang("test")).to.equal("en");
+ it("Should return Spanish by default", function() {
+ expect(Quizzer.getLang("")).to.equal("es");
+ expect(Quizzer.getLang("test")).to.equal("es");
});
- it("Should return English for English labels", function() {
+ it("Should return English for labels containing 'english'", function() {
expect(Quizzer.getLang("test english test")).to.equal("en");
expect(Quizzer.getLang("ENGLISH")).to.equal("en");
- })
+ });
+
+ it("Should return English for labels containing 'type'", function() {
+ expect(Quizzer.getLang("test type test")).to.equal("en");
+ expect(Quizzer.getLang("ENGLISH")).to.equal("en");
+ });
- it("Should return Spanish for Spanish labels", function() {
+ it("Should return English for labels containing 'category'", function() {
+ expect(Quizzer.getLang("test category test")).to.equal("en");
+ expect(Quizzer.getLang("ENGLISH")).to.equal("en");
+ });
+
+ it("Should return Spanish for labels containing 'spanish'", function() {
expect(Quizzer.getLang("test spanish test")).to.equal("es");
expect(Quizzer.getLang("SPANISH")).to.equal("es");
- })
+ });
});
});