mirror of
https://github.com/LucasVbr/own-workspace.git
synced 2026-05-19 10:53:19 +00:00
🇺🇸 Translate #btn-newword in english
This commit is contained in:
+46
-26
@@ -18,7 +18,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="btn-newword">
|
<div id="btn-newword">
|
||||||
<button @click="getNewWordEveryday" id="fetch" class="btn">
|
<button @click="getNewWordEveryday" id="fetch" class="btn">
|
||||||
Générer un mot
|
Generate a word
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
@@ -46,17 +46,17 @@
|
|||||||
<script>
|
<script>
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "Stats",
|
name: 'Stats',
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
date: "",
|
date: '',
|
||||||
time: "",
|
time: '',
|
||||||
word: {
|
word: {
|
||||||
word: "",
|
word: '',
|
||||||
definition: "",
|
definition: '',
|
||||||
},
|
},
|
||||||
displayWord: true,
|
displayWord: true,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
generateDateOfTheDay() {
|
generateDateOfTheDay() {
|
||||||
@@ -69,9 +69,28 @@ export default {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
prettyPrintDate(date, day, month) {
|
prettyPrintDate(date, day, month) {
|
||||||
const days = ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi"];
|
const days = [
|
||||||
|
'Dimanche',
|
||||||
|
'Lundi',
|
||||||
|
'Mardi',
|
||||||
|
'Mercredi',
|
||||||
|
'Jeudi',
|
||||||
|
'Vendredi',
|
||||||
|
'Samedi'];
|
||||||
const dayOfTheWeek = days[date.getDay()];
|
const dayOfTheWeek = days[date.getDay()];
|
||||||
const months = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"];
|
const months = [
|
||||||
|
'janvier',
|
||||||
|
'février',
|
||||||
|
'mars',
|
||||||
|
'avril',
|
||||||
|
'mai',
|
||||||
|
'juin',
|
||||||
|
'juillet',
|
||||||
|
'août',
|
||||||
|
'septembre',
|
||||||
|
'octobre',
|
||||||
|
'novembre',
|
||||||
|
'décembre'];
|
||||||
return `${dayOfTheWeek}, ${day} ${months[month - 1]}`;
|
return `${dayOfTheWeek}, ${day} ${months[month - 1]}`;
|
||||||
},
|
},
|
||||||
getCurrentTime() {
|
getCurrentTime() {
|
||||||
@@ -84,28 +103,28 @@ export default {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
},
|
},
|
||||||
prettyPrintTime(hours, minutes) {
|
prettyPrintTime(hours, minutes) {
|
||||||
return `${hours < 10 ? "0" + hours : hours}:${minutes < 10 ? "0" + minutes : minutes}`;
|
return `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ?
|
||||||
|
'0' + minutes :
|
||||||
|
minutes}`;
|
||||||
},
|
},
|
||||||
getNewWordEveryday() {
|
getNewWordEveryday() {
|
||||||
document.getElementById("fetch").disabled = true;
|
document.getElementById('fetch').disabled = true;
|
||||||
// fetch a new english word everyday
|
// fetch a new english word everyday
|
||||||
fetch("https://random-word-api.herokuapp.com/word?number=1")
|
fetch('https://random-word-api.herokuapp.com/word?number=1').
|
||||||
.then(response => response.json())
|
then(response => response.json()).
|
||||||
.then(data => {
|
then(data => {
|
||||||
// uppercase first letter of data[0]
|
// uppercase first letter of data[0]
|
||||||
const word = data[0];
|
const word = data[0];
|
||||||
this.getDefinition(word);
|
this.getDefinition(word);
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
getDefinition(word) {
|
getDefinition(word) {
|
||||||
const url = 'https://api.dictionaryapi.dev/api/v2/entries/en/' + word;
|
const url = 'https://api.dictionaryapi.dev/api/v2/entries/en/' + word;
|
||||||
return fetch(url)
|
return fetch(url).then(response => response.json()).then(data => {
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
document.getElementById("fetch").disabled = false;
|
document.getElementById('fetch').disabled = false;
|
||||||
const wordUppercased = word.charAt(0).toUpperCase() + word.slice(1);
|
const wordUppercased = word.charAt(0).toUpperCase() + word.slice(1);
|
||||||
this.word.word = wordUppercased + " : ";
|
this.word.word = wordUppercased + ' : ';
|
||||||
this.word.definition = data[0].meanings[0].definitions[0].definition;
|
this.word.definition = data[0].meanings[0].definitions[0].definition;
|
||||||
} else {
|
} else {
|
||||||
// get another word if the word is not found
|
// get another word if the word is not found
|
||||||
@@ -114,7 +133,7 @@ export default {
|
|||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.generateDateOfTheDay();
|
this.generateDateOfTheDay();
|
||||||
@@ -130,16 +149,16 @@ export default {
|
|||||||
},
|
},
|
||||||
colorSelected() {
|
colorSelected() {
|
||||||
return this.$store.getters.colorSelected;
|
return this.$store.getters.colorSelected;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
colorSelected: function(color) {
|
colorSelected: function(color) {
|
||||||
if (this.displayWord) {
|
if (this.displayWord) {
|
||||||
document.getElementById("word").style.color = color;
|
document.getElementById('word').style.color = color;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
@@ -200,6 +219,7 @@ export default {
|
|||||||
#see-words {
|
#see-words {
|
||||||
margin-top: 16px;
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ********** */
|
/* ********** */
|
||||||
/* RESPONSIVE */
|
/* RESPONSIVE */
|
||||||
/* ********** */
|
/* ********** */
|
||||||
|
|||||||
Reference in New Issue
Block a user