You are here

public function LingotekInterfaceTranslationController::requestTranslation in Lingotek Translation 3.4.x

Same name and namespace in other branches
  1. 4.0.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
  2. 3.2.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
  3. 3.3.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
  4. 3.5.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
  5. 3.6.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
  6. 3.7.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
  7. 3.8.x src/Controller/LingotekInterfaceTranslationController.php \Drupal\lingotek\Controller\LingotekInterfaceTranslationController::requestTranslation()
1 string reference to 'LingotekInterfaceTranslationController::requestTranslation'
lingotek.routing.yml in ./lingotek.routing.yml
lingotek.routing.yml

File

src/Controller/LingotekInterfaceTranslationController.php, line 146

Class

LingotekInterfaceTranslationController

Namespace

Drupal\lingotek\Controller

Code

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());
}