mirror of
https://github.com/LBRYFoundation/lbry.com.git
synced 2025-08-23 17:47:26 +00:00
allow refreshing of transifex cache
This commit is contained in:
parent
6295825f81
commit
2dbfb53492
2 changed files with 8 additions and 4 deletions
|
@ -29,14 +29,18 @@ class i18nActions extends Actions
|
||||||
throw new Exception('Please set Config::TRANSIFEX_API_KEY in your configuration.');
|
throw new Exception('Please set Config::TRANSIFEX_API_KEY in your configuration.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = Transifex::getTranslationResourceFile($project, $resource, $language);
|
$usecache = !Request::getParam('nocache');
|
||||||
|
$json = Transifex::getTranslationResourceFile($project, $resource, $language, $usecache);
|
||||||
|
|
||||||
if (!$json) {
|
if (!$json) {
|
||||||
return NavActions::execute404();
|
return NavActions::execute404();
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::setHeader(Response::HEADER_CROSS_ORIGIN, "*");
|
Response::setHeader(Response::HEADER_CROSS_ORIGIN, "*");
|
||||||
|
|
||||||
|
if ($usecache) {
|
||||||
Response::enablePublicMutableCache(md5(json_encode($json)));
|
Response::enablePublicMutableCache(md5(json_encode($json)));
|
||||||
|
}
|
||||||
|
|
||||||
return View::renderJson($json);
|
return View::renderJson($json);
|
||||||
}
|
}
|
||||||
|
|
4
lib/thirdparty/Transifex.class.php
vendored
4
lib/thirdparty/Transifex.class.php
vendored
|
@ -7,12 +7,12 @@ class Transifex
|
||||||
return (boolean)Config::get(Config::TRANSIFEX_API_KEY);
|
return (boolean)Config::get(Config::TRANSIFEX_API_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getTranslationResourceFile($project, $resource, $language)
|
public static function getTranslationResourceFile($project, $resource, $language, $cache = true)
|
||||||
{
|
{
|
||||||
$url = "https://www.transifex.com/api/2/project/$project/resource/$resource/translation/$language?file=1";
|
$url = "https://www.transifex.com/api/2/project/$project/resource/$resource/translation/$language?file=1";
|
||||||
return json_decode(CurlWithCache::get($url, [], [
|
return json_decode(CurlWithCache::get($url, [], [
|
||||||
'password' => 'api:' . Config::get(Config::TRANSIFEX_API_KEY),
|
'password' => 'api:' . Config::get(Config::TRANSIFEX_API_KEY),
|
||||||
'cache' => 1000 * 60 * 60 * 8
|
'cache' => $cache ? 1000 * 60 * 60 * 8 : false
|
||||||
]), true);
|
]), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue