Skip to content

Commit

Permalink
feat::Add multilanguage sexes (Issue #251) 101a
Browse files Browse the repository at this point in the history
  • Loading branch information
qmohitsingh committed Nov 24, 2023
1 parent 75717d7 commit ee1ce84
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
77 changes: 77 additions & 0 deletions include/faker-cxx/types/Language.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#pragma once

#include <map>
#include <vector>

namespace faker
{

enum class Language
{
English,
Polish,
French,
German,
Italian,
Russian,
Romanian,
Hindi,
Finnish,
Nepali,
Spanish,
Turkish,
Czech,
Slovak,
Ukrainian,
Danish,
Swedish,
Portuguese,
Norwegian,
Japanese,
Hungarian,
Croatian,
Greek,
Slovene,
Dutch,
Mandarin,
Korean,
Serbian,
Macedonian,
Albanian,
Latvian,
Irish,
Belarusian,
Estonian
};

//const std::vector<Language> languages{
// Language::English, Language::Polish, Language::Italian, Language::French, Language::German, Language::Russian,
// Language::Romanian, Language::Hindi, Language::Finnish, Language::Nepali, Language::Spanish, Language::Turkish,
// Language::Czech, Language::Slovak, Language::Ukrainian, Language::Danish, Language::Swedish};

inline std::string toString(Language language)
{
static const std::map<Language, std::string> languageToStringMapping{
{Language::English, "English"}, {Language::Polish, "Polish"}, {Language::Italian, "Italian"},
{Language::French, "French"}, {Language::German, "German"}, {Language::Russian, "Russian"},
{Language::Romanian, "Romanian"}, {Language::Hindi, "Hindi"}, {Language::Finnish, "Finnish"},
{Language::Nepali, "Nepali"}, {Language::Spanish, "Spanish"}, {Language::Turkish, "Turkish"},
{Language::Czech, "Czech"}, {Language::Slovak, "Slovak"}, {Language::Ukrainian, "Ukrainian"},
{Language::Danish, "Danish"}, {Language::Swedish, "Swedish"},
{Language::Portuguese, "Portuguese"}, {Language::Norwegian, "Norwegian"}, {Language::Japanese, "Japanese"},
{Language::Hungarian, "Hungarian"}, {Language::Croatian, "Croatian"}, {Language::Greek, "Greek"},
{Language::Slovene, "Slovene"}, {Language::Dutch, "Dutch"}, {Language::Mandarin, "Mandarin"},
{Language::Korean, "Korean"}, {Language::Serbian, "Serbian"}, {Language::Macedonian, "Macedonian"},
{Language::Albanian, "Albanian"}, {Language::Latvian, "Latvian"}, {Language::Irish, "Irish"},
{Language::Belarusian, "Belarusian"}, {Language::Estonian, "Estonian"}
};

return languageToStringMapping.at(language);
}

inline std::ostream& operator<<(std::ostream& os, Language language)
{
return os << toString(language);
}

}
21 changes: 20 additions & 1 deletion include/faker-cxx/types/Sex.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "Language.h"

namespace faker
{
enum class Sex
Expand All @@ -26,6 +28,23 @@ const std::map<Language, std::map<Sex, std::string>> sexTranslations = {
{Language::Ukrainian, {{Sex::Male, "Чоловік"}, {Sex::Female, "Жінка"}}},
{Language::Danish, {{Sex::Male, "Mand"}, {Sex::Female, "Kvinde"}}},
{Language::Swedish, {{Sex::Male, "Man"}, {Sex::Female, "Kvinna"}}},
{Language::Portuguese, {{Sex::Male, "Homem"}, {Sex::Female, "Mulher"}}},
{Language::Norwegian, {{Sex::Male, "Mann"}, {Sex::Female, "Kvinne"}}},
{Language::Japanese, {{Sex::Male, "男性"}, {Sex::Female, "女性"}}},
{Language::Hungarian, {{Sex::Male, "Férfi"}, {Sex::Female, ""}}},
{Language::Croatian, {{Sex::Male, "Muškarac"}, {Sex::Female, "Žena"}}},
{Language::Greek, {{Sex::Male, "Άνδρας"}, {Sex::Female, "Γυναίκα"}}},
{Language::Slovene, {{Sex::Male, "Moški"}, {Sex::Female, "Ženska"}}},
{Language::Dutch, {{Sex::Male, "Man"}, {Sex::Female, "Vrouw"}}},
{Language::Mandarin, {{Sex::Male, ""}, {Sex::Female, ""}}},
{Language::Korean, {{Sex::Male, "남자"}, {Sex::Female, "여자"}}},
{Language::Serbian, {{Sex::Male, "Мушкарац"}, {Sex::Female, "Жена"}}},
{Language::Macedonian, {{Sex::Male, "Маж"}, {Sex::Female, "Жена"}}},
{Language::Albanian, {{Sex::Male, "Mashkull"}, {Sex::Female, "Femër"}}},
{Language::Latvian, {{Sex::Male, "Vīrietis"}, {Sex::Female, "Sieviete"}}},
{Language::Belarusian, {{Sex::Male, "Мужчына"}, {Sex::Female, "Жанчына"}}},
{Language::Estonian, {{Sex::Male, "Mees"}, {Sex::Female, "Naine"}}},
{Language::Irish, {{Sex::Male, "fireannach"}, {Sex::Female, "baineann"}}}
};

inline std::string translateSex(Sex sex, Language language = Language::English)
Expand All @@ -39,7 +58,7 @@ inline std::string translateSex(Sex sex, Language language = Language::English)
return sexItr->second;
}
}
return "Unknown"; // Default or throw exception
return "Unknown";
}

inline std::string toString(Sex sex, Language language = Language::English)
Expand Down

0 comments on commit ee1ce84

Please sign in to comment.