From ee1ce84564b1d7ed700f5cdcad21876b6d8d9b83 Mon Sep 17 00:00:00 2001 From: Mohit Singh Date: Fri, 24 Nov 2023 02:36:16 -0500 Subject: [PATCH] feat::Add multilanguage sexes (Issue #251) 101a --- include/faker-cxx/types/Language.h | 77 ++++++++++++++++++++++++++++++ include/faker-cxx/types/Sex.h | 21 +++++++- 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 include/faker-cxx/types/Language.h diff --git a/include/faker-cxx/types/Language.h b/include/faker-cxx/types/Language.h new file mode 100644 index 000000000..0da0ed138 --- /dev/null +++ b/include/faker-cxx/types/Language.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include + +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 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 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); +} + +} \ No newline at end of file diff --git a/include/faker-cxx/types/Sex.h b/include/faker-cxx/types/Sex.h index 4d0858d1a..b7afbe5b1 100644 --- a/include/faker-cxx/types/Sex.h +++ b/include/faker-cxx/types/Sex.h @@ -1,5 +1,7 @@ #pragma once +#include "Language.h" + namespace faker { enum class Sex @@ -26,6 +28,23 @@ const std::map> 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, "Nő"}}}, + {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) @@ -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)