diff --git a/classes/LocaleManager.php b/classes/LocaleManager.php index 4a34265..829e2a6 100644 --- a/classes/LocaleManager.php +++ b/classes/LocaleManager.php @@ -47,6 +47,8 @@ class LocaleManager if (isset($cookieLocale)) { $this->setLocale(new Locale($cookieLocale)); } + bindtextdomain('Alltube', __DIR__.'/../i18n/'); + textdomain('Alltube'); } /** diff --git a/classes/VideoDownload.php b/classes/VideoDownload.php index 5b17bd3..5720a82 100644 --- a/classes/VideoDownload.php +++ b/classes/VideoDownload.php @@ -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; diff --git a/composer.json b/composer.json index fe25f0b..dede8f8 100644 --- a/composer.json +++ b/composer.json @@ -84,7 +84,10 @@ }, "scripts": { "compile": "composer install --ignore-platform-reqs", - "update-locales": "tsmarty2c.php templates > i18n/template.pot", + "update-locales": [ + "tsmarty2c.php templates > i18n/template.pot", + "xgettext --omit-header -j -o i18n/template.pot classes/* controllers/*" + ], "youtube-dl": "vendor/rg3/youtube-dl/youtube_dl/__main__.py" } } diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 721da4b..b6962e2 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -113,7 +113,7 @@ class FrontController [ 'config' => $this->config, 'class' => 'index', - 'description' => 'Easily download videos from Youtube, Dailymotion, Vimeo and other websites.', + 'description' => _('Easily download videos from Youtube, Dailymotion, Vimeo and other websites.'), 'domain' => $uri->getScheme().'://'.$uri->getAuthority(), 'canonical' => $this->getCanonicalUrl($request), 'supportedLocales' => $this->localeManager->getSupportedLocales(), @@ -156,9 +156,9 @@ class FrontController [ 'extractors' => $this->download->listExtractors(), 'class' => 'extractors', - 'title' => 'Supported websites', - 'description' => 'List of all supported websites from which Alltube Download '. - 'can extract video or audio files', + 'title' => _('Supported websites'), + 'description' => _('List of all supported websites from which Alltube Download '. + 'can extract video or audio files'), 'canonical' => $this->getCanonicalUrl($request), 'locale' => $this->localeManager->getLocale(), ] @@ -182,8 +182,8 @@ class FrontController 'password.tpl', [ 'class' => 'password', - 'title' => 'Password prompt', - 'description' => 'You need a password in order to download this video with Alltube Download', + 'title' => _('Password prompt'), + 'description' => _('You need a password in order to download this video with Alltube Download'), 'canonical' => $this->getCanonicalUrl($request), 'locale' => $this->localeManager->getLocale(), ] @@ -258,11 +258,11 @@ class FrontController } else { $template = 'video.tpl'; } - $title = 'Video download'; - $description = 'Download video from '.$video->extractor_key; + $title = _('Video download'); + $description = _('Download video from ').$video->extractor_key; if (isset($video->title)) { $title = $video->title; - $description = 'Download "'.$video->title.'" from '.$video->extractor_key; + $description = _('Download').' "'.$video->title.'" '._('from').' '.$video->extractor_key; } $this->view->render( $response, @@ -325,7 +325,7 @@ class FrontController [ 'errors' => $exception->getMessage(), 'class' => 'video', - 'title' => 'Error', + 'title' => _('Error'), 'canonical' => $this->getCanonicalUrl($request), 'locale' => $this->localeManager->getLocale(), ] @@ -397,7 +397,7 @@ class FrontController private function getRemuxStream(array $urls, $format, Response $response, Request $request) { if (!$this->config->remux) { - throw new \Exception('You need to enable remux mode to merge two formats.'); + throw new \Exception(_('You need to enable remux mode to merge two formats.')); } $stream = $this->download->getRemuxStream($urls); $response = $response->withHeader('Content-Type', 'video/x-matroska'); @@ -464,7 +464,7 @@ class FrontController ); } else { if (empty($videoUrls[0])) { - throw new \Exception("Can't find URL of video"); + throw new \Exception(_("Can't find URL of video.")); } return $response->withRedirect($videoUrls[0]); diff --git a/i18n/template.pot b/i18n/template.pot index 1fe1bf1..010b9e3 100644 --- a/i18n/template.pot +++ b/i18n/template.pot @@ -19,6 +19,7 @@ msgstr "" #: templates/playlist.tpl:26 templates/password.tpl:10 templates/video.tpl:97 #: templates/video.tpl:100 templates/index.tpl:19 +#: controllers/FrontController.php:265 msgid "Download" msgstr "" @@ -38,7 +39,7 @@ msgstr "" msgid "Video password" msgstr "" -#: templates/extractors.tpl:4 +#: templates/extractors.tpl:4 controllers/FrontController.php:159 msgid "Supported websites" msgstr "" @@ -137,3 +138,69 @@ msgstr "" #: templates/index.tpl:32 msgid "Bookmarklet" msgstr "" + +#: classes/VideoDownload.php:114 +msgid "Wrong password" +msgstr "" + +#: classes/VideoDownload.php:270 classes/VideoDownload.php:353 +msgid "Can't find avconv or ffmpeg." +msgstr "" + +#: classes/VideoDownload.php:326 classes/VideoDownload.php:485 +msgid "Conversion of M3U8 files is not supported." +msgstr "" + +#: classes/VideoDownload.php:334 classes/VideoDownload.php:371 +#: classes/VideoDownload.php:404 classes/VideoDownload.php:437 +#: classes/VideoDownload.php:493 +msgid "Could not open popen stream." +msgstr "" + +#: classes/VideoDownload.php:461 +msgid "Could not open fopen stream." +msgstr "" + +#: controllers/FrontController.php:116 +msgid "" +"Easily download videos from Youtube, Dailymotion, Vimeo and other websites." +msgstr "" + +#: controllers/FrontController.php:160 +msgid "" +"List of all supported websites from which Alltube Download can extract video " +"or audio files" +msgstr "" + +#: controllers/FrontController.php:185 +msgid "Password prompt" +msgstr "" + +#: controllers/FrontController.php:186 +msgid "" +"You need a password in order to download this video with Alltube Download" +msgstr "" + +#: controllers/FrontController.php:261 +msgid "Video download" +msgstr "" + +#: controllers/FrontController.php:262 +msgid "Download video from " +msgstr "" + +#: controllers/FrontController.php:265 +msgid "from" +msgstr "" + +#: controllers/FrontController.php:328 +msgid "Error" +msgstr "" + +#: controllers/FrontController.php:400 +msgid "You need to enable remux mode to merge two formats." +msgstr "" + +#: controllers/FrontController.php:467 +msgid "Can't find URL of video." +msgstr ""