Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat::Add multilanguage sexes (Issue #251) #312

Merged
merged 4 commits into from
Dec 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Person
* Person::sex() // "Male"
* @endcode
*/
static std::string sex();
static std::string sex(Language language = Language::English);
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved

/**
* @brief Returns a random gender.
Expand Down
72 changes: 72 additions & 0 deletions include/faker-cxx/types/Language.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#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
};

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);
}

}
58 changes: 55 additions & 3 deletions 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 @@ -8,13 +10,63 @@ enum class Sex
Female,
};

inline std::string toString(Sex sex)
const std::map<Language, std::map<Sex, std::string>> sexTranslations = {
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
{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"}}},
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
{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"}}},
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
{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)
cieslarmichal marked this conversation as resolved.
Show resolved Hide resolved
{
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";
}

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


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",
};
}
Loading