Skip to content

Commit

Permalink
feat::Add multilanguage sexes (Issue #251)
Browse files Browse the repository at this point in the history
  • Loading branch information
qmohitsingh committed Nov 24, 2023
1 parent adef940 commit 75717d7
Show file tree
Hide file tree
Showing 23 changed files with 331 additions and 1,177 deletions.
45 changes: 42 additions & 3 deletions include/faker-cxx/types/Sex.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,52 @@ enum class Sex
Female,
};

inline std::string toString(Sex sex)
const std::map<Language, std::map<Sex, std::string>> sexTranslations = {
{Language::English, {{Sex::Male, "Male"}, {Sex::Female, "Female"}}},
{Language::Polish, {{Sex::Male, "Mężczyzna"}, {Sex::Female, "Kobieta"}}},
{Language::Italian, {{Sex::Male, "Maschio"}, {Sex::Female, "Femmina"}}},
{Language::French, {{Sex::Male, "Homme"}, {Sex::Female, "Femme"}}},
{Language::German, {{Sex::Male, "Mann"}, {Sex::Female, "Frau"}}},
{Language::Russian, {{Sex::Male, "Мужчина"}, {Sex::Female, "Женщина"}}},
{Language::Romanian, {{Sex::Male, "Bărbat"}, {Sex::Female, "Femeie"}}},
{Language::Hindi, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}},
{Language::Finnish, {{Sex::Male, "Mies"}, {Sex::Female, "Nainen"}}},
{Language::Nepali, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}},
{Language::Spanish, {{Sex::Male, "Hombre"}, {Sex::Female, "Mujer"}}},
{Language::Turkish, {{Sex::Male, "Erkek"}, {Sex::Female, "Kadın"}}},
{Language::Czech, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}},
{Language::Slovak, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}},
{Language::Ukrainian, {{Sex::Male, "Чоловік"}, {Sex::Female, "Жінка"}}},
{Language::Danish, {{Sex::Male, "Mand"}, {Sex::Female, "Kvinde"}}},
{Language::Swedish, {{Sex::Male, "Man"}, {Sex::Female, "Kvinna"}}},
};

inline std::string translateSex(Sex sex, Language language = Language::English)
{
std::map<Sex, std::string> sexToStringMapping{{Sex::Male, "Male"}, {Sex::Female, "Female"}};
auto langItr = sexTranslations.find(language);
if (langItr != sexTranslations.end())
{
auto sexItr = langItr->second.find(sex);
if (sexItr != langItr->second.end())
{
return sexItr->second;
}
}
return "Unknown"; // Default or throw exception
}

return sexToStringMapping.at(sex);
inline std::string toString(Sex sex, Language language = Language::English)
{
return translateSex(sex, language);
}

// inline std::string toString(Sex sex,const std::string& language = "English")
//{
// std::map<Sex, std::string> sexToStringMapping{{Sex::Male, "Male"}, {Sex::Female, "Female"}};
//
// return sexToStringMapping.at(sex);
// }

inline std::ostream& operator<<(std::ostream& os, Sex sex)
{
return os << toString(sex);
Expand Down
24 changes: 11 additions & 13 deletions src/modules/food/FoodTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ TEST_F(FoodTest, shouldGenerateAlcoholicBeverage)
{
const auto generatedAlcoholicBeverage = Food::alcoholicBeverage();

ASSERT_TRUE(
std::ranges::any_of(alcoholicBeverages, [generatedAlcoholicBeverage](const std::string& alcoholicBeverage) { return generatedAlcoholicBeverage == alcoholicBeverage; }));
ASSERT_TRUE(std::ranges::any_of(alcoholicBeverages,
[generatedAlcoholicBeverage](const std::string& alcoholicBeverage)
{ return generatedAlcoholicBeverage == alcoholicBeverage; }));
}

TEST_F(FoodTest, shouldGenerateDishName)
Expand Down Expand Up @@ -63,8 +64,7 @@ TEST_F(FoodTest, shouldGenerateMeat)
{
const auto generatedMeat = Food::meat();

ASSERT_TRUE(std::ranges::any_of(meats, [generatedMeat](const std::string& meat)
{ return generatedMeat == meat; }));
ASSERT_TRUE(std::ranges::any_of(meats, [generatedMeat](const std::string& meat) { return generatedMeat == meat; }));
}

TEST_F(FoodTest, shouldGenerateMilkProduct)
Expand All @@ -79,24 +79,23 @@ TEST_F(FoodTest, shouldGenerateNonalcoholicBeverages)
{
const auto generatedNonalcoholicBeverages = Food::nonalcoholicBeverage();

ASSERT_TRUE(std::ranges::any_of(nonalcoholicBeverages, [generatedNonalcoholicBeverages](const std::string& nonalcoholicBeverage)
ASSERT_TRUE(std::ranges::any_of(nonalcoholicBeverages,
[generatedNonalcoholicBeverages](const std::string& nonalcoholicBeverage)
{ return generatedNonalcoholicBeverages == nonalcoholicBeverage; }));
}

TEST_F(FoodTest, shouldGenerateNut)
{
const auto generatedNut = Food::nut();

ASSERT_TRUE(std::ranges::any_of(nuts, [generatedNut](const std::string& nut)
{ return generatedNut == nut; }));
ASSERT_TRUE(std::ranges::any_of(nuts, [generatedNut](const std::string& nut) { return generatedNut == nut; }));
}

TEST_F(FoodTest, shouldGenerateOil)
{
const auto generatedOil = Food::oil();

ASSERT_TRUE(std::ranges::any_of(oils, [generatedOil](const std::string& oil)
{ return generatedOil == oil; }));
ASSERT_TRUE(std::ranges::any_of(oils, [generatedOil](const std::string& oil) { return generatedOil == oil; }));
}

TEST_F(FoodTest, shouldGenerateSeafood)
Expand All @@ -111,16 +110,15 @@ TEST_F(FoodTest, shouldGenerateSeed)
{
const auto generatedSeed = Food::seed();

ASSERT_TRUE(std::ranges::any_of(seeds, [generatedSeed](const std::string& seed)
{ return generatedSeed == seed; }));
ASSERT_TRUE(std::ranges::any_of(seeds, [generatedSeed](const std::string& seed) { return generatedSeed == seed; }));
}

TEST_F(FoodTest, shouldGenerateGrain)
{
const auto generatedGrain = Food::grain();

ASSERT_TRUE(std::ranges::any_of(grains, [generatedGrain](const std::string& grain)
{ return generatedGrain == grain; }));
ASSERT_TRUE(
std::ranges::any_of(grains, [generatedGrain](const std::string& grain) { return generatedGrain == grain; }));
}

TEST_F(FoodTest, shouldGenerateSugarProduct)
Expand Down
17 changes: 4 additions & 13 deletions src/modules/food/data/FoodCategories.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@

namespace faker
{
const std::vector<std::string> foodCategories = {
"Vegetables",
"Fruits",
"Meat",
"Seafood",
"Dairy",
"Grains",
"Beverages",
"Desserts",
"Snacks",
"Condiments",
"Frozen Foods",
};
const std::vector<std::string> foodCategories = {
"Vegetables", "Fruits", "Meat", "Seafood", "Dairy", "Grains",
"Beverages", "Desserts", "Snacks", "Condiments", "Frozen Foods",
};
}
54 changes: 10 additions & 44 deletions src/modules/food/data/Fruits.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,14 @@
#include <string>
#include <vector>

namespace faker {
const std::vector<std::string> fruits = {
"Apple",
"Banana",
"Orange",
"Strawberry",
"Pineapple",
"Mango",
"Grapes",
"Kiwi",
"Peach",
"Pear",
"Cherry",
"Blueberry",
"Raspberry",
"Blackberry",
"Avocado",
"Lemon",
"Lime",
"Grapefruit",
"Cantaloupe",
"Honeydew",
"Pomegranate",
"Apricot",
"Plum",
"Nectarine",
"Fig",
"Papaya",
"Passion Fruit",
"Guava",
"Coconut",
"Dragon Fruit",
"Persimmon",
"Cranberry",
"Date",
"Lychee",
"Mulberry",
"Kumquat",
"Jackfruit",
"Starfruit",
"Rambutan",
"Gooseberry",
"Elderberry",
};
namespace faker
{
const std::vector<std::string> fruits = {
"Apple", "Banana", "Orange", "Strawberry", "Pineapple", "Mango", "Grapes",
"Kiwi", "Peach", "Pear", "Cherry", "Blueberry", "Raspberry", "Blackberry",
"Avocado", "Lemon", "Lime", "Grapefruit", "Cantaloupe", "Honeydew", "Pomegranate",
"Apricot", "Plum", "Nectarine", "Fig", "Papaya", "Passion Fruit", "Guava",
"Coconut", "Dragon Fruit", "Persimmon", "Cranberry", "Date", "Lychee", "Mulberry",
"Kumquat", "Jackfruit", "Starfruit", "Rambutan", "Gooseberry", "Elderberry",
};
}
39 changes: 8 additions & 31 deletions src/modules/food/data/Grains.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,12 @@
#include <string>
#include <vector>

namespace faker {
const std::vector<std::string> grains = {
"Wheat",
"Rice",
"Barley",
"Oats",
"Quinoa",
"Corn",
"Rye",
"Millet",
"Buckwheat",
"Sorghum",
"Amaranth",
"Triticale",
"Spelt",
"Farro",
"Kamut",
"Emmer",
"Freekeh",
"Teff",
"Job's Tears",
"Einkorn",
"Bulgur",
"Maize",
"Semolina",
"Soy",
"Lentils",
"Chia Seeds",
"Flaxseeds",
"Sunflower Seeds",
};
namespace faker
{
const std::vector<std::string> grains = {
"Wheat", "Rice", "Barley", "Oats", "Quinoa", "Corn", "Rye",
"Millet", "Buckwheat", "Sorghum", "Amaranth", "Triticale", "Spelt", "Farro",
"Kamut", "Emmer", "Freekeh", "Teff", "Job's Tears", "Einkorn", "Bulgur",
"Maize", "Semolina", "Soy", "Lentils", "Chia Seeds", "Flaxseeds", "Sunflower Seeds",
};
}
30 changes: 6 additions & 24 deletions src/modules/food/data/Meats.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,10 @@
#include <string>
#include <vector>

namespace faker {
const std::vector<std::string> meats = {
"Chicken",
"Beef",
"Pork",
"Lamb",
"Turkey",
"Fish",
"Venison",
"Duck",
"Quail",
"Goose",
"Salmon",
"Shrimp",
"Crab",
"Lobster",
"Bison",
"Veal",
"Haddock",
"Trout",
"Tuna",
"Sausage",
"Ham",
};
namespace faker
{
const std::vector<std::string> meats = {
"Chicken", "Beef", "Pork", "Lamb", "Turkey", "Fish", "Venison", "Duck", "Quail", "Goose", "Salmon",
"Shrimp", "Crab", "Lobster", "Bison", "Veal", "Haddock", "Trout", "Tuna", "Sausage", "Ham",
};
}
44 changes: 9 additions & 35 deletions src/modules/food/data/MilkProducts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,13 @@
#include <string>
#include <vector>

namespace faker {
const std::vector<std::string> milkProducts = {
"Milk",
"Cheese",
"Yogurt",
"Butter",
"Cream",
"Sour Cream",
"Cottage Cheese",
"Whipped Cream",
"Ice Cream",
"Condensed Milk",
"Evaporated Milk",
"Mozzarella",
"Feta",
"Parmesan",
"Provolone",
"Cheddar",
"Gouda",
"Blue Cheese",
"Swiss Cheese",
"Brie",
"Camembert",
"Ricotta",
"Goat Cheese",
"Mascarpone",
"Quark",
"Havarti",
"Colby",
"Monterey Jack",
"Gruyère",
"Havarti",
"Cream Cheese",
"Neufchâtel",
};
namespace faker
{
const std::vector<std::string> milkProducts = {
"Milk", "Cheese", "Yogurt", "Butter", "Cream", "Sour Cream", "Cottage Cheese",
"Whipped Cream", "Ice Cream", "Condensed Milk", "Evaporated Milk", "Mozzarella", "Feta", "Parmesan",
"Provolone", "Cheddar", "Gouda", "Blue Cheese", "Swiss Cheese", "Brie", "Camembert",
"Ricotta", "Goat Cheese", "Mascarpone", "Quark", "Havarti", "Colby", "Monterey Jack",
"Gruyère", "Havarti", "Cream Cheese", "Neufchâtel",
};
}
7 changes: 4 additions & 3 deletions src/modules/food/data/NonalcoholicBeverages.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include <string>
#include <vector>

namespace faker {
const std::vector<std::string> nonalcoholicBeverages = {
namespace faker
{
const std::vector<std::string> nonalcoholicBeverages = {
"Water",
"Tea",
"Coffee",
Expand Down Expand Up @@ -36,5 +37,5 @@ namespace faker {
"Vegetable Juice",
"Pear Nectar",
"Mango Lassi",
};
};
}
20 changes: 6 additions & 14 deletions src/modules/food/data/Nuts.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@
#include <string>
#include <vector>

namespace faker {
const std::vector<std::string> nuts = {
"Almond",
"Walnut",
"Pecan",
"Cashew",
"Pistachio",
"Hazelnut",
"Macadamia",
"Brazil Nut",
"Pine Nut",
"Chestnut",
"Peanut",
};
namespace faker
{
const std::vector<std::string> nuts = {
"Almond", "Walnut", "Pecan", "Cashew", "Pistachio", "Hazelnut",
"Macadamia", "Brazil Nut", "Pine Nut", "Chestnut", "Peanut",
};
}
Loading

0 comments on commit 75717d7

Please sign in to comment.