You are here

class LingotekInterfaceTranslationController in Lingotek Translation 3.2.x

Same name and namespace in other branches
  1. 4.0.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController
  2. 3.3.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController
  3. 3.4.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController
  4. 3.5.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController
  5. 3.6.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController
  6. 3.7.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController
  7. 3.8.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController

Hierarchy

Expanded class hierarchy of LingotekInterfaceTranslationController

File

src/Controller/LingotekInterfaceTranslationController.php, line 20

Namespace

Drupal\lingotek\Controller
View source
class LingotekInterfaceTranslationController extends LingotekControllerBase {

  /**
   * The Lingotek interface translation service.
   *
   * @var \Drupal\lingotek\LingotekInterfaceTranslationServiceInterface
   */
  protected $lingotekInterfaceTranslation;

  /**
   * Constructs a LingotekManagementController object.
   *
   * @param \Symfony\Component\HttpFoundation\Request $request
   *   The Request instance.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The factory for configuration objects.
   * @param \Drupal\lingotek\LingotekInterface $lingotek
   *   The lingotek service.
   * @param \Drupal\lingotek\LanguageLocaleMapperInterface $language_locale_mapper
   *   The language-locale mapper.
   * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
   *   The form builder.
   * @param \Psr\Log\LoggerInterface $logger
   *   A logger instance.
   * @param \Drupal\lingotek\LingotekInterfaceTranslationServiceInterface $lingotek_interface_translation
   *   The Lingotek interface translation service.
   */
  public function __construct(Request $request, ConfigFactoryInterface $config_factory, LingotekInterface $lingotek, LanguageLocaleMapperInterface $language_locale_mapper, FormBuilderInterface $form_builder, LoggerInterface $logger, LingotekInterfaceTranslationServiceInterface $lingotek_interface_translation) {
    parent::__construct($request, $config_factory, $lingotek, $language_locale_mapper, $form_builder, $logger);
    $this->lingotekInterfaceTranslation = $lingotek_interface_translation;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('request_stack')
      ->getCurrentRequest(), $container
      ->get('config.factory'), $container
      ->get('lingotek'), $container
      ->get('lingotek.language_locale_mapper'), $container
      ->get('form_builder'), $container
      ->get('logger.channel.lingotek'), $container
      ->get('lingotek.interface_translation'));
  }
  public function upload(Request $request) {
    $component = $request->query
      ->get('component');
    if ($component) {

      // It is not a config entity, but a config object.
      if ($this->lingotekInterfaceTranslation
        ->getDocumentId($component)) {
        return $this
          ->update($component);
      }
      else {
        try {
          if ($this->lingotekInterfaceTranslation
            ->uploadDocument($component)) {
            $this
              ->messenger()
              ->addStatus($this
              ->t('%label uploaded successfully', [
              '%label' => $component,
            ]));
          }
        } catch (LingotekDocumentArchivedException $exception) {
          $this
            ->messenger()
            ->addError($this
            ->t('Document %label has been archived. Please upload again.', [
            '%label' => $component,
          ]));
        } catch (LingotekDocumentLockedException $exception) {
          $this
            ->messenger()
            ->addError($this
            ->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
            '%label' => $component,
          ]));
        } catch (LingotekPaymentRequiredException $exception) {
          $this
            ->messenger()
            ->addError($this
            ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
        } catch (LingotekApiException $e) {

          // Mark the document as failed.
          $this
            ->messenger()
            ->addError($this
            ->t('The upload for %label failed. Please try again.', [
            '%label' => $component,
          ]));
        }
      }
    }
    return new RedirectResponse($request
      ->getRequestUri());
  }
  public function update(Request $request) {
    $component = $request->query
      ->get('component');
    if ($component) {
      try {
        if ($this->lingotekInterfaceTranslation
          ->updateDocument($component)) {
          $this
            ->messenger()
            ->addStatus($this
            ->t('%label has been updated.', [
            '%label' => $component,
          ]));
        }
      } catch (LingotekDocumentArchivedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has been archived. Please upload again.', [
          '%label' => $component,
        ]));
      } catch (LingotekDocumentLockedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
          '%label' => $component,
        ]));
      } catch (LingotekPaymentRequiredException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('%label update failed. Please try again.', [
          '%label' => $component,
        ]));
      }
    }
    return new RedirectResponse($request
      ->getRequestUri());
  }
  public function checkUpload(Request $request) {
    $component = $request->query
      ->get('component');
    if ($component) {
      try {
        if ($this->lingotekInterfaceTranslation
          ->checkSourceStatus($component)) {
          $this
            ->messenger()
            ->addStatus($this
            ->t('The import for %label is complete.', [
            '%label' => $component,
          ]));
        }
        else {
          $this
            ->messenger()
            ->addStatus($this
            ->t('The import for %label is still pending.', [
            '%label' => $component,
          ]));
        }
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t('%label status check failed. Please try again.', [
          '%label' => $component,
        ]));
      }
    }
    return new RedirectResponse($request
      ->getRequestUri());
  }
  public function requestTranslation(Request $request) {
    $component = $request->query
      ->get('component');
    $locale = $request->query
      ->get('locale');
    if ($component && $locale) {
      try {
        if ($this->lingotekInterfaceTranslation
          ->addTarget($component, $locale)) {
          $this
            ->messenger()
            ->addStatus($this
            ->t("Locale '@locale' was added as a translation target for %label.", [
            '@locale' => $locale,
            '%label' => $component,
          ]));
        }
        else {
          $this
            ->messenger()
            ->addWarning($this
            ->t("There was a problem adding '@locale' as a translation target for %label.", [
            '@locale' => $locale,
            '%label' => $component,
          ]));
        }
      } catch (LingotekDocumentArchivedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has been archived. Please upload again.', [
          '%label' => $component,
        ]));
      } catch (LingotekDocumentLockedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
          '%label' => $component,
        ]));
      } catch (LingotekPaymentRequiredException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t("Requesting '@locale' translation for %label failed. Please try again.", [
          '%label' => $component,
          '@locale' => $locale,
        ]));
      }
    }
    return new RedirectResponse($request
      ->getRequestUri());
  }
  public function checkTranslation(Request $request) {
    $component = $request->query
      ->get('component');
    $locale = $request->query
      ->get('locale');
    if ($component && $locale) {
      $langcode = $this->languageLocaleMapper
        ->getConfigurableLanguageForLocale($locale)
        ->getId();
      try {
        if ($this->lingotekInterfaceTranslation
          ->checkTargetStatus($component, $langcode) === Lingotek::STATUS_READY) {
          $this
            ->messenger()
            ->addStatus($this
            ->t('The @locale translation for %label is ready for download.', [
            '@locale' => $locale,
            '%label' => $component,
          ]));
        }
        else {
          $this
            ->messenger()
            ->addStatus($this
            ->t('The @locale translation for %label is still in progress.', [
            '@locale' => $locale,
            '%label' => $component,
          ]));
        }
      } catch (LingotekDocumentArchivedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has been archived. Please upload again.', [
          '%label' => $component,
        ]));
      } catch (LingotekDocumentLockedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
          '%label' => $component,
        ]));
      } catch (LingotekPaymentRequiredException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t("The request for %label '@locale' translation status failed. Please try again.", [
          '%label' => $component,
          '@locale' => $locale,
        ]));
      }
    }
    return new RedirectResponse($request
      ->getRequestUri());
  }
  public function download(Request $request) {
    $component = $request->query
      ->get('component');
    $locale = $request->query
      ->get('locale');
    if ($component && $locale) {
      try {
        if ($this->lingotekInterfaceTranslation
          ->downloadDocument($component, $locale)) {
          $this
            ->messenger()
            ->addStatus($this
            ->t('The translation of %label into @locale has been downloaded.', [
            '@locale' => $locale,
            '%label' => $component,
          ]));
        }
        else {
          $this
            ->messenger()
            ->addStatus($this
            ->t("The '@locale' translation download for %label failed. Please try again.", [
            '@locale' => $locale,
            '%label' => $component,
          ]));
        }
      } catch (LingotekDocumentArchivedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has been archived. Please upload again.', [
          '%label' => $component,
        ]));
      } catch (LingotekDocumentLockedException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Document %label has a new version. The document id has been updated for all future interactions. Please try again.', [
          '%label' => $component,
        ]));
      } catch (LingotekPaymentRequiredException $exception) {
        $this
          ->messenger()
          ->addError($this
          ->t('Community has been disabled. Please contact support@lingotek.com to re-enable your community.'));
      } catch (LingotekApiException $e) {
        $this
          ->messenger()
          ->addError($this
          ->t("The '@locale' translation download for %label failed. Please try again.", [
          '%label' => $component,
          '@locale' => $locale,
        ]));
      }
    }
    return new RedirectResponse($request
      ->getRequestUri());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ControllerBase::$currentUser protected property The current user service. 1
ControllerBase::$entityFormBuilder protected property The entity form builder.
ControllerBase::$entityTypeManager protected property The entity type manager.
ControllerBase::$keyValue protected property The key-value storage. 1
ControllerBase::$languageManager protected property The language manager. 1
ControllerBase::$moduleHandler protected property The module handler. 2
ControllerBase::$stateService protected property The state service.
ControllerBase::cache protected function Returns the requested cache bin.
ControllerBase::config protected function Retrieves a configuration object.
ControllerBase::container private function Returns the service container.
ControllerBase::currentUser protected function Returns the current user. 1
ControllerBase::entityFormBuilder protected function Retrieves the entity form builder.
ControllerBase::entityTypeManager protected function Retrieves the entity type manager.
ControllerBase::formBuilder protected function Returns the form builder service. 2
ControllerBase::keyValue protected function Returns a key/value storage collection. 1
ControllerBase::languageManager protected function Returns the language manager service. 1
ControllerBase::moduleHandler protected function Returns the module handler. 2
ControllerBase::redirect protected function Returns a redirect response object for the specified route.
ControllerBase::state protected function Returns the state storage service.
LingotekControllerBase::$configFactory protected property The config factory. Overrides ControllerBase::$configFactory
LingotekControllerBase::$formBuilder protected property The form builder. Overrides ControllerBase::$formBuilder
LingotekControllerBase::$languageLocaleMapper protected property The language-locale mapper.
LingotekControllerBase::$logger protected property A logger instance.
LingotekControllerBase::$request protected property A Symfony request instance
LingotekControllerBase::connected public function Checks if site is connected to Lingotek.
LingotekInterfaceTranslationController::$lingotekInterfaceTranslation protected property The Lingotek interface translation service.
LingotekInterfaceTranslationController::checkTranslation public function
LingotekInterfaceTranslationController::checkUpload public function
LingotekInterfaceTranslationController::create public static function Instantiates a new instance of this class. Overrides LingotekControllerBase::create
LingotekInterfaceTranslationController::download public function
LingotekInterfaceTranslationController::requestTranslation public function
LingotekInterfaceTranslationController::update public function
LingotekInterfaceTranslationController::upload public function
LingotekInterfaceTranslationController::__construct public function Constructs a LingotekManagementController object. Overrides LingotekControllerBase::__construct
LingotekSetupTrait::$lingotek protected property A lingotek connector object
LingotekSetupTrait::checkSetup protected function Verify the Lingotek Translation module has been properly initialized.
LingotekSetupTrait::setupCompleted public function Checks if Lingotek module is completely set up.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.