feat: Make strings in PHP files translatable

Meaningful strings are now parsed through the getext() function and the "composer update-locales"
script now parses PHP files.

Fixes #143
This commit is contained in:
Pierre Rudloff 2018-01-26 11:37:43 +01:00
parent 9ec3194c5e
commit 986dad5100
5 changed files with 101 additions and 25 deletions

View file

@ -34,6 +34,10 @@ class VideoDownload
} else {
$this->config = Config::getInstance();
}
/*
We don't translate these exceptions because they always occur before Slim can catch them
so they will always go to the logs.
*/
if (!is_file($this->config->youtubedl)) {
throw new \Exception("Can't find youtube-dl at ".$this->config->youtubedl);
} elseif (!$this->checkCommand([$this->config->python, '--version'])) {
@ -107,7 +111,7 @@ class VideoDownload
if ($errorOutput == 'ERROR: This video is protected by a password, use the --video-password option') {
throw new PasswordException($errorOutput);
} elseif (substr($errorOutput, 0, 21) == 'ERROR: Wrong password') {
throw new \Exception('Wrong password');
throw new \Exception(_('Wrong password'));
} else {
throw new \Exception($errorOutput);
}
@ -263,7 +267,7 @@ class VideoDownload
private function getAvconvProcess(\stdClass $video, $audioBitrate, $filetype = 'mp3', $audioOnly = true)
{
if (!$this->checkCommand([$this->config->avconv, '-version'])) {
throw(new \Exception('Can\'t find avconv or ffmpeg'));
throw(new \Exception(_('Can\'t find avconv or ffmpeg.')));
}
if ($video->protocol == 'rtmp') {
@ -319,7 +323,7 @@ class VideoDownload
{
$video = $this->getJSON($url, $format, $password);
if (in_array($video->protocol, ['m3u8', 'm3u8_native'])) {
throw(new \Exception('Conversion of M3U8 files is not supported.'));
throw(new \Exception(_('Conversion of M3U8 files is not supported.')));
}
$avconvProc = $this->getAvconvProcess($video, $this->config->audioBitrate);
@ -327,7 +331,7 @@ class VideoDownload
$stream = popen($avconvProc->getCommandLine(), 'r');
if (!is_resource($stream)) {
throw new \Exception('Could not open popen stream.');
throw new \Exception(_('Could not open popen stream.'));
}
return $stream;
@ -346,7 +350,7 @@ class VideoDownload
public function getM3uStream(\stdClass $video)
{
if (!$this->checkCommand([$this->config->avconv, '-version'])) {
throw(new \Exception('Can\'t find avconv or ffmpeg'));
throw(new \Exception(_('Can\'t find avconv or ffmpeg.')));
}
$process = new Process(
@ -364,7 +368,7 @@ class VideoDownload
$stream = popen($process->getCommandLine(), 'r');
if (!is_resource($stream)) {
throw new \Exception('Could not open popen stream.');
throw new \Exception(_('Could not open popen stream.'));
}
return $stream;
@ -397,7 +401,7 @@ class VideoDownload
$stream = popen($process->getCommandLine(), 'r');
if (!is_resource($stream)) {
throw new \Exception('Could not open popen stream.');
throw new \Exception(_('Could not open popen stream.'));
}
return $stream;
@ -430,7 +434,7 @@ class VideoDownload
);
$stream = popen($process->getCommandLine(), 'r');
if (!is_resource($stream)) {
throw new \Exception('Could not open popen stream.');
throw new \Exception(_('Could not open popen stream.'));
}
return $stream;
@ -454,7 +458,7 @@ class VideoDownload
}
$stream = fopen('playlist://'.implode(';', $playlistItems).'/'.$format, 'r');
if (!is_resource($stream)) {
throw new \Exception('Could not fopen popen stream.');
throw new \Exception(_('Could not open fopen stream.'));
}
return $stream;
@ -478,7 +482,7 @@ class VideoDownload
{
$video = $this->getJSON($url, $format, $password);
if (in_array($video->protocol, ['m3u8', 'm3u8_native'])) {
throw(new \Exception('Conversion of M3U8 files is not supported.'));
throw(new \Exception(_('Conversion of M3U8 files is not supported.')));
}
$avconvProc = $this->getAvconvProcess($video, $audioBitrate, $filetype, false);
@ -486,7 +490,7 @@ class VideoDownload
$stream = popen($avconvProc->getCommandLine(), 'r');
if (!is_resource($stream)) {
throw new \Exception('Could not open popen stream.');
throw new \Exception(_('Could not open popen stream.'));
}
return $stream;