So for my final year project, I am trying to build a language learning web application for indigenous languages where I am.
The problem is, I have no idea how the code would even look like.
Like how do they know when I type “bonjour”, it actually means “good day”?
Or for example if I type “je le veux” meaning “I want it” in French.
how do they know that is correct? Duolingo for example will mark me as wrong if I type “je veux le”
do they use like an JS object or python dictionary to store the data or something?
ChatGPT, says it would be something like this
// Define a dictionary of correct translations
const translations = {
"hello": "bonjour",
"goodbye": "au revoir",
"I want it": "je le veux",
// Add more translations as needed
};
// Function to check if user input is correct
function checkTranslation(userInput) {
// Normalize user input (e.g., convert to lowercase)
userInput = userInput.toLowerCase().trim();
// Look up the correct translation for the user's input
const correctTranslation = translations[userInput];
// Check if the translation exists and matches the user's input
if (correctTranslation && correctTranslation === userInput) {
return true; // User input is correct
} else {
return false; // User input is incorrect
}
}
// Example usage
const userInput1 = "Bonjour";
const userInput2 = "je veux le";
console.log(checkTranslation(userInput1)); // Output: true (correct)
console.log(checkTranslation(userInput2)); // Output: false (incorrect)`````
I would like a human opinion also.
what do you guys think?