baseTranslations = $baseTranslations; } /** * Validates the given translations * * There need to be more than 250 translations present * * Locale and TranslatorName needs to be set in plugin General * * Locale must be valid (format, language & country) * * @param array $translations * * @return boolean */ public function isValid($translations) { $this->message = null; if (empty($translations['General']['Locale'])) { $this->message = self::ERRORSTATE_LOCALEREQUIRED; return false; } if (empty($translations['General']['TranslatorName'])) { $this->message = self::ERRORSTATE_TRANSLATORINFOREQUIRED; return false; } /** @var LanguageDataProvider $languageDataProvider */ $languageDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider'); /** @var RegionDataProvider $regionDataProvider */ $regionDataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\RegionDataProvider'); $allLanguages = $languageDataProvider->getLanguageList(); $allCountries = $regionDataProvider->getCountryList(); if (!preg_match('/^([a-z]{2})_([A-Z]{2})\.UTF-8$/', $translations['General']['Locale'], $matches)) { $this->message = self::ERRORSTATE_LOCALEINVALID; return false; } else if (!array_key_exists($matches[1], $allLanguages)) { $this->message = self::ERRORSTATE_LOCALEINVALIDLANGUAGE; return false; } else if (!array_key_exists(strtolower($matches[2]), $allCountries)) { $this->message = self::ERRORSTATE_LOCALEINVALIDCOUNTRY; return false; } return true; } }