My problem is with code about translating a single word into 5 languages
My code:
#include <iostream>
#include <map>
int dict_number;
static const int dict_length = 10;
struct Dictionary
{
std::map<int, std::string> dictionary_no{
{1, "Eple"},
{2, "Banan"},
{3, "Hjem"},
{4, "Hallo"},
{5, "Kafe" },
{6, "Brød"},
{7, "Melk"},
{8, "Hamster"},
{9, "Katt"},
{10, "Hund"}
};
std::map<int, std::string> dictionary_en = {
{1, "Apple"},
{2, "Banana"},
{3, "Home"},
{4, "Hello"},
{5, "Cafe" },
{6, "Bread"},
{7, "Milk"},
{8, "Hamster"},
{9, "Cat"},
{10, "Dog"}
};
std::map<int, std::string> dictionary_pl = {
{1, "Jabłko"},
{2, "Banan"},
{3, "Dom"},
{4, "Cześć"},
{5, "Kawa" },
{6, "Chleb"},
{7, "Mleko"},
{8, "Chomik"},
{9, "Kot"},
{10, "Pies"}
};
std::map<int, std::string> dictionary_de = {
{1, "Apfel"},
{2, "Banane"},
{3, "Haus"},
{4, "Hallo"},
{5, "Kaffee" },
{6, "Brot"},
{7, "Milch"},
{8, "Hamster"},
{9, "Katze"},
{10, "Hund"}
};
std::map<int, std::string> dictionary_ua = {
{1, "Яблуко"},
{2, "Банан"},
{3, "Дім"},
{4, "Привіт"},
{5, "Кафе" },
{6, "Хліб"},
{7, "Молоко"},
{8, "Хом’як"},
{9, "Кіт"},
{10, "Пес"}
};
std::map<int, std::string> dictionary_cn = {
{1, "蘋果"},
{2, "香蕉"},
{3, "房子"},
{4, "你好"},
{5, "咖啡"},
{6, "麵包"},
{7, "牛奶"},
{8, "倉鼠"},
{9, "貓"},
{10, "狗"}
};
};
Dictionary dictionary;
enum Translation
{
polish,
ukrainian,
german,
english,
norwegian,
chinese
};
void translateWord(Translation translation, Translation translateTo, std::string word)
{
switch (translation)
{
case english:
for (int search = 0; search < dictionary.dictionary_en.size(); search++) {
if (dictionary.dictionary_en[search] == word) {
dict_number = search;
switch (translateTo)
{
case german:
std::cout << dictionary.dictionary_de[dict_number] << std::endl;
break;
case norwegian:
std::cout << dictionary.dictionary_no[dict_number] << std::endl;
break;
case polish:
std::cout << dictionary.dictionary_pl[dict_number] << std::endl;
break;
case ukrainian:
std::cout << dictionary.dictionary_ua[dict_number] << std::endl;
break;
case chinese:
std::cout << dictionary.dictionary_cn[dict_number] << std::endl;
break;
}
}
}
break;
case german:
for (int search = 0; search < dictionary.dictionary_de.size(); search++) {
if (dictionary.dictionary_de[search] == word) {
dict_number = search;
switch (translateTo)
{
case english:
std::cout << dictionary.dictionary_en[dict_number] << std::endl;
break;
case norwegian:
std::cout << dictionary.dictionary_no[dict_number] << std::endl;
break;
case polish:
std::cout << dictionary.dictionary_pl[dict_number] << std::endl;
break;
case ukrainian:
std::cout << dictionary.dictionary_ua[dict_number] << std::endl;
break;
case chinese:
std::cout << dictionary.dictionary_cn[dict_number] << std::endl;
break;
}
}
}
break;
case norwegian:
for (int search = 0; search < dictionary.dictionary_no.size(); search++) {
if (dictionary.dictionary_no[search] == word) {
dict_number = search;
switch (translateTo)
{
case german:
std::cout << dictionary.dictionary_de[dict_number] << std::endl;
break;
case english:
std::cout << dictionary.dictionary_en[dict_number] << std::endl;
break;
case polish:
std::cout << dictionary.dictionary_pl[dict_number] << std::endl;
break;
case ukrainian:
std::cout << dictionary.dictionary_ua[dict_number] << std::endl;
break;
case chinese:
std::cout << dictionary.dictionary_cn[dict_number] << std::endl;
break;
}
}
}
break;
case polish:
for (int search = 0; search < dictionary.dictionary_pl.size(); search++) {
if (dictionary.dictionary_pl[search] == word) {
dict_number = search;
switch (translateTo)
{
case german:
std::cout << dictionary.dictionary_de[dict_number] << std::endl;
break;
case norwegian:
std::cout << dictionary.dictionary_no[dict_number] << std::endl;
break;
case english:
std::cout << dictionary.dictionary_en[dict_number] << std::endl;
break;
case ukrainian:
std::cout << dictionary.dictionary_ua[dict_number] << std::endl;
break;
case chinese:
std::cout << dictionary.dictionary_cn[dict_number] << std::endl;
break;
}
}
}
break;
case ukrainian:
for (int search = 0; search < dictionary.dictionary_ua.size(); search++) {
if (dictionary.dictionary_ua[search] == word) {
dict_number = search;
switch (translateTo)
{
case german:
std::cout << dictionary.dictionary_de[dict_number] << std::endl;
break;
case norwegian:
std::cout << dictionary.dictionary_no[dict_number] << std::endl;
break;
case polish:
std::cout << dictionary.dictionary_pl[dict_number] << std::endl;
break;
case english:
std::cout << dictionary.dictionary_en[dict_number] << std::endl;
break;
case chinese:
std::cout << dictionary.dictionary_cn[dict_number] << std::endl;
break;
}
}
}
break;
case chinese:
for (int search = 0; search < dictionary.dictionary_cn.size(); search++) {
if (dictionary.dictionary_cn[search] == word) {
dict_number = search;
switch (translateTo)
{
case english:
std::cout << dictionary.dictionary_en[dict_number] << std::endl;
break;
case german:
std::cout << dictionary.dictionary_de[dict_number] << std::endl;
break;
case norwegian:
std::cout << dictionary.dictionary_no[dict_number] << std::endl;
break;
case polish:
std::cout << dictionary.dictionary_pl[dict_number] << std::endl;
break;
case ukrainian:
std::cout << dictionary.dictionary_ua[dict_number] << std::endl;
break;
}
}
}
break;
}
}
int main()
{
translateWord(english, polish, "Hello");
return 0;
}
Can this code be improved or shortened? Big thanks for help!