public function translationAction(Request $request, Tag $tag)
    {
        $this->denyAccessUnlessGranted('ez:tags:edit' . ($tag->isSynonym() ? 'synonym' : ''));

        if (!$this->isCsrfTokenValid('eztags_admin', $request->request->get('_csrf_token'))) {
            $this->addFlashMessage('errors', 'invalid_csrf_token');

            return $this->redirectToTag($tag);
        }

        $tagUpdateStruct = $this->tagsService->newTagUpdateStruct();

        if ($request->request->has('RemoveTranslationButton')) {
            if (empty($request->request->get('Locale'))) {
                $this->addFlashMessage('errors', 'no_translation_selected');

                return $this->redirectToTag($tag);
            }

            $locales = $request->request->get('Locale');

            $newKeywords = $tag->keywords;

            foreach ($locales as $locale) {
                if (!isset($newKeywords[$locale])) {
                    $this->addFlashMessage('errors', 'no_translation', ['%locale%' => $locale]);
                } elseif ($locale === $tag->mainLanguageCode) {
                    $this->addFlashMessage('errors', 'main_translation');
                } else {
                    unset($newKeywords[$locale]);

                    $tagUpdateStruct = $this->tagsService->newTagUpdateStruct();

                    foreach ($newKeywords as $languageCode => $keyword) {
                        $tagUpdateStruct->setKeyword($keyword, $languageCode);
                    }

                    $this->tagsService->updateTag($tag, $tagUpdateStruct);

                    $this->addFlashMessage('success', 'translation_removed');
                }
            }
        } elseif ($request->request->has('UpdateMainTranslationButton')) {
            $newMainTranslation = $request->request->get('MainLocale');

            if (!in_array($newMainTranslation, $tag->languageCodes, true)) {
                $this->addFlashMessage('errors', 'no_translation', ['%locale%', $newMainTranslation]);
            } else {
                $tagUpdateStruct->mainLanguageCode = $newMainTranslation;
                $this->tagsService->updateTag($tag, $tagUpdateStruct);

                $this->addFlashMessage('success', 'main_translation_set', ['%locale%' => $newMainTranslation]);
            }
        } elseif ($request->request->has('UpdateAlwaysAvailableButton')) {
            $tagUpdateStruct->alwaysAvailable = (bool) $request->request->get('AlwaysAvailable');
            $this->tagsService->updateTag($tag, $tagUpdateStruct);

            $this->addFlashMessage('success', 'always_available_set');
        }

        return $this->redirectToTag($tag);
    }