forked from lbryio/lbry.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18nActions.class.php
47 lines (36 loc) · 1.27 KB
/
i18nActions.class.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
<?php
class i18nActions extends Actions
{
public static function setCulture()
{
$culture = Request::getPostParam('culture');
// Validate
if ($culture && !in_array($culture, i18n::getAllCultures())) {
$culture = null;
}
if ($culture) {
Session::set(Session::KEY_USER_CULTURE, $culture);
} else {
Session::unsetKey(Session::KEY_USER_CULTURE);
}
//if session changes update domain
//english language = www
return Controller::redirect(Request::getReferrer());
}
public static function executeServeTranslationFile(string $project, string $resource, string $language)
{
if (!Transifex::isConfigured()) {
throw new Exception('Please set Config::TRANSIFEX_API_KEY in your configuration.');
}
$usecache = !Request::getParam('nocache');
$json = Transifex::getTranslationResourceFile($project, $resource, $language, $usecache);
if (!$json) {
return NavActions::execute404();
}
Response::setHeader(Response::HEADER_CROSS_ORIGIN, "*");
if ($usecache) {
Response::enablePublicMutableCache(md5(json_encode($json)));
}
return View::renderJson($json);
}
}