diff --git a/module/Rest/lang/es.mo b/module/Rest/lang/es.mo new file mode 100644 index 00000000..2a8d4431 Binary files /dev/null and b/module/Rest/lang/es.mo differ diff --git a/module/Rest/lang/es.po b/module/Rest/lang/es.po new file mode 100644 index 00000000..fdfb2ed5 --- /dev/null +++ b/module/Rest/lang/es.po @@ -0,0 +1,60 @@ +msgid "" +msgstr "" +"Project-Id-Version: Shlink 1.0\n" +"POT-Creation-Date: 2016-07-21 16:39+0200\n" +"PO-Revision-Date: 2016-07-21 16:40+0200\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es_ES\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 1.8.7.1\n" +"X-Poedit-Basepath: ..\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: translate;translatePlural\n" +"X-Poedit-SearchPath-0: config\n" +"X-Poedit-SearchPath-1: src\n" + +msgid "You have to provide both \"username\" and \"password\"" +msgstr "Debes proporcionar tanto \"username\" como \"password\"" + +msgid "Invalid username and/or password" +msgstr "Usuario y/o contraseña no válidos" + +msgid "A URL was not provided" +msgstr "No se ha proporcionado una URL" + +#, php-format +msgid "Provided URL \"%s\" is invalid. Try with a different one." +msgstr "" +"La URL \"%s\" proporcionada es inválida. Inténtalo de nuevo con una " +"diferente." + +msgid "Unexpected error occurred" +msgstr "Ocurrió un error inesperado" + +#, php-format +msgid "Provided short code \"%s\" is invalid" +msgstr "El código corto \"%s\" proporcionado es inválido" + +#, php-format +msgid "No URL found for shortcode \"%s\"" +msgstr "No se ha encontrado una URL para el código corto \"%s\"" + +#, php-format +msgid "Provided short code \"%s\" has an invalid format" +msgstr "El código corto proporcionado \"%s\" tiene un formato no inválido" + +#, php-format +msgid "" +"Missing or invalid auth token provided. Perform a new authentication request " +"and send provided token on every new request on the \"%s\" header" +msgstr "" +"No se ha proporcionado token de autenticación o este es inválido. Realia una " +"nueva petición de autenticación y envía el token proporcionado en cada nueva " +"petición en la cabecera \"%s\"" + +#~ msgid "RestToken not found for token \"%s\"" +#~ msgstr "No se ha encontrado un RestToken para el token \"%s\"" diff --git a/module/Rest/src/Action/AuthenticateMiddleware.php b/module/Rest/src/Action/AuthenticateMiddleware.php index cbea1360..1a37ea90 100644 --- a/module/Rest/src/Action/AuthenticateMiddleware.php +++ b/module/Rest/src/Action/AuthenticateMiddleware.php @@ -9,6 +9,7 @@ use Shlinkio\Shlink\Rest\Service\RestTokenService; use Shlinkio\Shlink\Rest\Service\RestTokenServiceInterface; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; +use Zend\I18n\Translator\TranslatorInterface; class AuthenticateMiddleware extends AbstractRestMiddleware { @@ -16,16 +17,22 @@ class AuthenticateMiddleware extends AbstractRestMiddleware * @var RestTokenServiceInterface */ private $restTokenService; + /** + * @var TranslatorInterface + */ + private $translator; /** * AuthenticateMiddleware constructor. * @param RestTokenServiceInterface|RestTokenService $restTokenService + * @param TranslatorInterface $translator * - * @Inject({RestTokenService::class}) + * @Inject({RestTokenService::class, "translator"}) */ - public function __construct(RestTokenServiceInterface $restTokenService) + public function __construct(RestTokenServiceInterface $restTokenService, TranslatorInterface $translator) { $this->restTokenService = $restTokenService; + $this->translator = $translator; } /** @@ -40,7 +47,7 @@ class AuthenticateMiddleware extends AbstractRestMiddleware if (! isset($authData['username'], $authData['password'])) { return new JsonResponse([ 'error' => RestUtils::INVALID_ARGUMENT_ERROR, - 'message' => 'You have to provide both "username" and "password"' + 'message' => $this->translator->translate('You have to provide both "username" and "password"'), ], 400); } @@ -50,7 +57,7 @@ class AuthenticateMiddleware extends AbstractRestMiddleware } catch (AuthenticationException $e) { return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => 'Invalid username and/or password', + 'message' => $this->translator->translate('Invalid username and/or password'), ], 401); } } diff --git a/module/Rest/src/Action/CreateShortcodeMiddleware.php b/module/Rest/src/Action/CreateShortcodeMiddleware.php index fdb0ade3..fe3074fa 100644 --- a/module/Rest/src/Action/CreateShortcodeMiddleware.php +++ b/module/Rest/src/Action/CreateShortcodeMiddleware.php @@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; use Zend\Diactoros\Uri; +use Zend\I18n\Translator\TranslatorInterface; class CreateShortcodeMiddleware extends AbstractRestMiddleware { @@ -21,18 +22,27 @@ class CreateShortcodeMiddleware extends AbstractRestMiddleware * @var array */ private $domainConfig; + /** + * @var TranslatorInterface + */ + private $translator; /** * GenerateShortcodeMiddleware constructor. * * @param UrlShortenerInterface|UrlShortener $urlShortener + * @param TranslatorInterface $translator * @param array $domainConfig * - * @Inject({UrlShortener::class, "config.url_shortener.domain"}) + * @Inject({UrlShortener::class, "translator", "config.url_shortener.domain"}) */ - public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig) - { + public function __construct( + UrlShortenerInterface $urlShortener, + TranslatorInterface $translator, + array $domainConfig + ) { $this->urlShortener = $urlShortener; + $this->translator = $translator; $this->domainConfig = $domainConfig; } @@ -48,7 +58,7 @@ class CreateShortcodeMiddleware extends AbstractRestMiddleware if (! isset($postData['longUrl'])) { return new JsonResponse([ 'error' => RestUtils::INVALID_ARGUMENT_ERROR, - 'message' => 'A URL was not provided', + 'message' => $this->translator->translate('A URL was not provided'), ], 400); } $longUrl = $postData['longUrl']; @@ -67,12 +77,15 @@ class CreateShortcodeMiddleware extends AbstractRestMiddleware } catch (InvalidUrlException $e) { return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => sprintf('Provided URL "%s" is invalid. Try with a different one.', $longUrl), + 'message' => sprintf( + $this->translator->translate('Provided URL "%s" is invalid. Try with a different one.'), + $longUrl + ), ], 400); } catch (\Exception $e) { return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, - 'message' => 'Unexpected error occured', + 'message' => $this->translator->translate('Unexpected error occurred'), ], 500); } } diff --git a/module/Rest/src/Action/GetVisitsMiddleware.php b/module/Rest/src/Action/GetVisitsMiddleware.php index 3e5bfbaf..75765389 100644 --- a/module/Rest/src/Action/GetVisitsMiddleware.php +++ b/module/Rest/src/Action/GetVisitsMiddleware.php @@ -10,6 +10,7 @@ use Shlinkio\Shlink\Core\Service\VisitsTracker; use Shlinkio\Shlink\Core\Service\VisitsTrackerInterface; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; +use Zend\I18n\Translator\TranslatorInterface; class GetVisitsMiddleware extends AbstractRestMiddleware { @@ -17,16 +18,22 @@ class GetVisitsMiddleware extends AbstractRestMiddleware * @var VisitsTrackerInterface */ private $visitsTracker; + /** + * @var TranslatorInterface + */ + private $translator; /** * GetVisitsMiddleware constructor. * @param VisitsTrackerInterface|VisitsTracker $visitsTracker + * @param TranslatorInterface $translator * - * @Inject({VisitsTracker::class}) + * @Inject({VisitsTracker::class, "translator"}) */ - public function __construct(VisitsTrackerInterface $visitsTracker) + public function __construct(VisitsTrackerInterface $visitsTracker, TranslatorInterface $translator) { $this->visitsTracker = $visitsTracker; + $this->translator = $translator; } /** @@ -52,12 +59,12 @@ class GetVisitsMiddleware extends AbstractRestMiddleware } catch (InvalidArgumentException $e) { return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => sprintf('Provided short code "%s" is invalid', $shortCode), + 'message' => sprintf($this->translator->translate('Provided short code "%s" is invalid'), $shortCode), ], 400); } catch (\Exception $e) { return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, - 'message' => 'Unexpected error occured', + 'message' => $this->translator->translate('Unexpected error occurred'), ], 500); } } diff --git a/module/Rest/src/Action/ListShortcodesMiddleware.php b/module/Rest/src/Action/ListShortcodesMiddleware.php index 4361ab89..99b1c718 100644 --- a/module/Rest/src/Action/ListShortcodesMiddleware.php +++ b/module/Rest/src/Action/ListShortcodesMiddleware.php @@ -9,6 +9,7 @@ use Shlinkio\Shlink\Core\Service\ShortUrlService; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; +use Zend\I18n\Translator\TranslatorInterface; class ListShortcodesMiddleware extends AbstractRestMiddleware { @@ -18,16 +19,22 @@ class ListShortcodesMiddleware extends AbstractRestMiddleware * @var ShortUrlServiceInterface */ private $shortUrlService; + /** + * @var TranslatorInterface + */ + private $translator; /** * ListShortcodesMiddleware constructor. * @param ShortUrlServiceInterface|ShortUrlService $shortUrlService + * @param TranslatorInterface $translator * - * @Inject({ShortUrlService::class}) + * @Inject({ShortUrlService::class, "translator"}) */ - public function __construct(ShortUrlServiceInterface $shortUrlService) + public function __construct(ShortUrlServiceInterface $shortUrlService, TranslatorInterface $translator) { $this->shortUrlService = $shortUrlService; + $this->translator = $translator; } /** @@ -45,7 +52,7 @@ class ListShortcodesMiddleware extends AbstractRestMiddleware } catch (\Exception $e) { return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, - 'message' => 'Unexpected error occured', + 'message' => $this->translator->translate('Unexpected error occurred'), ], 500); } } diff --git a/module/Rest/src/Action/ResolveUrlMiddleware.php b/module/Rest/src/Action/ResolveUrlMiddleware.php index 92a1e5c2..db7e5827 100644 --- a/module/Rest/src/Action/ResolveUrlMiddleware.php +++ b/module/Rest/src/Action/ResolveUrlMiddleware.php @@ -9,6 +9,7 @@ use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortenerInterface; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; +use Zend\I18n\Translator\TranslatorInterface; class ResolveUrlMiddleware extends AbstractRestMiddleware { @@ -16,16 +17,22 @@ class ResolveUrlMiddleware extends AbstractRestMiddleware * @var UrlShortenerInterface */ private $urlShortener; + /** + * @var TranslatorInterface + */ + private $translator; /** * ResolveUrlMiddleware constructor. * @param UrlShortenerInterface|UrlShortener $urlShortener + * @param TranslatorInterface $translator * - * @Inject({UrlShortener::class}) + * @Inject({UrlShortener::class, "translator"}) */ - public function __construct(UrlShortenerInterface $urlShortener) + public function __construct(UrlShortenerInterface $urlShortener, TranslatorInterface $translator) { $this->urlShortener = $urlShortener; + $this->translator = $translator; } /** @@ -43,7 +50,7 @@ class ResolveUrlMiddleware extends AbstractRestMiddleware if (! isset($longUrl)) { return new JsonResponse([ 'error' => RestUtils::INVALID_ARGUMENT_ERROR, - 'message' => sprintf('No URL found for shortcode "%s"', $shortCode), + 'message' => sprintf($this->translator->translate('No URL found for shortcode "%s"'), $shortCode), ], 400); } @@ -53,12 +60,15 @@ class ResolveUrlMiddleware extends AbstractRestMiddleware } catch (InvalidShortCodeException $e) { return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), - 'message' => sprintf('Provided short code "%s" has an invalid format', $shortCode), + 'message' => sprintf( + $this->translator->translate('Provided short code "%s" has an invalid format'), + $shortCode + ), ], 400); } catch (\Exception $e) { return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, - 'message' => 'Unexpected error occured', + 'message' => $this->translator->translate('Unexpected error occurred'), ], 500); } } diff --git a/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php b/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php index 9120e2c6..f05c1b78 100644 --- a/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php +++ b/module/Rest/src/Middleware/CheckAuthenticationMiddleware.php @@ -10,6 +10,7 @@ use Shlinkio\Shlink\Rest\Service\RestTokenServiceInterface; use Shlinkio\Shlink\Rest\Util\RestUtils; use Zend\Diactoros\Response\JsonResponse; use Zend\Expressive\Router\RouteResult; +use Zend\I18n\Translator\TranslatorInterface; use Zend\Stratigility\MiddlewareInterface; class CheckAuthenticationMiddleware implements MiddlewareInterface @@ -20,16 +21,22 @@ class CheckAuthenticationMiddleware implements MiddlewareInterface * @var RestTokenServiceInterface */ private $restTokenService; + /** + * @var TranslatorInterface + */ + private $translator; /** * CheckAuthenticationMiddleware constructor. * @param RestTokenServiceInterface|RestTokenService $restTokenService + * @param TranslatorInterface $translator * - * @Inject({RestTokenService::class}) + * @Inject({RestTokenService::class, "translator"}) */ - public function __construct(RestTokenServiceInterface $restTokenService) + public function __construct(RestTokenServiceInterface $restTokenService, TranslatorInterface $translator) { $this->restTokenService = $restTokenService; + $this->translator = $translator; } /** @@ -93,8 +100,10 @@ class CheckAuthenticationMiddleware implements MiddlewareInterface return new JsonResponse([ 'error' => RestUtils::INVALID_AUTH_TOKEN_ERROR, 'message' => sprintf( - 'Missing or invalid auth token provided. Perform a new authentication request and send provided token ' - . 'on every new request on the "%s" header', + $this->translator->translate( + 'Missing or invalid auth token provided. Perform a new authentication request and send provided ' + . 'token on every new request on the "%s" header' + ), self::AUTH_TOKEN_HEADER ), ], 401); diff --git a/module/Rest/src/Service/RestTokenService.php b/module/Rest/src/Service/RestTokenService.php index c452af2a..b9dd4a9d 100644 --- a/module/Rest/src/Service/RestTokenService.php +++ b/module/Rest/src/Service/RestTokenService.php @@ -21,8 +21,8 @@ class RestTokenService implements RestTokenServiceInterface /** * ShortUrlService constructor. * @param EntityManagerInterface $em - * * @param array $restConfig + * * @Inject({"em", "config.rest"}) */ public function __construct(EntityManagerInterface $em, array $restConfig) diff --git a/module/Rest/src/Util/RestUtils.php b/module/Rest/src/Util/RestUtils.php index 82082dcd..8e50a1cf 100644 --- a/module/Rest/src/Util/RestUtils.php +++ b/module/Rest/src/Util/RestUtils.php @@ -21,7 +21,7 @@ class RestUtils return self::INVALID_SHORTCODE_ERROR; case $e instanceof Core\InvalidUrlException: return self::INVALID_URL_ERROR; - case $e instanceof Core\InvalidArgumentException: + case $e instanceof Common\InvalidArgumentException: return self::INVALID_ARGUMENT_ERROR; case $e instanceof Rest\AuthenticationException: return self::INVALID_CREDENTIALS_ERROR;