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 /plugins/LanguagesManager | |
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 'plugins/LanguagesManager')
-rw-r--r-- | plugins/LanguagesManager/API.php | 51 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/CreatePull.php | 233 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/FetchTranslations.php | 45 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/LanguageCodes.php | 4 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/LanguageInfo.php | 4 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/LanguageNames.php | 4 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/SetTranslations.php | 2 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/Update.php | 35 | ||||
-rw-r--r-- | plugins/LanguagesManager/Commands/Validate.php | 17 | ||||
-rw-r--r-- | plugins/LanguagesManager/tests/Integration/LanguagesManagerTest.php | 2 |
10 files changed, 67 insertions, 330 deletions
diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php index fa80210065..8b071ae5da 100644 --- a/plugins/LanguagesManager/API.php +++ b/plugins/LanguagesManager/API.php @@ -32,31 +32,33 @@ use Piwik\Translation\Loader\DevelopmentLoader; */ class API extends \Piwik\Plugin\API { - protected $availableLanguageNames = null; - protected $languageNames = null; + protected $availableLanguageNames = []; + protected $languageNames = []; /** * Returns true if specified language is available * * @param string $languageCode + * @param bool $_ignoreConfig * @return bool true if language available; false otherwise */ - public function isLanguageAvailable($languageCode) + public function isLanguageAvailable($languageCode, $_ignoreConfig = false) { return $languageCode !== false && Filesystem::isValidFilename($languageCode) - && in_array($languageCode, $this->getAvailableLanguages()); + && in_array($languageCode, $this->getAvailableLanguages($_ignoreConfig)); } /** * Return array of available languages * + * @param bool $_ignoreConfig * @return array Array of strings, each containing its ISO language code */ - public function getAvailableLanguages() + public function getAvailableLanguages($_ignoreConfig = false) { - if (!is_null($this->languageNames)) { - return $this->languageNames; + if (!empty($this->languageNames[$_ignoreConfig])) { + return $this->languageNames[$_ignoreConfig]; } $path = PIWIK_INCLUDE_PATH . "/lang/"; $languagesPath = _glob($path . "*.json"); @@ -71,7 +73,12 @@ class API extends \Piwik\Plugin\API $configLanguages = Config::getInstance()->Languages["Languages"]; - $languages = array_intersect($filesystemLanguages, $configLanguages); + if ($_ignoreConfig) { + $languages = $filesystemLanguages; + } else { + $languages = array_intersect($filesystemLanguages, $configLanguages); + } + $this->enableDevelopmentLanguageInDevEnvironment($languages); /** @@ -83,18 +90,19 @@ class API extends \Piwik\Plugin\API */ Piwik::postEvent('LanguagesManager.getAvailableLanguages', array(&$languages)); - $this->languageNames = $languages; + $this->languageNames[$_ignoreConfig] = $languages; return $languages; } /** * Return information on translations (code, language, % translated, etc) * - * @param boolean $excludeNonCorePlugins excludes non core plugin from percentage calculation + * @param bool $excludeNonCorePlugins excludes non core plugin from percentage calculation + * @param bool $_ignoreConfig * * @return array Array of arrays */ - public function getAvailableLanguagesInfo($excludeNonCorePlugins=true) + public function getAvailableLanguagesInfo($excludeNonCorePlugins=true, $_ignoreConfig = false) { $data = file_get_contents(PIWIK_INCLUDE_PATH . '/lang/en.json'); $englishTranslation = json_decode($data, true); @@ -120,7 +128,7 @@ class API extends \Piwik\Plugin\API } } - $filenames = $this->getAvailableLanguages(); + $filenames = $this->getAvailableLanguages($_ignoreConfig); $languagesInfo = array(); foreach ($filenames as $filename) { $data = file_get_contents(sprintf('%s/lang/%s.json', PIWIK_INCLUDE_PATH, $filename)); @@ -168,7 +176,7 @@ class API extends \Piwik\Plugin\API $languageInfo = array('code' => $filename, 'name' => $translations['Intl']['OriginalLanguageName'], 'english_name' => $translations['Intl']['EnglishLanguageName'], - 'translators' => $translations['General']['TranslatorName'], + 'translators' => $translations['General']['TranslatorName'] ?? '-', 'percentage_complete' => $percentageComplete . '%', ); $languagesInfo[] = $languageInfo; @@ -179,12 +187,13 @@ class API extends \Piwik\Plugin\API /** * Return array of available languages * + * @param bool $_ignoreConfig * @return array Array of array, each containing its ISO language code and name of the language */ - public function getAvailableLanguageNames() + public function getAvailableLanguageNames($_ignoreConfig = false) { - $this->loadAvailableLanguages(); - return $this->availableLanguageNames; + $this->loadAvailableLanguages($_ignoreConfig); + return $this->availableLanguageNames[$_ignoreConfig]; } /** @@ -342,19 +351,19 @@ class API extends \Piwik\Plugin\API return $lang; } - private function loadAvailableLanguages() + private function loadAvailableLanguages($_ignoreConfig = false) { - if (!is_null($this->availableLanguageNames)) { + if (!empty($this->availableLanguageNames[$_ignoreConfig])) { return; } - $cacheId = 'availableLanguages'; + $cacheId = 'availableLanguages' . (int) $_ignoreConfig; $cache = PiwikCache::getEagerCache(); if ($cache->contains($cacheId)) { $languagesInfo = $cache->fetch($cacheId); } else { - $languages = $this->getAvailableLanguages(); + $languages = $this->getAvailableLanguages($_ignoreConfig); $languagesInfo = array(); foreach ($languages as $languageCode) { $data = @file_get_contents(PIWIK_INCLUDE_PATH . "/plugins/Intl/lang/$languageCode.json"); @@ -375,7 +384,7 @@ class API extends \Piwik\Plugin\API $cache->save($cacheId, $languagesInfo); } - $this->availableLanguageNames = $languagesInfo; + $this->availableLanguageNames[$_ignoreConfig] = $languagesInfo; } private function enableDevelopmentLanguageInDevEnvironment(&$languages) diff --git a/plugins/LanguagesManager/Commands/CreatePull.php b/plugins/LanguagesManager/Commands/CreatePull.php deleted file mode 100644 index 683f6e9c2b..0000000000 --- a/plugins/LanguagesManager/Commands/CreatePull.php +++ /dev/null @@ -1,233 +0,0 @@ -<?php -/** - * Matomo - free/libre analytics platform - * - * @link https://matomo.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ - -namespace Piwik\Plugins\LanguagesManager\Commands; - -use Piwik\Plugins\LanguagesManager\API; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; -use Symfony\Component\Console\Output\OutputInterface; - -/** - */ -class CreatePull extends TranslationBase -{ - const GIT_BASE_BRANCH = '4.x-dev'; - - protected function configure() - { - $this->setName('translations:createpull') - ->setDescription('Updates translation files') - ->addOption('username', 'u', InputOption::VALUE_OPTIONAL, 'Transifex username') - ->addOption('password', 'p', InputOption::VALUE_OPTIONAL, 'Transifex password') - ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'Transifex project slug') - ->addOption('plugin', 'P', InputOption::VALUE_OPTIONAL, 'optional name of plugin to update translations for'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $changes = shell_exec('git status --porcelain -uno'); - - if (!empty($changes)) { - - $output->writeln("You have uncommitted changes. Creating pull request is only available with a clean working directory"); - return; - } - - $unpushedCommits = shell_exec('git log origin/' . self::GIT_BASE_BRANCH . '..HEAD'); - - if (!empty($unpushedCommits)) { - - $output->writeln("You have unpushed commits. Creating pull request is only available with a clean working directory"); - return; - } - - chdir(PIWIK_DOCUMENT_ROOT); - - shell_exec(' - git checkout -f ' . self::GIT_BASE_BRANCH . ' > /dev/null 2>&1 - git pull > /dev/null 2>&1 - git submodule init > /dev/null 2>&1 - git submodule update > /dev/null 2>&1 - '); - - $plugin = $input->getOption('plugin'); - if (!empty($plugin)) { - - chdir(PIWIK_DOCUMENT_ROOT.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$plugin); - shell_exec(' - git checkout ' . self::GIT_BASE_BRANCH . ' > /dev/null 2>&1 - git pull > /dev/null 2>&1 - '); - } - - // check if branch exists localy and track it if not - $branch = shell_exec('git branch | grep translationupdates'); - - if (empty($branch)) { - - shell_exec('git checkout -b translationupdates origin/translationupdates'); - } - - // switch to branch and update it to latest $GIT_BASE_BRANCH - shell_exec(' - git checkout -f translationupdates > /dev/null 2>&1 - git reset --hard origin/' . self::GIT_BASE_BRANCH . ' > /dev/null 2>&1 - git push origin translationupdates > /dev/null 2>&1 - '); - - // update translation files - $command = $this->getApplication()->find('translations:update'); - $arguments = array( - 'command' => 'translations:update', - '--username' => $input->getOption('username'), - '--password' => $input->getOption('password'), - '--slug' => $input->getOption('slug'), - '--plugin' => $plugin - ); - $inputObject = new ArrayInput($arguments); - $inputObject->setInteractive($input->isInteractive()); - $command->run($inputObject, $output); - - shell_exec('git add lang/. > /dev/null 2>&1'); - - if (empty($plugin)) { - foreach (Update::getPluginsInCore() as $pluginName) { - shell_exec(sprintf('git add plugins/%s/lang/. > /dev/null 2>&1', $pluginName)); - } - } - - $changes = shell_exec('git status --porcelain -uno'); - - if (empty($changes)) { - - $output->writeln("Nothing changed. Everything is already up to date."); - shell_exec('git checkout ' . self::GIT_BASE_BRANCH . ' > /dev/null 2>&1'); - return; - } - - API::unsetInstance(); // reset languagemanager api (to force refresh of data) - - $stats = shell_exec('git diff --numstat HEAD'); - - preg_match_all('/([0-9]+)\t([0-9]+)\t[a-zA-Z\/]*lang\/([a-z]{2,3}(?:-[a-z]{2,3})?)\.json/', $stats, $lineChanges); - - $addedLinesSum = 0; - if (!empty($lineChanges[1])) { - $addedLinesSum = array_sum($lineChanges[1]); - } - - $linesSumByLang = array(); - $lineChangesCount = count($lineChanges[0]); - for ($i = 0; $i < $lineChangesCount; $i++) { - @$linesSumByLang[$lineChanges[3][$i]] += $lineChanges[1][$i]; - } - - preg_match_all('/M [a-zA-Z\/]*lang\/([a-z]{2,3}(?:-[a-z]{2,3})?)\.json/', $changes, $modifiedFiles); - preg_match_all('/A [a-zA-Z\/]*lang\/([a-z]{2,3}(?:-[a-z]{2,3})?)\.json/', $changes, $addedFiles); - - $messages = array(); - - $languageCodesTouched = array(); - if (!empty($addedFiles[1])) { - foreach ($addedFiles[1] as $addedFile) { - $languageInfo = $this->getLanguageInfoByIsoCode($addedFile); - $messages[$addedFile] = sprintf('- Added %s (%s changes / %s translated)\n', $languageInfo['english_name'], $linesSumByLang[$addedFile], $languageInfo['percentage_complete']); - } - $languageCodesTouched = array_merge($languageCodesTouched, $addedFiles[1]); - } - - if (!empty($modifiedFiles[1])) { - foreach ($modifiedFiles[1] as $modifiedFile) { - if ($linesSumByLang[$modifiedFile]) { - $languageInfo = $this->getLanguageInfoByIsoCode($modifiedFile); - $messages[$modifiedFile] = sprintf( - '- Updated %s (%s changes / %s translated)\n', - $languageInfo['english_name'], - $linesSumByLang[$modifiedFile], - $languageInfo['percentage_complete'] - ); - $languageCodesTouched[] = $modifiedFile; - } - } - $languageCodesTouched = array_unique($languageCodesTouched); - } - - $message = implode('', $messages); - - $message .= '\n\nHelp us translate Matomo in your language!\nSignup at https://www.transifex.com/matomo/matomo/\nIf you have any questions, get in touch with us at translations@matomo.org'; - - $languageCodesTouched = array_unique($languageCodesTouched, SORT_REGULAR); - - $title = sprintf( - 'Updated %s strings in %u languages (%s)', - $addedLinesSum, - count($languageCodesTouched), - implode(', ', $languageCodesTouched) - ); - - shell_exec('git commit -m "language update ${pluginName}"'); - shell_exec('git push'); - shell_exec('git checkout ' . self::GIT_BASE_BRANCH . ' > /dev/null 2>&1'); - - $this->createPullRequest($output, $title, $message); - } - - private function getLanguageInfoByIsoCode($isoCode) - { - $languages = API::getInstance()->getAvailableLanguagesInfo(); - foreach ($languages as $languageInfo) { - if ($languageInfo['code'] == $isoCode) { - return $languageInfo; - } - } - return array(); - } - - private function createPullRequest(OutputInterface $output, $title, $message) - { - $dialog = $this->getHelperSet()->get('dialog'); - - while (true) { - - $username = $dialog->ask($output, 'Please provide your GitHub username (to create a pull request using GitHub API): '); - - $returnCode = shell_exec('curl \ - -X POST \ - -k \ - --silent \ - --write-out %{http_code} \ - --stderr /dev/null \ - -o /dev/null \ - -u '.$username.' \ - --data "{\"title\":\"[automatic translation update] '.$title.'\",\"body\":\"'.$message.'\",\"head\":\"translationupdates\",\"base\":\"' . self::GIT_BASE_BRANCH . '\"}" \ - -H "Accept: application/json" \ - https://api.github.com/repos/matomo-org/matomo/pulls'); - - switch ($returnCode) { - case 401: - $output->writeln("Pull request failed. Bad credentials... Please try again"); - continue 2; - - case 422: - $output->writeln("Pull request failed. Unprocessable Entity. Maybe a pull request was already created before."); - return; - - case 201: - case 200: - $output->writeln("Pull request successfully created."); - return; - - default: - $output->writeln("Pull request failed... Please try again"); - } - } - } -} diff --git a/plugins/LanguagesManager/Commands/FetchTranslations.php b/plugins/LanguagesManager/Commands/FetchTranslations.php index e69fd49761..87dd5076f8 100644 --- a/plugins/LanguagesManager/Commands/FetchTranslations.php +++ b/plugins/LanguagesManager/Commands/FetchTranslations.php @@ -12,7 +12,7 @@ namespace Piwik\Plugins\LanguagesManager\Commands; use Piwik\Container\StaticContainer; use Piwik\Exception\AuthenticationFailedException; use Piwik\Plugins\LanguagesManager\API as LanguagesManagerApi; -use Piwik\Translation\Transifex\API; +use Piwik\Translation\Weblate\API; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -22,18 +22,16 @@ use Symfony\Component\Console\Output\OutputInterface; */ class FetchTranslations extends TranslationBase { - const DOWNLOAD_PATH = '/transifex'; + const DOWNLOAD_PATH = '/weblate'; protected function configure() { $path = StaticContainer::get('path.tmp') . self::DOWNLOAD_PATH; $this->setName('translations:fetch') - ->setDescription('Fetches translations files from Transifex to ' . $path) - ->addOption('username', 'u', InputOption::VALUE_OPTIONAL, 'Transifex username') - ->addOption('password', 'p', InputOption::VALUE_OPTIONAL, 'Transifex password') - ->addOption('lastupdate', 'l', InputOption::VALUE_OPTIONAL, 'Last time update ran', time()-30*24*3600) - ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'project slug on transifex', 'matomo') + ->setDescription('Fetches translations files from Weblate to ' . $path) + ->addOption('token', 't', InputOption::VALUE_OPTIONAL, 'Weblate API token') + ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'project slug on weblate', 'matomo') ->addOption('plugin', 'r', InputOption::VALUE_OPTIONAL, 'Plugin to update'); } @@ -41,37 +39,35 @@ class FetchTranslations extends TranslationBase { $output->setDecorated(true); - $username = $input->getOption('username'); - $password = $input->getOption('password'); + $apiToken = $input->getOption('token'); $plugin = $input->getOption('plugin'); - $lastUpdate = $input->getOption('lastupdate'); $slug = $input->getOption('slug'); - $resource = 'matomo-'. ($plugin ? 'plugin-'.strtolower($plugin) : 'base'); + $resource = $plugin ? 'plugin-'.strtolower($plugin) : 'matomo-base'; - $transifexApi = new API($username, $password, $slug); + $weblateApi = new API($apiToken, $slug); // remove all existing translation files in download path $files = glob($this->getDownloadPath() . DIRECTORY_SEPARATOR . '*.json'); array_map('unlink', $files); - if (!$transifexApi->resourceExists($resource)) { - $output->writeln("Skipping resource $resource as it doesn't exist on Transifex"); + if (!$weblateApi->resourceExists($resource)) { + $output->writeln("Skipping resource $resource as it doesn't exist on Weblate"); return; } - $output->writeln("Fetching translations from Transifex for resource $resource"); + $output->writeln("Fetching translations from Weblate for resource $resource"); try { - $languages = $transifexApi->getAvailableLanguageCodes(); + $languages = $weblateApi->getAvailableLanguageCodes(); if (!empty($plugin)) { $languages = array_filter($languages, function ($language) { - return LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language))); + return LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language)), true); }); } } catch (AuthenticationFailedException $e) { - $availableLanguages = LanguagesManagerApi::getInstance()->getAvailableLanguageNames(); + $availableLanguages = LanguagesManagerApi::getInstance()->getAvailableLanguageNames(true); $languageCodes = array(); foreach ($availableLanguages as $languageInfo) { @@ -96,20 +92,9 @@ class FetchTranslations extends TranslationBase $progress->start(); - $statistics = $transifexApi->getStatistics($resource); - foreach ($languages as $language) { try { - // if we have modification date given from statistics api compare it with given last update time to ignore not update resources - if (LanguagesManagerApi::getInstance()->isLanguageAvailable(str_replace('_', '-', strtolower($language))) && isset($statistics->$language)) { - $lastupdated = strtotime($statistics->$language->last_update); - if ($lastUpdate > $lastupdated) { - $progress->advance(); - continue; - } - } - - $translations = $transifexApi->getTranslations($resource, $language, true); + $translations = $weblateApi->getTranslations($resource, $language, true); file_put_contents($this->getDownloadPath() . DIRECTORY_SEPARATOR . str_replace('_', '-', strtolower($language)) . '.json', $translations); } catch (\Exception $e) { $output->writeln("Error fetching language file $language: " . $e->getMessage()); diff --git a/plugins/LanguagesManager/Commands/LanguageCodes.php b/plugins/LanguagesManager/Commands/LanguageCodes.php index 79129107a9..323aa0febb 100644 --- a/plugins/LanguagesManager/Commands/LanguageCodes.php +++ b/plugins/LanguagesManager/Commands/LanguageCodes.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\LanguagesManager\Commands; use Piwik\Plugins\LanguagesManager\API; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -20,12 +21,13 @@ class LanguageCodes extends TranslationBase protected function configure() { $this->setName('translations:languagecodes') + ->addOption('all', 'a', InputOption::VALUE_NONE, 'Displays all languages (ignores language configuration)') ->setDescription('Shows available language codes'); } protected function execute(InputInterface $input, OutputInterface $output) { - $languages = API::getInstance()->getAvailableLanguageNames(); + $languages = API::getInstance()->getAvailableLanguageNames($input->getOption('all')); $languageCodes = array(); foreach ($languages as $languageInfo) { diff --git a/plugins/LanguagesManager/Commands/LanguageInfo.php b/plugins/LanguagesManager/Commands/LanguageInfo.php index 5571db8cc3..ef38f3c2a8 100644 --- a/plugins/LanguagesManager/Commands/LanguageInfo.php +++ b/plugins/LanguagesManager/Commands/LanguageInfo.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\LanguagesManager\Commands; use Piwik\Plugins\LanguagesManager\API; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -20,12 +21,13 @@ class LanguageInfo extends TranslationBase protected function configure() { $this->setName('translations:languageinfo') + ->addOption('all', 'a', InputOption::VALUE_NONE, 'Displays all languages (ignores language configuration)') ->setDescription('Shows available languages info'); } protected function execute(InputInterface $input, OutputInterface $output) { - $languages = API::getInstance()->getAvailableLanguagesInfo(); + $languages = API::getInstance()->getAvailableLanguagesInfo(true, $input->getOption('all')); foreach ($languages as $languageInfo) { $output->writeln($languageInfo['code'].'|' . $languageInfo['english_name'] . '|' . $languageInfo['percentage_complete']); diff --git a/plugins/LanguagesManager/Commands/LanguageNames.php b/plugins/LanguagesManager/Commands/LanguageNames.php index 7e41d5057a..d30c81141e 100644 --- a/plugins/LanguagesManager/Commands/LanguageNames.php +++ b/plugins/LanguagesManager/Commands/LanguageNames.php @@ -11,6 +11,7 @@ namespace Piwik\Plugins\LanguagesManager\Commands; use Piwik\Plugins\LanguagesManager\API; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -20,12 +21,13 @@ class LanguageNames extends TranslationBase protected function configure() { $this->setName('translations:languagenames') + ->addOption('all', 'a', InputOption::VALUE_NONE, 'Displays all languages (ignores language configuration)') ->setDescription('Shows available language names'); } protected function execute(InputInterface $input, OutputInterface $output) { - $languages = API::getInstance()->getAvailableLanguageNames(); + $languages = API::getInstance()->getAvailableLanguageNames($input->getOption('all')); $languageNames = array(); foreach ($languages as $languageInfo) { diff --git a/plugins/LanguagesManager/Commands/SetTranslations.php b/plugins/LanguagesManager/Commands/SetTranslations.php index 6790d40158..4952e62962 100644 --- a/plugins/LanguagesManager/Commands/SetTranslations.php +++ b/plugins/LanguagesManager/Commands/SetTranslations.php @@ -43,7 +43,7 @@ class SetTranslations extends TranslationBase $languageCode = $input->getOption('code'); $filename = $input->getOption('file'); - $languageCodes = (new API())->getAvailableLanguages(); + $languageCodes = (new API())->getAvailableLanguages(true); if (empty($languageCode) || !in_array($languageCode, $languageCodes)) { $languageCode = $dialog->askAndValidate($output, 'Please provide a valid language code: ', function ($code) use ($languageCodes) { diff --git a/plugins/LanguagesManager/Commands/Update.php b/plugins/LanguagesManager/Commands/Update.php index 7fe598985d..4103b27f2b 100644 --- a/plugins/LanguagesManager/Commands/Update.php +++ b/plugins/LanguagesManager/Commands/Update.php @@ -28,10 +28,8 @@ class Update extends TranslationBase { $this->setName('translations:update') ->setDescription('Updates translation files') - ->addOption('force', 'f', InputOption::VALUE_NONE, 'Force update of all language files') - ->addOption('username', 'u', InputOption::VALUE_OPTIONAL, 'Transifex username') - ->addOption('password', 'p', InputOption::VALUE_OPTIONAL, 'Transifex password') - ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'Transifex project slug') + ->addOption('token', 't', InputOption::VALUE_OPTIONAL, 'Weblate API token') + ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'Weblate project slug') ->addOption('all', 'a', InputOption::VALUE_NONE, 'Force to update all plugins (even non core). Can not be used with plugin option') ->addOption('plugin', 'P', InputOption::VALUE_OPTIONAL, 'optional name of plugin to update translations for'); } @@ -45,7 +43,7 @@ class Update extends TranslationBase /** @var DialogHelper $dialog */ $dialog = $this->getHelperSet()->get('dialog'); - $languages = API::getInstance()->getAvailableLanguageNames(); + $languages = API::getInstance()->getAvailableLanguageNames(true); $languageCodes = array(); foreach ($languages as $languageInfo) { @@ -63,8 +61,6 @@ class Update extends TranslationBase if (empty($plugin)) { $pluginList = $forceAllPlugins ? self::getAllPlugins() : self::getPluginsInCore(); array_unshift($pluginList, ''); - } else { - $input->setOption('force', true); // force plugin only updates } foreach ($pluginList as $plugin) { @@ -220,34 +216,11 @@ class Update extends TranslationBase $command = $this->getApplication()->find('translations:fetch'); $arguments = array( 'command' => 'translations:fetch', - '--username' => $input->getOption('username'), - '--password' => $input->getOption('password'), + '--token' => $input->getOption('token'), '--slug' => $input->getOption('slug'), '--plugin' => $plugin ); - if ($input->getOption('force')) { - $arguments['--lastupdate'] = 1; - } else { - $lastModDate = strtotime('2015-01-04 00:00:00'); // date of initial transifex setup - try { - // try to find the language file (of given plugin) with the newest modification date in git log - $path = ($plugin ? 'plugins/' . $plugin . '/' : '') . 'lang'; - $files = explode("\n", trim(shell_exec('git ls-tree -r --name-only HEAD ' . $path))); - - foreach ($files as $file) { - $fileModDate = shell_exec('git log -1 --format="%at" -- ' . $file); - if (basename($file) != 'en.json' && $fileModDate > $lastModDate) { - $lastModDate = $fileModDate; - } - } - } catch (\Exception $e) { - } - - if ($lastModDate != 0) { - $arguments['--lastupdate'] = $lastModDate; - } - } $inputObject = new ArrayInput($arguments); $inputObject->setInteractive($input->isInteractive()); $command->run($inputObject, $output); diff --git a/plugins/LanguagesManager/Commands/Validate.php b/plugins/LanguagesManager/Commands/Validate.php index 07082ba730..c14273c0c2 100644 --- a/plugins/LanguagesManager/Commands/Validate.php +++ b/plugins/LanguagesManager/Commands/Validate.php @@ -24,9 +24,8 @@ class Validate extends TranslationBase { $this->setName('translations:validate') ->setDescription('Validates translation files') - ->addOption('username', 'u', InputOption::VALUE_OPTIONAL, 'Transifex username') - ->addOption('password', 'p', InputOption::VALUE_OPTIONAL, 'Transifex password') - ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'Transifex project slug') + ->addOption('token', 't', InputOption::VALUE_OPTIONAL, 'Weblate API token') + ->addOption('slug', 's', InputOption::VALUE_OPTIONAL, 'Weblate project slug') ->addOption('all', 'a', InputOption::VALUE_NONE, 'Force to update all plugins (even non core). Can not be used with plugin option') ->addOption('plugin', 'P', InputOption::VALUE_OPTIONAL, 'optional name of plugin to update translations for'); } @@ -37,7 +36,7 @@ class Validate extends TranslationBase $start = microtime(true); - $languages = API::getInstance()->getAvailableLanguageNames(); + $languages = API::getInstance()->getAvailableLanguageNames(true); $languageCodes = array(); foreach ($languages as $languageInfo) { @@ -127,12 +126,10 @@ class Validate extends TranslationBase $command = $this->getApplication()->find('translations:fetch'); $arguments = array( - 'command' => 'translations:fetch', - '--username' => $input->getOption('username'), - '--password' => $input->getOption('password'), - '--slug' => $input->getOption('slug'), - '--plugin' => $plugin, - '--lastupdate' => 1 + 'command' => 'translations:fetch', + '--token' => $input->getOption('token'), + '--slug' => $input->getOption('slug'), + '--plugin' => $plugin ); $inputObject = new ArrayInput($arguments); diff --git a/plugins/LanguagesManager/tests/Integration/LanguagesManagerTest.php b/plugins/LanguagesManager/tests/Integration/LanguagesManagerTest.php index 5b776c7d24..48456239dc 100644 --- a/plugins/LanguagesManager/tests/Integration/LanguagesManagerTest.php +++ b/plugins/LanguagesManager/tests/Integration/LanguagesManagerTest.php @@ -107,7 +107,7 @@ class LanguagesManagerTest extends \PHPUnit\Framework\TestCase $translationWriter->saveTemporary(); $this->markTestSkipped(implode("\n", $translationWriter->getFilterMessages()) . "\n" . 'Translation file errors detected in ' . $language . "...\n" - . "To synchronise the language files with the english strings, you can manually edit the language files or run the following command may work if you have access to Transifex: \n" + . "To synchronise the language files with the english strings, you can manually edit the language files or run the following command may work if you have access to Weblate: \n" . "$ ./console translations:update [--plugin=XYZ] \n" ); } |