Add support for variables in translation (#250)

This commit is contained in:
Pierre Rudloff 2019-11-29 21:33:49 +01:00
parent 6fb1cbaa6c
commit 850fc80622
8 changed files with 145 additions and 101 deletions

View File

@ -140,7 +140,11 @@ class LocaleManager
*/ */
public function smartyTranslate(array $params, $text) public function smartyTranslate(array $params, $text)
{ {
return $this->t($text); if (isset($params['params'])) {
return $this->t($text, $params['params']);
} else {
return $this->t($text);
}
} }
/** /**
@ -150,9 +154,9 @@ class LocaleManager
* *
* @return string Translated string * @return string Translated string
*/ */
public function t($string) public function t($string, array $params = [])
{ {
return $this->translator->trans($string); return $this->translator->trans($string, $params);
} }
/** /**

View File

@ -358,8 +358,9 @@ class Video
if (!$this->checkCommand([$this->config->avconv, '-version'])) { if (!$this->checkCommand([$this->config->avconv, '-version'])) {
throw new Exception( throw new Exception(
$this->localeManager->t( $this->localeManager->t(
'Can\'t find avconv or ffmpeg at ' "Can't find avconv or ffmpeg at @path.",
) . $this->config->avconv . '.' ['@path' => $this->config->avconv]
)
); );
} }
@ -373,14 +374,14 @@ class Video
if (!empty($from)) { if (!empty($from)) {
if (!preg_match($durationRegex, $from)) { if (!preg_match($durationRegex, $from)) {
throw new Exception($this->localeManager->t('Invalid start time: ') . $from . '.'); throw new Exception($this->localeManager->t('Invalid start time: @from.', ['@from' => $from]));
} }
$afterArguments[] = '-ss'; $afterArguments[] = '-ss';
$afterArguments[] = $from; $afterArguments[] = $from;
} }
if (!empty($to)) { if (!empty($to)) {
if (!preg_match($durationRegex, $to)) { if (!preg_match($durationRegex, $to)) {
throw new Exception($this->localeManager->t('Invalid end time: ') . $to . '.'); throw new Exception($this->localeManager->t('Invalid end time: @to.', ['@to' => $to]));
} }
$afterArguments[] = '-to'; $afterArguments[] = '-to';
$afterArguments[] = $to; $afterArguments[] = $to;
@ -461,8 +462,9 @@ class Video
if (!$this->checkCommand([$this->config->avconv, '-version'])) { if (!$this->checkCommand([$this->config->avconv, '-version'])) {
throw new Exception( throw new Exception(
$this->localeManager->t( $this->localeManager->t(
'Can\'t find avconv or ffmpeg at ' "Can't find avconv or ffmpeg at @path.",
) . $this->config->avconv . '.' ['@path' => $this->config->avconv]
)
); );
} }

View File

@ -167,11 +167,19 @@ class FrontController extends BaseController
$template = 'info.tpl'; $template = 'info.tpl';
} }
$title = $this->localeManager->t('Video download'); $title = $this->localeManager->t('Video download');
$description = $this->localeManager->t('Download video from ') . $this->video->extractor_key; $description = $this->localeManager->t(
'Download video from @extractor',
['@extractor' => $this->video->extractor_key]
);
if (isset($this->video->title)) { if (isset($this->video->title)) {
$title = $this->video->title; $title = $this->video->title;
$description = $this->localeManager->t('Download') . ' "' . $this->video->title . '" ' . $description = $this->localeManager->t(
$this->localeManager->t('from') . ' ' . $this->video->extractor_key; 'Download @title from @extractor',
[
'@title' => $this->video->title,
'@extractor' => $this->video->extractor_key
]
);
} }
$this->view->render( $this->view->render(
$response, $response,

View File

@ -1,20 +1,16 @@
msgid "" msgid ""
msgstr "Content-Type: text/plain; charset=UTF-8\n" msgstr "Content-Type: text/plain; charset=UTF-8\n"
#: templates/playlist.tpl:5 #: templates/playlist.tpl:13
msgid "Videos extracted from" msgid "Videos extracted from @title:"
msgstr "" msgstr ""
#: templates/playlist.tpl:7 #: templates/playlist.tpl:38 templates/password.tpl:11 templates/index.tpl:19
msgid ":" #: templates/info.tpl:98
msgstr ""
#: templates/playlist.tpl:30 templates/password.tpl:11 templates/index.tpl:19
#: templates/info.tpl:94 controllers/FrontController.php:176
msgid "Download" msgid "Download"
msgstr "" msgstr ""
#: templates/playlist.tpl:31 #: templates/playlist.tpl:39
msgid "More options" msgid "More options"
msgstr "" msgstr ""
@ -22,39 +18,31 @@ msgstr ""
msgid "Switch language" msgid "Switch language"
msgstr "" msgstr ""
#: templates/inc/header.tpl:30 #: templates/inc/header.tpl:8
msgid "Share on Twitter" msgid "Set language"
msgstr "" msgstr ""
#: templates/inc/header.tpl:30 templates/inc/header.tpl:33 #: templates/inc/footer.tpl:8
msgid "(opens a new window)" msgid "Code by @dev"
msgstr "" msgstr ""
#: templates/inc/header.tpl:33 #: templates/inc/footer.tpl:16
msgid "Share on Facebook" msgid "Design by @designer"
msgstr "" msgstr ""
#: templates/inc/footer.tpl:4 #: templates/inc/footer.tpl:21
msgid "Code by"
msgstr ""
#: templates/inc/footer.tpl:6
msgid "Design by"
msgstr ""
#: templates/inc/footer.tpl:10
msgid "Get the code" msgid "Get the code"
msgstr "" msgstr ""
#: templates/inc/footer.tpl:12 #: templates/inc/footer.tpl:29
msgid "Based on" msgid "Based on @youtubedl"
msgstr "" msgstr ""
#: templates/inc/footer.tpl:14 #: templates/inc/footer.tpl:33
msgid "Donate using Liberapay" msgid "Donate using Liberapay"
msgstr "" msgstr ""
#: templates/inc/footer.tpl:14 #: templates/inc/footer.tpl:35
msgid "Donate" msgid "Donate"
msgstr "" msgstr ""
@ -98,43 +86,51 @@ msgstr ""
msgid "Bookmarklet" msgid "Bookmarklet"
msgstr "" msgstr ""
#: templates/info.tpl:6 #: templates/info.tpl:13
msgid "You are going to download" msgid "You are going to download @title."
msgstr "" msgstr ""
#: templates/info.tpl:27 #: templates/info.tpl:31
msgid "Available formats:" msgid "Available formats:"
msgstr "" msgstr ""
#: templates/info.tpl:29 #: templates/info.tpl:33
msgid "Generic formats" msgid "Generic formats"
msgstr "" msgstr ""
#: templates/info.tpl:34 #: templates/info.tpl:38
msgid "Detailed formats" msgid "Detailed formats"
msgstr "" msgstr ""
#: templates/info.tpl:76 #: templates/info.tpl:80
msgid "Stream the video through the server" msgid "Stream the video through the server"
msgstr "" msgstr ""
#: templates/info.tpl:81 #: templates/info.tpl:85
msgid "Convert into a custom format:" msgid "Convert into a custom format:"
msgstr "" msgstr ""
#: templates/info.tpl:82 #: templates/info.tpl:86
msgid "Custom format"
msgstr ""
#: templates/info.tpl:86
msgid "Format to convert to" msgid "Format to convert to"
msgstr "" msgstr ""
#: templates/info.tpl:87 #: templates/info.tpl:91
msgid "with" msgid "with"
msgstr "" msgstr ""
#: templates/info.tpl:88 #: templates/info.tpl:92
msgid "Bit rate" msgid "Bit rate"
msgstr "" msgstr ""
#: templates/info.tpl:91 #: templates/info.tpl:93
msgid "Custom bitrate"
msgstr ""
#: templates/info.tpl:95
msgid "kbit/s audio" msgid "kbit/s audio"
msgstr "" msgstr ""
@ -146,60 +142,60 @@ msgstr ""
msgid "Please check the URL of your video." msgid "Please check the URL of your video."
msgstr "" msgstr ""
#: templates/extractors.tpl:4 controllers/FrontController.php:114 #: templates/extractors.tpl:4 controllers/FrontController.php:109
msgid "Supported websites" msgid "Supported websites"
msgstr "" msgstr ""
#: classes/Config.php:153 #: classes/Config.php:158
msgid "Best" msgid "Best"
msgstr "" msgstr ""
#: classes/Config.php:154 #: classes/Config.php:159
msgid "Remux best video with best audio" msgid "Remux best video with best audio"
msgstr "" msgstr ""
#: classes/Config.php:155 #: classes/Config.php:160
msgid "Worst" msgid "Worst"
msgstr "" msgstr ""
#: classes/Video.php:156 #: classes/Video.php:159
msgid "Wrong password" msgid "Wrong password"
msgstr "" msgstr ""
#: classes/Video.php:247 #: classes/Video.php:250
msgid "youtube-dl returned an empty URL." msgid "youtube-dl returned an empty URL."
msgstr "" msgstr ""
#: classes/Video.php:356 classes/Video.php:455 #: classes/Video.php:361 classes/Video.php:465
msgid "Can't find avconv or ffmpeg at " msgid "Can't find avconv or ffmpeg at @path."
msgstr "" msgstr ""
#: classes/Video.php:369 #: classes/Video.php:377
msgid "Invalid start time: " msgid "Invalid start time: @from."
msgstr "" msgstr ""
#: classes/Video.php:376 #: classes/Video.php:384
msgid "Invalid end time: " msgid "Invalid end time: @to."
msgstr "" msgstr ""
#: classes/Video.php:422 #: classes/Video.php:430
msgid "Conversion of playlists is not supported." msgid "Conversion of playlists is not supported."
msgstr "" msgstr ""
#: classes/Video.php:427 classes/Video.php:565 #: classes/Video.php:435 classes/Video.php:578
msgid "Conversion of M3U8 files is not supported." msgid "Conversion of M3U8 files is not supported."
msgstr "" msgstr ""
#: classes/Video.php:429 #: classes/Video.php:437
msgid "Conversion of DASH segments is not supported." msgid "Conversion of DASH segments is not supported."
msgstr "" msgstr ""
#: classes/Video.php:438 classes/Video.php:475 classes/Video.php:512 #: classes/Video.php:446 classes/Video.php:488 classes/Video.php:525
#: classes/Video.php:545 classes/Video.php:573 #: classes/Video.php:558 classes/Video.php:586
msgid "Could not open popen stream." msgid "Could not open popen stream."
msgstr "" msgstr ""
#: classes/Video.php:493 #: classes/Video.php:506
msgid "This video does not have two URLs." msgid "This video does not have two URLs."
msgstr "" msgstr ""
@ -211,38 +207,38 @@ msgstr ""
msgid "Can't find URL of video." msgid "Can't find URL of video."
msgstr "" msgstr ""
#: controllers/FrontController.php:70 #: controllers/FrontController.php:64
msgid "" msgid ""
"Easily download videos from Youtube, Dailymotion, Vimeo and other websites." "Easily download videos from Youtube, Dailymotion, Vimeo and other websites."
msgstr "" msgstr ""
#: controllers/FrontController.php:115 #: controllers/FrontController.php:110
msgid "" msgid ""
"List of all supported websites from which Alltube Download can extract video " "List of all supported websites from which Alltube Download can extract video "
"or audio files" "or audio files"
msgstr "" msgstr ""
#: controllers/FrontController.php:141 #: controllers/FrontController.php:136
msgid "Password prompt" msgid "Password prompt"
msgstr "" msgstr ""
#: controllers/FrontController.php:142 #: controllers/FrontController.php:138
msgid "" msgid ""
"You need a password in order to download this video with Alltube Download" "You need a password in order to download this video with Alltube Download"
msgstr "" msgstr ""
#: controllers/FrontController.php:172 #: controllers/FrontController.php:169
msgid "Video download" msgid "Video download"
msgstr "" msgstr ""
#: controllers/FrontController.php:173 #: controllers/FrontController.php:171
msgid "Download video from " msgid "Download video from @extractor"
msgstr "" msgstr ""
#: controllers/FrontController.php:177 #: controllers/FrontController.php:177
msgid "from" msgid "Download @title from @extractor"
msgstr "" msgstr ""
#: controllers/FrontController.php:248 #: controllers/FrontController.php:253 controllers/FrontController.php:284
msgid "Error" msgid "Error"
msgstr "" msgstr ""

View File

@ -1,18 +1,40 @@
</div> </div>
<footer class="small-font"> <footer class="small-font">
<div class="footer_wrapper"> <div class="footer_wrapper">
{t}Code by{/t} <a rel="author" target="blank" {$dev="<a rel='author' target='blank'
href="http://rudloff.pro/">Pierre Rudloff</a> href='http://rudloff.pro/'>
&middot; {t}Design by{/t} Pierre Rudloff
<a rel="author" target="blank" </a>"}
href="http://olivierhaquette.fr">Olivier Haquette</a> {t params=['@dev'=>$dev]}Code by @dev{/t}
&middot;
<a rel="noopener" target="_blank" href="https://github.com/Rudloff/alltube">{t}Get the code{/t}</a> &middot;
&middot;
{t}Based on{/t} <a href="http://rg3.github.io/youtube-dl/">youtube-dl</a> {$designer="<a rel='author' target='blank'
&middot; href='http://olivierhaquette.fr'>
<a rel="noopener" target="_blank" title="{t}Donate using Liberapay{/t}" href="https://liberapay.com/Rudloff/donate">{t}Donate{/t}</a> Olivier Haquette
</div> </a>"}
{t params=['@designer' => $designer]}Design by @designer{/t}
&middot;
<a rel="noopener" target="_blank" href="https://github.com/Rudloff/alltube">
{t}Get the code{/t}
</a>
&middot;
{$youtubedl="<a href='http://rg3.github.io/youtube-dl/'>
youtube-dl
</a>"}
{t params=['@youtubedl'=>$youtubedl]}Based on @youtubedl{/t}
&middot;
<a rel="noopener" target="_blank" title="{t}Donate using Liberapay{/t}"
href="https://liberapay.com/Rudloff/donate">
{t}Donate{/t}
</a>
</div>
</footer> </footer>
</body> </body>
</html> </html>

View File

@ -5,7 +5,7 @@
{if isset($locale) AND $locale->getCountry()} {if isset($locale) AND $locale->getCountry()}
{$locale->getCountry()->getEmoji()} {$locale->getCountry()->getEmoji()}
{else} {else}
Set language {t}Set language{/t}
{/if} {/if}
</button> </button>
<ul class="supportedLocales"> <ul class="supportedLocales">

View File

@ -3,10 +3,14 @@
<div itemscope itemtype="http://schema.org/VideoObject"> <div itemscope itemtype="http://schema.org/VideoObject">
<main class="main"> <main class="main">
{include file="inc/logo.tpl"} {include file="inc/logo.tpl"}
<p id="download_intro">{t}You are going to download{/t}<i itemprop="name"> {$title="<i itemprop='name'>
<a itemprop="url" id="video_link" <a itemprop='url' id='video_link'
href="{$video->webpage_url}"> href='{$video->webpage_url}'>
{$video->title}</a></i>. {$video->title}
</a>
</i>"}
<p id="download_intro">
{t params=['@title' => $title]}You are going to download @title.{/t}
</p> </p>
{if isset($video->thumbnail)} {if isset($video->thumbnail)}
<img itemprop="thumbnailUrl" class="thumb" src="{$video->thumbnail}" alt="" /> <img itemprop="thumbnailUrl" class="thumb" src="{$video->thumbnail}" alt="" />
@ -79,14 +83,14 @@
{if $config->convertAdvanced} {if $config->convertAdvanced}
<input type="checkbox" name="customConvert" id="customConvert"/> <input type="checkbox" name="customConvert" id="customConvert"/>
<label for="customConvert">{t}Convert into a custom format:{/t}</label> <label for="customConvert">{t}Convert into a custom format:{/t}</label>
<select title="Custom format" name="customFormat" aria-label="{t}Format to convert to{/t}"> <select title="{t}Custom format{/t}" name="customFormat" aria-label="{t}Format to convert to{/t}">
{foreach $config->convertAdvancedFormats as $format} {foreach $config->convertAdvancedFormats as $format}
<option>{$format}</option> <option>{$format}</option>
{/foreach} {/foreach}
</select> </select>
{t}with{/t} {t}with{/t}
<label for="customBitrate" class="sr-only">{t}Bit rate{/t}</label> <label for="customBitrate" class="sr-only">{t}Bit rate{/t}</label>
<input type="number" value="{$config->audioBitrate}" title="Custom bitrate" class="customBitrate" <input type="number" value="{$config->audioBitrate}" title="{t}Custom bitrate{/t}" class="customBitrate"
name="customBitrate" id="customBitrate" aria-describedby="customBitrateUnit" /> name="customBitrate" id="customBitrate" aria-describedby="customBitrateUnit" />
<span id="customBitrateUnit">{t}kbit/s audio{/t}</span> <span id="customBitrateUnit">{t}kbit/s audio{/t}</span>
<br/><br/> <br/><br/>

View File

@ -2,10 +2,18 @@
<div class="wrapper"> <div class="wrapper">
<main class="main"> <main class="main">
{include file="inc/logo.tpl"} {include file="inc/logo.tpl"}
<p>{t}Videos extracted from{/t} {if isset($video->title)}<i>
<a href="{$video->webpage_url}"> {if isset($video->title)}
{$video->title}</a></i>{/if}{t}:{/t} {$title="<i>
</p> <a href='{$video->webpage_url}'>
{$video->title}
</a>
</i>"}
<p>
{t params=['@title'=>$title]}Videos extracted from @title:{/t}
</p>
{/if}
{if $config->stream} {if $config->stream}
<a href="{path_for name="download"}?url={$video->webpage_url}" class="downloadBtn">Download everything</a> <a href="{path_for name="download"}?url={$video->webpage_url}" class="downloadBtn">Download everything</a>
{/if} {/if}