diff --git a/src/bundle/DependencyInjection/IbexaRestExtension.php b/src/bundle/DependencyInjection/IbexaRestExtension.php index b651ac04..7994dae4 100644 --- a/src/bundle/DependencyInjection/IbexaRestExtension.php +++ b/src/bundle/DependencyInjection/IbexaRestExtension.php @@ -58,6 +58,7 @@ public function prepend(ContainerBuilder $container) } $this->prependRouterConfiguration($container); + $this->prependJMSTranslation($container); } private function prependRouterConfiguration(ContainerBuilder $container) @@ -65,6 +66,22 @@ private function prependRouterConfiguration(ContainerBuilder $container) $config = ['router' => ['default_router' => ['non_siteaccess_aware_routes' => ['ibexa.rest.']]]]; $container->prependExtensionConfig('ibexa', $config); } + + private function prependJMSTranslation(ContainerBuilder $container): void + { + $container->prependExtensionConfig('jms_translation', [ + 'configs' => [ + 'ibexa_rest' => [ + 'dirs' => [ + __DIR__ . '/../../', + ], + 'excluded_dirs' => ['Behat', 'Tests', 'node_modules', 'Features'], + 'output_dir' => __DIR__ . '/../Resources/translations/', + 'output_format' => 'xliff', + ], + ], + ]); + } } class_alias(IbexaRestExtension::class, 'EzSystems\EzPlatformRestBundle\DependencyInjection\EzPlatformRestExtension'); diff --git a/src/bundle/Resources/translations/repository_exceptions.en.xliff b/src/bundle/Resources/translations/repository_exceptions.en.xliff new file mode 100644 index 00000000..19371e47 --- /dev/null +++ b/src/bundle/Resources/translations/repository_exceptions.en.xliff @@ -0,0 +1,81 @@ + + + +
+ + The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message. +
+ + + Cannot publish an empty Content Type draft + Cannot publish an empty Content Type draft + key: Cannot publish an empty Content Type draft + + + Cannot unlink the Content Type from its only remaining group + Cannot unlink the Content Type from its only remaining group + key: Cannot unlink the Content Type from its only remaining group + + + Current version already has DRAFT status + Current version already has DRAFT status + key: Current version already has DRAFT status + + + Only empty Content Type groups can be deleted + Only empty Content Type groups can be deleted + key: Only empty Content Type groups can be deleted + + + Only versions with DRAFT status can be published + Only versions with DRAFT status can be published + key: Only versions with DRAFT status can be published + + + Only versions with DRAFT status can be updated + Only versions with DRAFT status can be updated + key: Only versions with DRAFT status can be updated + + + Relation is not of type COMMON + Relation is not of type COMMON + key: Relation is not of type COMMON + + + Relation of type COMMON can only be added to drafts + Relation of type COMMON can only be added to drafts + key: Relation of type COMMON can only be added to drafts + + + Relation of type COMMON can only be removed from drafts + Relation of type COMMON can only be removed from drafts + key: Relation of type COMMON can only be removed from drafts + + + Relation of type COMMON to the selected destination content ID already exists + Relation of type COMMON to the selected destination content ID already exists + key: Relation of type COMMON to the selected destination content ID already exists + + + The Content Type is already linked to the provided group + The Content Type is already linked to the provided group + key: The Content Type is already linked to the provided group + + + Translation can be deleted from a DRAFT version only + Translation can be deleted from a DRAFT version only + key: Translation can be deleted from a DRAFT version only + + + Versions with PUBLISHED status cannot be deleted + Versions with PUBLISHED status cannot be deleted + key: Versions with PUBLISHED status cannot be deleted + + + An error has occurred. Please try again later or contact your Administrator. + An error has occurred. Please try again later or contact your Administrator. + key: non_verbose_error + + +
+
diff --git a/src/lib/Server/Controller/Content.php b/src/lib/Server/Controller/Content.php index 753953fe..d525fd62 100644 --- a/src/lib/Server/Controller/Content.php +++ b/src/lib/Server/Controller/Content.php @@ -20,6 +20,7 @@ use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; use Ibexa\Rest\Server\Values\RestContentCreateStruct; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -710,7 +711,7 @@ public function createRelation($contentId, $versionNumber, Request $request) try { $destinationContentInfo = $this->repository->getContentService()->loadContentInfo($destinationContentId); } catch (NotFoundException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } $existingRelations = $this->repository->getContentService()->loadRelations($versionInfo); diff --git a/src/lib/Server/Controller/ContentType.php b/src/lib/Server/Controller/ContentType.php index 21f3344c..eb5b6704 100644 --- a/src/lib/Server/Controller/ContentType.php +++ b/src/lib/Server/Controller/ContentType.php @@ -21,6 +21,7 @@ use Ibexa\Rest\Server\Exceptions\BadRequestException; use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -68,7 +69,7 @@ public function createContentTypeGroup(Request $request) ] ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } @@ -98,7 +99,7 @@ public function updateContentTypeGroup($contentTypeGroupId, Request $request) return $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId, Language::ALL); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } @@ -304,7 +305,7 @@ public function createContentType($contentTypeGroupId, Request $request) [$contentTypeGroup] ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } catch (ContentTypeValidationException $e) { throw new BadRequestException($e->getMessage()); } catch (ContentTypeFieldDefinitionValidationException $e) { @@ -378,7 +379,7 @@ public function createContentTypeDraft($contentTypeId, Request $request) $contentType ); } catch (BadStateException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } $contentTypeUpdateStruct = $this->inputDispatcher->parse( @@ -396,7 +397,7 @@ public function createContentTypeDraft($contentTypeId, Request $request) $contentTypeUpdateStruct ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\CreatedContentType( @@ -455,7 +456,7 @@ public function updateContentTypeDraft($contentTypeId, Request $request) $contentTypeUpdateStruct ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\RestContentType( @@ -494,11 +495,11 @@ public function addContentTypeDraftFieldDefinition($contentTypeId, Request $requ $fieldDefinitionCreate ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } catch (ContentTypeFieldDefinitionValidationException $e) { throw new BadRequestException($e->getMessage()); } catch (BadStateException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } $updatedDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId); @@ -678,7 +679,7 @@ public function updateContentTypeDraftFieldDefinition($contentTypeId, $fieldDefi $fieldDefinitionUpdate ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } $updatedDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId); @@ -768,7 +769,7 @@ public function deleteContentType($contentTypeId) try { $this->contentTypeService->deleteContentType($contentType); } catch (BadStateException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\NoContent(); diff --git a/src/lib/Server/Controller/Location.php b/src/lib/Server/Controller/Location.php index f0bcfcba..fbb1834e 100644 --- a/src/lib/Server/Controller/Location.php +++ b/src/lib/Server/Controller/Location.php @@ -17,6 +17,7 @@ use Ibexa\Rest\Server\Exceptions\BadRequestException; use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -125,7 +126,7 @@ public function createLocation($contentId, Request $request) try { $createdLocation = $this->locationService->createLocation($contentInfo, $locationCreateStruct); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\CreatedLocation(['restLocation' => new Values\RestLocation($createdLocation, 0)]); diff --git a/src/lib/Server/Controller/ObjectState.php b/src/lib/Server/Controller/ObjectState.php index 9ef65513..ffc15770 100644 --- a/src/lib/Server/Controller/ObjectState.php +++ b/src/lib/Server/Controller/ObjectState.php @@ -17,6 +17,7 @@ use Ibexa\Rest\Server\Values; use Ibexa\Rest\Values\ContentObjectStates; use Ibexa\Rest\Values\RestObjectState; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -69,7 +70,7 @@ public function createObjectStateGroup(Request $request) ) ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */$e->getMessage()); } return new Values\CreatedObjectStateGroup( @@ -103,7 +104,7 @@ public function createObjectState($objectStateGroupId, Request $request) ) ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\CreatedObjectState( @@ -230,7 +231,7 @@ public function updateObjectStateGroup($objectStateGroupId, Request $request) return $updatedStateGroup; } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } @@ -260,7 +261,7 @@ public function updateObjectState($objectStateGroupId, $objectStateId, Request $ return new RestObjectState($updatedObjectState, $objectStateGroupId); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } @@ -321,7 +322,10 @@ public function setObjectStatesForContent($contentId, Request $request) foreach ($countByGroups as $groupId => $count) { if ($count > 1) { - throw new ForbiddenException("Multiple Object states provided for group with ID $groupId"); + throw new ForbiddenException( + /** @Ignore */ + "Multiple Object states provided for group with ID $groupId" + ); } } diff --git a/src/lib/Server/Controller/Role.php b/src/lib/Server/Controller/Role.php index e4d93c5f..91362d74 100644 --- a/src/lib/Server/Controller/Role.php +++ b/src/lib/Server/Controller/Role.php @@ -22,6 +22,7 @@ use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions\BadRequestException; use Ibexa\Rest\Server\Values; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -95,9 +96,9 @@ public function createRole(Request $request) ) ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } catch (UnauthorizedException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } catch (LimitationValidationException $e) { throw new BadRequestException($e->getMessage()); } catch (Exceptions\Parser $e) { @@ -139,9 +140,9 @@ public function createRoleDraft($roleId, Request $request) $this->roleService->loadRole($roleId) ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } catch (UnauthorizedException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } catch (LimitationValidationException $e) { throw new BadRequestException($e->getMessage()); } catch (Exceptions\Parser $e) { diff --git a/src/lib/Server/Controller/Section.php b/src/lib/Server/Controller/Section.php index 34bb8b2d..3e153bda 100644 --- a/src/lib/Server/Controller/Section.php +++ b/src/lib/Server/Controller/Section.php @@ -89,7 +89,7 @@ public function createSection(Request $request) ) ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\CreatedSection( @@ -135,7 +135,7 @@ public function updateSection($sectionId, Request $request) $this->mapToUpdateStruct($createStruct) ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } diff --git a/src/lib/Server/Controller/Trash.php b/src/lib/Server/Controller/Trash.php index 42e4ec70..0f73cad1 100644 --- a/src/lib/Server/Controller/Trash.php +++ b/src/lib/Server/Controller/Trash.php @@ -14,6 +14,7 @@ use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; use InvalidArgumentException; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -147,7 +148,7 @@ public function restoreTrashItem($trashItemId, Request $request) try { $parentLocation = $this->locationService->loadLocation(array_pop($locationPathParts)); } catch (NotFoundException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } @@ -159,7 +160,7 @@ public function restoreTrashItem($trashItemId, Request $request) try { $this->locationService->loadLocation($trashItem->parentLocationId); } catch (NotFoundException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } diff --git a/src/lib/Server/Controller/URLAlias.php b/src/lib/Server/Controller/URLAlias.php index dd20418a..056dea65 100644 --- a/src/lib/Server/Controller/URLAlias.php +++ b/src/lib/Server/Controller/URLAlias.php @@ -13,6 +13,7 @@ use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -132,7 +133,7 @@ public function createURLAlias(Request $request) $urlAliasCreate['alwaysAvailable'] ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } else { try { @@ -144,7 +145,7 @@ public function createURLAlias(Request $request) $urlAliasCreate['alwaysAvailable'] ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } } diff --git a/src/lib/Server/Controller/URLWildcard.php b/src/lib/Server/Controller/URLWildcard.php index 391c014d..611d48b0 100644 --- a/src/lib/Server/Controller/URLWildcard.php +++ b/src/lib/Server/Controller/URLWildcard.php @@ -12,6 +12,7 @@ use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; /** @@ -83,7 +84,7 @@ public function createURLWildcard(Request $request) $urlWildcardCreate['forward'] ); } catch (InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } return new Values\CreatedURLWildcard( diff --git a/src/lib/Server/Controller/User.php b/src/lib/Server/Controller/User.php index 494da78c..2b9fd2eb 100644 --- a/src/lib/Server/Controller/User.php +++ b/src/lib/Server/Controller/User.php @@ -26,6 +26,7 @@ use Ibexa\Rest\Server\Exceptions; use Ibexa\Rest\Server\Exceptions\ForbiddenException; use Ibexa\Rest\Server\Values; +use JMS\TranslationBundle\Annotation\Ignore; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; use Symfony\Component\Security\Core\User\UserInterface; @@ -304,7 +305,7 @@ public function createUser($groupPath, Request $request) try { $createdUser = $this->userService->createUser($userCreateStruct, [$userGroup]); } catch (ApiExceptions\InvalidArgumentException $e) { - throw new ForbiddenException($e->getMessage()); + throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } $createdContentInfo = $createdUser->getVersionInfo()->getContentInfo(); diff --git a/src/lib/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php b/src/lib/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php index 2dfca06a..3e1975a0 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php +++ b/src/lib/Server/Output/ValueObjectVisitor/ContentFieldValidationException.php @@ -9,6 +9,7 @@ use Ibexa\Contracts\Core\Repository\Values\Translation; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\Visitor; +use JMS\TranslationBundle\Annotation\Ignore; /** * ContentFieldValidationException value object visitor. @@ -60,6 +61,7 @@ public function visit(Visitor $visitor, Generator $generator, $data) $generator->valueElement( 'message', $this->translator->trans( + /** @Ignore */ $this->translationToString($translation), $translation->values, 'repository_exceptions'