From 310be9832c07959c70020e5ac5e36a41b928f289 Mon Sep 17 00:00:00 2001 From: sgiehl Date: Mon, 22 Jun 2015 12:16:00 +0200 Subject: [PATCH] ensure all languages have Intl translations, otherwise do not use them --- plugins/LanguagesManager/API.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php index bddfaff4508..46afc357c2b 100644 --- a/plugins/LanguagesManager/API.php +++ b/plugins/LanguagesManager/API.php @@ -128,6 +128,12 @@ public function getAvailableLanguagesInfo() } return $res; }; + + // Skip languages not having Intl translations + if (empty($translations['Intl'])) { + continue; + } + $translationStringsDone = $intersect($englishTranslation, $translations); $percentageComplete = count($translationStringsDone, COUNT_RECURSIVE) / count($englishTranslation, COUNT_RECURSIVE); $percentageComplete = round(100 * $percentageComplete, 0); @@ -282,13 +288,19 @@ private function loadAvailableLanguages() if ($cache->contains($cacheId)) { $languagesInfo = $cache->fetch($cacheId); } else { - $filenames = $this->getAvailableLanguages(); + $languages = $this->getAvailableLanguages(); $languagesInfo = array(); - foreach ($filenames as $filename) { - $data = file_get_contents(PIWIK_INCLUDE_PATH . "/plugins/Intl/lang/$filename.json"); + foreach ($languages as $languageCode) { + $data = @file_get_contents(PIWIK_INCLUDE_PATH . "/plugins/Intl/lang/$languageCode.json"); + + // Skip languages not having Intl translations + if (empty($data)) { + continue; + } + $translations = json_decode($data, true); $languagesInfo[] = array( - 'code' => $filename, + 'code' => $languageCode, 'name' => $translations['Intl']['OriginalLanguageName'], 'english_name' => $translations['Intl']['EnglishLanguageName'] );