forked from marcotroisi/microtranslator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
80 lines (64 loc) · 1.85 KB
/
index.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* @author Marco Troisi
* @created 03.04.15
*/
require 'vendor/autoload.php';
$f3 = Base::instance();
/**
* Mongo Connection
*/
$m = new MongoClient();
$db = $m->selectDB('microtranslator');
$locale = (isset($_GET['locale'])) ? $_GET['locale'] : 'en_GB';
$mongoDictionary = new \MicroTranslator\Library\MongoDictionary($locale, $db, 'translations', 'word', 'translation');
$translator = new \Moss\Locale\Translator\Translator($locale, $mongoDictionary);
/**
* Translation Service
*/
$translationService = new \MicroTranslator\Service\Translation(
new \MicroTranslator\Repository\Translation($db),
$translator
);
/**
* Controllers
*/
$localeController = new \MicroTranslator\Controller\LocaleController($translationService);
$translationController = new \MicroTranslator\Controller\TranslationController($translationService);
/**
* Routes
*/
// Home
$f3->route('GET /',
function() use ($translationService) {
echo 'MicroTranslator';
}
);
// Gets All Available Locales
$f3->route('GET /locale',
function() use ($localeController) {
return $localeController->showAllAvailable();
}
);
// Gets All Terms
$f3->route('GET /translation',
function($f3, $params) use ($translationController) {
return $translationController->show();
}
);
// Gets or inserts/updates a Term for a specific Locale
$f3->route('GET|POST /translation/@word',
function($f3, $params) use ($translationController, $locale) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$translation = $f3->get('POST.translation');
$word = $params['word'];
return $translationController->save($word, $locale, $translation);
}
return $translationController->show($locale, $params['word']);
}
);
// Gets Untranslated Terms for a specific Locale
/**
* Run F3 Application
*/
$f3->run();