diff options
author | sgiehl <stefan@piwik.org> | 2015-06-06 01:09:03 +0300 |
---|---|---|
committer | sgiehl <stefan@piwik.org> | 2015-06-06 01:09:03 +0300 |
commit | ede0aa4dd8fef51e1cfdd0a545fa7e31b9e95359 (patch) | |
tree | 947cc049844fa040898c430367b90b0349d67a9a /plugins/LanguagesManager | |
parent | cfda78628e8296a2b580de7cf6f4f5464351ea16 (diff) |
added new plugin 'Intl' which will hold translations
Diffstat (limited to 'plugins/LanguagesManager')
-rw-r--r-- | plugins/LanguagesManager/Commands/GenerateIntl.php | 115 |
1 files changed, 0 insertions, 115 deletions
diff --git a/plugins/LanguagesManager/Commands/GenerateIntl.php b/plugins/LanguagesManager/Commands/GenerateIntl.php deleted file mode 100644 index 5b8af855bd..0000000000 --- a/plugins/LanguagesManager/Commands/GenerateIntl.php +++ /dev/null @@ -1,115 +0,0 @@ -<?php -/** - * Piwik - free/libre analytics platform - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ - -namespace Piwik\Plugins\LanguagesManager\Commands; - -use Aws\CloudFront\Exception\Exception; -use Piwik\Container\StaticContainer; -use Piwik\Filesystem; -use Piwik\Http; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -/** - * Console Command to generate Intl-data files for Piwik - * - * This script uses the master data of unicode-cldr/cldr-localenames-full repository to fetch available translations - */ -class GenerateIntl extends TranslationBase -{ - protected function configure() - { - $this->setName('translations:generate-intl-data') - ->setDescription('Generates Intl-data for Piwik'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $piwikLanguages = \Piwik\Plugins\LanguagesManager\API::getInstance()->getAvailableLanguages(); - $languageCodes = array_keys(StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider')->getLanguageList()); - $countryCodes = array_keys(StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider')->getCountryList()); - $countryCodes = array_map('strtoupper', $countryCodes); - - $languageDataUrl = 'https://raw.githubusercontent.com/unicode-cldr/cldr-localenames-full/master/main/%s/languages.json'; - $languageWritePath = Filesystem::getPathToPiwikRoot() . '/core/Intl/Data/Resources/languages/%s.json'; - - $countryDataUrl = 'https://raw.githubusercontent.com/unicode-cldr/cldr-localenames-full/master/main/%s/territories.json'; - $countryWritePath = Filesystem::getPathToPiwikRoot() . '/core/Intl/Data/Resources/countries/%s.json'; - - - foreach ($piwikLanguages AS $langCode) { - - if ($langCode == 'dev') { - continue; - } - - $requestLangCode = $langCode; - - if (substr_count($langCode, '-') == 1) { - $langCodeParts = explode('-', $langCode, 2); - $requestLangCode = sprintf('%s-%s', $langCodeParts[0], strtoupper($langCodeParts[1])); - } - - if ($langCode == 'zh-cn') { - $requestLangCode = 'zh-Hans'; - } - - if ($langCode == 'zh-tw') { - $requestLangCode = 'zh-Hant'; - } - - try { - $languageData = Http::fetchRemoteFile(sprintf($languageDataUrl, $requestLangCode)); - $languageData = json_decode($languageData, true); - $languageData = $languageData['main'][$requestLangCode]['localeDisplayNames']['languages']; - - $translations = (array) @json_decode(file_get_contents(sprintf($languageWritePath, $langCode))); - - if (empty($translations)) { - $translations = array_fill_keys($languageCodes, ''); - } - - foreach ($languageCodes AS $code) { - if (!empty($languageData[$code]) && $languageData[$code] != $code) { - $translations[$code] = $languageData[$code]; - } - } - - file_put_contents(sprintf($languageWritePath, $langCode), json_encode($translations, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); - $output->writeln('Saved language data for '.$langCode); - } catch (Exception $e) { - $output->writeln('Unable to import language data for '.$langCode); - } - - try { - $countryData = Http::fetchRemoteFile(sprintf($countryDataUrl, $requestLangCode)); - $countryData = json_decode($countryData, true); - $countryData = $countryData['main'][$requestLangCode]['localeDisplayNames']['territories']; - - $translations = (array) @json_decode(file_get_contents(sprintf($countryWritePath, $langCode))); - - if (empty($translations)) { - $translations = array_fill_keys($countryCodes, ''); - } - - foreach ($countryCodes AS $code) { - if (!empty($countryData[$code]) && $countryData[$code] != $code) { - $translations[$code] = $countryData[$code]; - } - } - - file_put_contents(sprintf($countryWritePath, $langCode), json_encode($translations, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE)); - $output->writeln('Saved country data for '.$langCode); - } catch (Exception $e) { - $output->writeln('Unable to import country data for '.$langCode); - } - - } - } -} |