summaryrefslogtreecommitdiff
path: root/includes/pronouns.php
blob: 6ab2487cdbe17f59ae806867fb86526c08738523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php

$pronounsSets = [
    "pony" => [
        "gender" => "ponygender",
        "gender:fr" => "poneygenre",
        "object" => "pony",
        "person" => "pony",
        "possessive_det" => "pony's",
        "possessive_pro" => "pony's",
        "reflexive" => "ponyself",
        "subjective" => "pony",
        "third" => true,
        "color" => "warning"
    ],
    "she" => [
        "gender" => "female",
        "gender:fr" => "fille",
        "object" => "her",
        "person" => "girl",
        "possessive_det" => "her",
        "possessive_pro" => "hers",
        "reflexive" => "herself",
        "subjective" => "she",
        "third" => true,
        "color" => "success"
    ],
    "he" => [
        "gender" => "male",
        "gender:fr" => "garçon",
        "object" => "him",
        "person" => "boy",
        "possessive_det" => "his",
        "possessive_pro" => "his",
        "reflexive" => "himself",
        "subjective" => "he",
        "third" => true,
        "color" => "info"
    ],
    "it" => [
        "gender" => "agender",
        "gender:fr" => "agenre",
        "object" => "it",
        "person" => "person",
        "possessive_det" => "its",
        "possessive_pro" => "its",
        "reflexive" => "itself",
        "subjective" => "it",
        "third" => true,
        "color" => "light"
    ],
    "they" => [
        "gender" => "non binary",
        "gender:fr" => "non binaire",
        "object" => "them",
        "person" => "person",
        "possessive_det" => "their",
        "possessive_pro" => "theirs",
        "reflexive" => "themself",
        "subjective" => "they",
        "third" => false,
        "color" => "primary"
    ]
];

$pronounGetCount = 0;

$possibilitiesPerSet = [];
foreach ($pronounsSets as $name => $set) {
    if (!isset($possibilitiesPerSet[$name])) $possibilitiesPerSet[$name] = [];
    $possibilitiesPerSet[$name][] = $name;

    foreach ($set as $category => $value) {
        if (is_string($value)) $possibilitiesPerSet[$name][] = $value;
    }
}

function getSetFromValue(string $value) {
    global $possibilitiesPerSet;

    foreach ($possibilitiesPerSet as $name => $set) {
        if (in_array($value, $set)) {
            return $name;
        }
    }

    return null;
}

function getPronounsFromMark(?string $mark = null): array {
    if (!isset($mark) || trim($mark) === "") {
        return ["they"];
    } else {
        $parts = array_unique(array_map(function ($i) {
            return getSetFromValue($i);
        }, explode("/", $mark)));
        return $parts;
    }
}

function getMemberPronouns(?string $pronouns): ?array {
    global $pronounsSets;
    $list = getPronounsFromMark($pronouns);
    return $pronounsSets[$list[array_rand($list)]] ?? $pronounsSets["she"];
}

function getGenderFromPronoun(string $pronoun, bool $french = false) {
    global $pronounsSets;
    $set = getPronounsFromMark($pronoun)[0];

    if ($french) {
        return ($pronounsSets[$set] ?? $pronounsSets["they"])["gender:fr"];
    } else {
        return ($pronounsSets[$set] ?? $pronounsSets["they"])["gender"];
    }
}

function pronounInFrench(string $pronoun): string {
    return match ($pronoun) {
        "she" => "elle",
        "her" => "elle",
        "he"  => "il",
        "him" => "lui",
        "they" => "iel",
        "them" => "iel",
        "it" => "iel",
        "its" => "iel",
        "pony" => "poney",
        "pony's" => "à poney",
        "ponys" => "à poney",
        default => $pronoun,
    };
}

function getTooltipsFromMark(string $mark = null, bool $french = false): ?string {
    if (!isset($mark)) {
        return null;
    } else {
        if ($french) {
            return implode("/", array_map(function ($i) {
                return "<span title='" . ucfirst(getGenderFromPronoun($i, true)) . "' data-bs-toggle='tooltip'>" . pronounInFrench($i) . "</span>";
            }, explode("/", $mark)));
        } else {
            return implode("/", array_map(function ($i) {
                return "<span title='" . ucfirst(getGenderFromPronoun($i, false)) . "' data-bs-toggle='tooltip'>" . $i . "</span>";
            }, explode("/", $mark)));
        }
    }
}