public function activateLanguagesForTesting()
 {
     $supportedLanguages = $this->getSupportedLanguagesData();
     foreach ($this->languageCodeArrayForTesting as $languageCode) {
         // Check if the language is supported
         if (!array_key_exists($languageCode, $supportedLanguages)) {
             throw new NotFoundException(Zurmo::t('ZurmoModule', 'Language not supported.'));
         }
         $language = new ActiveLanguage();
         $language->code = $supportedLanguages[$languageCode]['code'];
         $language->name = $supportedLanguages[$languageCode]['name'];
         $language->nativeName = $supportedLanguages[$languageCode]['nativeName'];
         $language->activationDatetime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         $language->lastUpdateDatetime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         $language->save();
     }
 }
Exemplo n.º 2
0
 /**
  * Activates a language
  */
 public function activateLanguage($languageCode)
 {
     $activeLanguages = $this->getActiveLanguagesData();
     // Check if the language is already active
     if (array_key_exists($languageCode, $activeLanguages)) {
         return true;
     }
     $supportedLanguages = $this->getSupportedLanguagesData();
     // Check if the language is supported
     if (!array_key_exists($languageCode, $supportedLanguages)) {
         throw new NotFoundException(Zurmo::t('ZurmoModule', 'Language not supported.'));
     }
     $translationUrl = ZurmoTranslationServerUtil::getPoFileUrl($languageCode);
     // Check if the po file exists
     $headers = get_headers($translationUrl);
     list($version, $status_code, $msg) = explode(' ', $headers[0], 3);
     if ($status_code != 200) {
         throw new NotFoundException(Zurmo::t('ZurmoModule', 'Translation not available.'));
     }
     if (ZurmoMessageSourceUtil::importPoFile($languageCode, $translationUrl)) {
         $language = new ActiveLanguage();
         $language->code = $supportedLanguages[$languageCode]['code'];
         $language->name = $supportedLanguages[$languageCode]['name'];
         $language->nativeName = $supportedLanguages[$languageCode]['nativeName'];
         $language->activationDatetime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         $language->lastUpdateDatetime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         if ($language->save()) {
             return true;
         }
     }
     throw new FailedServiceException(Zurmo::t('ZurmoModule', 'Unexpected error. Please try again later.'));
 }