public function importMessagesForTesting()
 {
     foreach ($this->messagesForTesting as $languageCode => $categories) {
         foreach ($categories as $category => $messages) {
             ZurmoMessageSourceUtil::importMessagesArray($languageCode, $category, $messages);
         }
     }
 }
 public function testImportPoFile()
 {
     $testLanguageCode = 'po';
     $pathToFiles = Yii::getPathOfAlias('application.tests.unit.files');
     $filePath = $pathToFiles . DIRECTORY_SEPARATOR . 'messages-test.po';
     ZurmoMessageSourceUtil::importPoFile($testLanguageCode, $filePath);
     $file = new ZurmoGettextPoFile($filePath);
     $messages = $file->read($filePath);
     $messageSource = new ZurmoMessageSource();
     foreach ($messages as $message) {
         $translation = $messageSource->translate($message['msgctxt'], $message['msgid'], $testLanguageCode);
         $this->assertEquals($translation, $message['msgstr']);
     }
 }
예제 #3
0
 /**
  * Updates a language
  */
 public function updateLanguage($languageCode)
 {
     try {
         $language = ActiveLanguage::getByCode($languageCode);
     } catch (NotFoundException $e) {
         throw new NotFoundException(Zurmo::t('ZurmoModule', 'Language not active.'));
     }
     $translationUrl = ZurmoTranslationServerUtil::getPoFileUrl($language->code);
     // 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($language->code, $translationUrl)) {
         $language->lastUpdateDatetime = DateTimeUtil::convertTimestampToDbFormatDateTime(time());
         if ($language->save()) {
             return true;
         }
     }
     throw new FailedServiceException(Zurmo::t('ZurmoModule', 'Unexpected error. Please try again later.'));
 }