Added translator and translations to ResolveUrlCommand

This commit is contained in:
Alejandro Celaya 2016-07-21 16:01:16 +02:00
parent 6a05265a48
commit 73a35a8f44
3 changed files with 51 additions and 15 deletions

Binary file not shown.

View file

@ -1,8 +1,8 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Shlink 1.0\n" "Project-Id-Version: Shlink 1.0\n"
"POT-Creation-Date: 2016-07-21 15:48+0200\n" "POT-Creation-Date: 2016-07-21 15:54+0200\n"
"PO-Revision-Date: 2016-07-21 15:49+0200\n" "PO-Revision-Date: 2016-07-21 15:56+0200\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: es_ES\n" "Language: es_ES\n"
@ -112,3 +112,24 @@ msgstr "Dirección localizada en \"%s\""
msgid "Finished processing all IPs" msgid "Finished processing all IPs"
msgstr "Finalizado el procesado de todas las IPs" msgstr "Finalizado el procesado de todas las IPs"
msgid "Returns the long URL behind a short code"
msgstr "Devuelve la URL larga detrás de un código corto"
msgid "The short code to parse"
msgstr "El código corto a convertir"
msgid "A short code was not provided. Which short code do you want to parse?:"
msgstr ""
"No se proporcionó un código corto. ¿Qué código corto quieres convertir?"
#, php-format
msgid "No URL found for short code \"%s\""
msgstr "No se ha encontrado ninguna URL para el código corto \"%s\""
msgid "Long URL:"
msgstr "URL larga:"
#, php-format
msgid "Provided short code \"%s\" has an invalid format."
msgstr "El código corto proporcionado \"%s\" tiene un formato inválido."

View file

@ -11,6 +11,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Question\Question;
use Zend\I18n\Translator\TranslatorInterface;
class ResolveUrlCommand extends Command class ResolveUrlCommand extends Command
{ {
@ -18,24 +19,34 @@ class ResolveUrlCommand extends Command
* @var UrlShortenerInterface * @var UrlShortenerInterface
*/ */
private $urlShortener; private $urlShortener;
/**
* @var TranslatorInterface
*/
private $translator;
/** /**
* ResolveUrlCommand constructor. * ResolveUrlCommand constructor.
* @param UrlShortenerInterface|UrlShortener $urlShortener * @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)
{ {
parent::__construct(null);
$this->urlShortener = $urlShortener; $this->urlShortener = $urlShortener;
$this->translator = $translator;
parent::__construct(null);
} }
public function configure() public function configure()
{ {
$this->setName('shortcode:parse') $this->setName('shortcode:parse')
->setDescription('Returns the long URL behind a short code') ->setDescription($this->translator->translate('Returns the long URL behind a short code'))
->addArgument('shortCode', InputArgument::REQUIRED, 'The short code to parse'); ->addArgument(
'shortCode',
InputArgument::REQUIRED,
$this->translator->translate('The short code to parse')
);
} }
public function interact(InputInterface $input, OutputInterface $output) public function interact(InputInterface $input, OutputInterface $output)
@ -47,9 +58,10 @@ class ResolveUrlCommand extends Command
/** @var QuestionHelper $helper */ /** @var QuestionHelper $helper */
$helper = $this->getHelper('question'); $helper = $this->getHelper('question');
$question = new Question( $question = new Question(sprintf(
'<question>A short code was not provided. Which short code do you want to parse?:</question> ' '<question>%s</question> ',
); $this->translator->translate('A short code was not provided. Which short code do you want to parse?:')
));
$shortCode = $helper->ask($input, $output, $question); $shortCode = $helper->ask($input, $output, $question);
if (! empty($shortCode)) { if (! empty($shortCode)) {
@ -64,15 +76,18 @@ class ResolveUrlCommand extends Command
try { try {
$longUrl = $this->urlShortener->shortCodeToUrl($shortCode); $longUrl = $this->urlShortener->shortCodeToUrl($shortCode);
if (! isset($longUrl)) { if (! isset($longUrl)) {
$output->writeln(sprintf('<error>No URL found for short code "%s"</error>', $shortCode)); $output->writeln(sprintf(
'<error>' . $this->translator->translate('No URL found for short code "%s"') . '</error>',
$shortCode
));
return; return;
} }
$output->writeln(sprintf('Long URL <info>%s</info>', $longUrl)); $output->writeln(sprintf('%s <info>%s</info>', $this->translator->translate('Long URL:'), $longUrl));
} catch (InvalidShortCodeException $e) { } catch (InvalidShortCodeException $e) {
$output->writeln( $output->writeln(sprintf('<error>' . $this->translator->translate(
sprintf('<error>Provided short code "%s" has an invalid format.</error>', $shortCode) 'Provided short code "%s" has an invalid format.'
); ) . '</error>', $shortCode));
} }
} }
} }