diff options
author | Stefan Giehl <stefan@matomo.org> | 2021-09-01 11:00:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-01 11:00:26 +0300 |
commit | ba1facfd1ecb4e618f3162aedbdb3170e9461e50 (patch) | |
tree | e9a1b4561753c0b46608fb9280addd9623f03d5f /core | |
parent | fb9a8736b0d4fcd6cedcd7df9a3a6eae6c3d3f5f (diff) |
Prepares Weblate migration (#17927)
* Add translation stats to readme
* improve generate-intl command
* update readme
* remove translation workflow
* allow empty translation files
* Adds internal parameter to ignore config in LanguageManager API
* ignore missing translators
* extend commands to ignore language info
* Update lang/README.md
Co-authored-by: Lukas Winkler <git@lw1.at>
* Update commands to use Weblate instead of Transifex API
* Replace remaining Transifex occurences
* submodule updates
* fix/update tests
Co-authored-by: Lukas Winkler <git@lw1.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/Translation/Weblate/API.php (renamed from core/Translation/Transifex/API.php) | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/core/Translation/Transifex/API.php b/core/Translation/Weblate/API.php index b6bcfbed04..dad14ee6ac 100644 --- a/core/Translation/Transifex/API.php +++ b/core/Translation/Weblate/API.php @@ -6,7 +6,7 @@ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later * */ -namespace Piwik\Translation\Transifex; +namespace Piwik\Translation\Weblate; use Exception; use Piwik\Cache; @@ -15,40 +15,51 @@ use Piwik\Http; class API { - protected $apiUrl = 'https://www.transifex.com/api/2/'; - protected $username = ''; - protected $password = ''; + protected $apiUrl = 'https://hosted.weblate.org/api/'; + protected $apiToken = ''; protected $projectSlug = ''; - public function __construct($username, $password, $project = 'matomo') + public function __construct($apiToken, $project = 'matomo') { - $this->username = $username; - $this->password = $password; + $this->apiToken = $apiToken; $this->projectSlug = $project; } /** - * Returns all resources available on Transifex project + * Returns all resources available on Weblate project * * @return array */ public function getAvailableResources() { $cache = Cache::getTransientCache(); - $cacheId = 'transifex_resources_' . $this->projectSlug; - $resources = $cache->fetch($cacheId); + $cacheId = 'weblate_resources_' . $this->projectSlug; + $result = $cache->fetch($cacheId); - if (empty($resources)) { - $apiPath = 'project/' . $this->projectSlug . '/resources'; + if (empty($result)) { + $apiPath = 'projects/' . $this->projectSlug . '/components/'; $resources = $this->getApiResults($apiPath); - $cache->save($cacheId, $resources); + $result = []; + + while($resources->results) { + $result = array_merge($result, $resources->results); + + if ($resources->next) { + $apiPath = str_replace($this->apiUrl, '', $resources->next); + $resources = $this->getApiResults($apiPath); + } else { + break; + } + } + + $cache->save($cacheId, $result); } - return $resources; + return $result; } /** - * Checks if the given resource exists in Transifex project + * Checks if the given resource exists in Weblate project * * @param string $resource * @return bool @@ -65,7 +76,7 @@ class API } /** - * Returns all language codes the transifex project is available for + * Returns all language codes the Weblate project is available for * * @return array * @throws AuthenticationFailedException @@ -74,13 +85,13 @@ class API public function getAvailableLanguageCodes() { $cache = Cache::getTransientCache(); - $cacheId = 'transifex_languagescodes_' . $this->projectSlug; + $cacheId = 'weblate_languagescodes_' . $this->projectSlug; $languageCodes = $cache->fetch($cacheId); if (empty($languageCodes)) { - $apiData = $this->getApiResults('project/' . $this->projectSlug . '/languages'); + $apiData = $this->getApiResults('projects/' . $this->projectSlug . '/languages/'); foreach ($apiData as $languageData) { - $languageCodes[] = $languageData->language_code; + $languageCodes[] = $languageData->code; } $cache->save($cacheId, $languageCodes); } @@ -88,19 +99,6 @@ class API } /** - * Returns statistic data for the given resource - * - * @param string $resource e.g. piwik-base, piwik-plugin-api,... - * @return array - * @throws AuthenticationFailedException - * @throws Exception - */ - public function getStatistics($resource) - { - return $this->getApiResults('project/' . $this->projectSlug . '/resource/' . $resource . '/stats/'); - } - - /** * Return the translations for the given resource and language * * @param string $resource e.g. piwik-base, piwik-plugin-api,... @@ -113,7 +111,7 @@ class API public function getTranslations($resource, $language, $raw = false) { if ($this->resourceExists($resource)) { - $apiPath = 'project/' . $this->projectSlug . '/resource/' . $resource . '/translation/' . $language . '/?mode=onlytranslated&file'; + $apiPath = 'translations/' . $this->projectSlug . '/' . $resource . '/' . $language . '/file/'; return $this->getApiResults($apiPath, $raw); } return null; @@ -132,7 +130,9 @@ class API { $apiUrl = $this->apiUrl . $apiPath; - $response = Http::sendHttpRequest($apiUrl, 1000, null, null, 5, false, false, true, 'GET', $this->username, $this->password); + $response = Http::sendHttpRequestBy(Http::getTransportMethod(), $apiUrl, 60, null, null, null, 5, false, + false, false, true, 'GET', null, null, null, + ['Authorization: Token ' . $this->apiToken]); $httpStatus = $response['status']; $response = $response['data']; |