Switch to symfony/translation for translations (#250)

This commit is contained in:
Pierre Rudloff 2019-11-27 23:15:49 +01:00
parent 0b1ce90f47
commit a5bd827d21
16 changed files with 399 additions and 212 deletions

View file

@ -7,6 +7,7 @@
namespace Alltube\Controller;
use Alltube\Config;
use Alltube\LocaleManager;
use Alltube\SessionManager;
use Alltube\Video;
use Aura\Session\Segment;
@ -53,6 +54,13 @@ abstract class BaseController
*/
protected $sessionSegment;
/**
* LocaleManager instance.
*
* @var LocaleManager
*/
protected $localeManager;
/**
* BaseController constructor.
*
@ -64,6 +72,7 @@ abstract class BaseController
$this->container = $container;
$session = SessionManager::getSession();
$this->sessionSegment = $session->getSegment(self::class);
$this->localeManager = $this->container->get('locale');
if ($this->config->stream) {
$this->defaultFormat = 'best';

View file

@ -212,7 +212,7 @@ class DownloadController extends BaseController
private function getRemuxStream(Request $request, Response $response)
{
if (!$this->config->remux) {
throw new Exception(_('You need to enable remux mode to merge two formats.'));
throw new Exception($this->localeManager->t('You need to enable remux mode to merge two formats.'));
}
$stream = $this->video->getRemuxStream();
$response = $response->withHeader('Content-Type', 'video/x-matroska');
@ -252,7 +252,7 @@ class DownloadController extends BaseController
return $this->getStream($request, $response);
} else {
if (empty($videoUrls[0])) {
throw new Exception(_("Can't find URL of video."));
throw new Exception($this->localeManager->t("Can't find URL of video."));
}
return $response->withRedirect($videoUrls[0]);

View file

@ -8,7 +8,6 @@ namespace Alltube\Controller;
use Alltube\Exception\PasswordException;
use Alltube\Locale;
use Alltube\LocaleManager;
use Alltube\Video;
use Exception;
use Psr\Container\ContainerInterface;
@ -30,13 +29,6 @@ class FrontController extends BaseController
*/
private $view;
/**
* LocaleManager instance.
*
* @var LocaleManager
*/
private $localeManager;
/**
* BaseController constructor.
*
@ -46,7 +38,6 @@ class FrontController extends BaseController
{
parent::__construct($container);
$this->localeManager = $this->container->get('locale');
$this->view = $this->container->get('view');
}
@ -67,7 +58,9 @@ class FrontController extends BaseController
[
'config' => $this->config,
'class' => 'index',
'description' => _('Easily download videos from Youtube, Dailymotion, Vimeo and other websites.'),
'description' => $this->localeManager->t(
'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.'
),
'domain' => $uri->getScheme() . '://' . $uri->getAuthority(),
'canonical' => $this->getCanonicalUrl($request),
'supportedLocales' => $this->localeManager->getSupportedLocales(),
@ -111,8 +104,8 @@ class FrontController extends BaseController
'config' => $this->config,
'extractors' => Video::getExtractors(),
'class' => 'extractors',
'title' => _('Supported websites'),
'description' => _('List of all supported websites from which Alltube Download ' .
'title' => $this->localeManager->t('Supported websites'),
'description' => $this->localeManager->t('List of all supported websites from which Alltube Download ' .
'can extract video or audio files'),
'canonical' => $this->getCanonicalUrl($request),
'locale' => $this->localeManager->getLocale(),
@ -138,8 +131,10 @@ class FrontController extends BaseController
[
'config' => $this->config,
'class' => 'password',
'title' => _('Password prompt'),
'description' => _('You need a password in order to download this video with Alltube Download'),
'title' => $this->localeManager->t('Password prompt'),
'description' => $this->localeManager->t(
'You need a password in order to download this video with Alltube Download'
),
'canonical' => $this->getCanonicalUrl($request),
'locale' => $this->localeManager->getLocale(),
]
@ -169,12 +164,12 @@ class FrontController extends BaseController
} else {
$template = 'info.tpl';
}
$title = _('Video download');
$description = _('Download video from ') . $this->video->extractor_key;
$title = $this->localeManager->t('Video download');
$description = $this->localeManager->t('Download video from ') . $this->video->extractor_key;
if (isset($this->video->title)) {
$title = $this->video->title;
$description = _('Download') . ' "' . $this->video->title . '" ' .
_('from') . ' ' . $this->video->extractor_key;
$description = $this->localeManager->t('Download') . ' "' . $this->video->title . '" ' .
$this->localeManager->t('from') . ' ' . $this->video->extractor_key;
}
$this->view->render(
$response,
@ -245,7 +240,7 @@ class FrontController extends BaseController
'config' => $this->config,
'errors' => $exception->getMessage(),
'class' => 'video',
'title' => _('Error'),
'title' => $this->localeManager->t('Error'),
'canonical' => $this->getCanonicalUrl($request),
'locale' => $this->localeManager->getLocale(),
]