-
Notifications
You must be signed in to change notification settings - Fork 0
/
WikiTextGenerator.php
57 lines (47 loc) · 2 KB
/
WikiTextGenerator.php
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
<?php
namespace App\Services;
class WikiTextGenerator {
public function wordToWikiText(string $label, string $translation, string $grammarCategory, string $langCode, array $exampleLabels, array $exampleTranslations): string {
$categoryCode = $this->mapGrammarCategoryToTranslation($grammarCategory);
$wikiText = "=== {{S|$categoryCode|$langCode}} ===" . "\r\n";
$wikiText .= "'''$label''' {{pron||$langCode}}" . "\r\n";
$wikiText .= "# $translation" . "\r\n";
for ($i = 0; $i < count($exampleLabels); $i++) {
$examplelabel = $exampleLabels[$i];
$exampleTranslation = $exampleTranslations[$i];
$wikiText .= "#* $examplelabel" . "\r\n";
$wikiText .= "#*: $exampleTranslation" . "\r\n";
}
return $wikiText;
}
public function addNewLanguageSection(string $langCode): string {
$wikiText = "== {{langue|$langCode}} ==" . "\r\n";
$wikiText .= "=== {{S|étymologie}} ===" . "\r\n";
$wikiText .= ": {{ébauche-étym|$langCode}}" . "\r\n". "\r\n";
return $wikiText;
}
public function addWikiCategory(string $langCode): string {
$wikiCategory = $this->mapLangCodeToWikiCategory($langCode);
return "[[$wikiCategory]]". "\r\n";
}
private function mapLangCodeToWikiCategory(string $langCode): string {
return match($langCode) {
'adj' => "Catégorie:adioukrou",
'any' => "Catégorie:agni de Côte d’Ivoire",
'bci' => "Catégorie:baoulé",
'bété' => "Catégorie:bété (Côte d’Ivoire)",
'default' => '',
};
}
private function mapGrammarCategoryToTranslation(string $grammarCategory): string {
return match($grammarCategory) {
'noun' => "nom",
'verb' => "verbe",
'adj' => "adj",
'adj-int' => "adj-int",
'adv' => "adverbe",
'interj' => "interj",
'default' => $grammarCategory,
};
}
}