Added multple translation tracks with configurable endpoints and labels

This commit is contained in:
Benjamin Peter 2017-12-09 23:44:47 +01:00 committed by dedeibel
parent 65397e5734
commit be515f5150
9 changed files with 140 additions and 57 deletions

View file

@ -285,12 +285,12 @@ try {
require('view/room.php');
}
else if(preg_match('@^([^/]+)/translated$@', $route, $m))
else if(preg_match('@^([^/]+)/i18n/([^/]+)$@', $route, $m))
{
$_GET = array(
'room' => $m[1],
'selection' => '',
'language' => 'translated',
'language' => $m[2],
);
require('view/room.php');
}
@ -305,17 +305,19 @@ try {
require('view/room.php');
}
else if(preg_match('@^([^/]+)/(sd|audio|slides|dash)/translated$@', $route, $m))
else if(preg_match('@^([^/]+)/(sd|audio|slides|dash)/i18n/([^/]+)$@', $route, $m))
{
$_GET = array(
'room' => $m[1],
'selection' => $m[2],
'language' => 'translated',
'language' => $m[3],
);
require('view/room.php');
}
else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|translated|stereo)(/no-autoplay)?$@', $route, $m))
// TODO use dynamic i18n parameter
// TODO change to no-autoplay query parameter?
else if(preg_match('@^embed/([^/]+)/(hd|sd|audio|slides)/(native|translated|translated2|stereo)(/no-autoplay)?$@', $route, $m))
{
$_GET = array(
'room' => $m[1],

View file

@ -72,16 +72,34 @@ class Conferences
return in_array($mandator, Conferences::listConferences());
}
public static function loadConferenceConfig($mandator) {
$configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php';
$config = include($configfile);
public static function loadConferenceConfig($mandator) {
$configfile = forceslash(Conferences::MANDATOR_DIR).forceslash($mandator).'config.php';
$config = include($configfile);
if(!is_array($config)) {
throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?");
}
if(!is_array($config)) {
throw new ConfigException("Loading $configfile did not return an array. Maybe it's missing a return-statement?");
}
return $config;
}
// Allow setting TRANSLATION simply to true and fill in default values for uniformity
$rooms = $config['ROOMS'];
foreach ($rooms as $slug => $room) {
if (!isset($room['TRANSLATION'])) {
$config['ROOMS'][$slug]['TRANSLATION'] = [];
}
elseif (! is_array($room['TRANSLATION'])) {
if ($room['TRANSLATION'] === true) {
$config['ROOMS'][$slug]['TRANSLATION'] = [[
'endpoint' => 'translated',
'label' => 'Translated'
]];
}
else {
$config['ROOMS'][$slug]['TRANSLATION'] = [];
}
}
}
return $config;
}
public static function getConference($mandator) {
return new Conference(Conferences::loadConferenceConfig($mandator), $mandator);

View file

@ -175,10 +175,40 @@ class Room
return 'Adaptive multi-format-multi-bitrate-Stream to rule the World!!1elf';
}
public function hasTranslation() {
public function getTranslations() {
return $this->getConference()->get('ROOMS.'.$this->getSlug().'.TRANSLATION');
}
private function getTranslationEndpoints() {
return array_map(
function ($translation) {
return $translation['endpoint'];
},
$this->getTranslations()
);
}
private function isTranslationEndpoint($endpoint) {
return in_array($endpoint, $this->getTranslationEndpoints());
}
private function findTranslationLabel($language) {
foreach($this->getTranslations() as $translation) {
if ($translation['endpoint'] === $language) {
return $translation['label'];
}
}
return null;
}
public function hasTranslation() {
return count($this->getTranslations()) > 0;
}
public function isValidLanguage($language) {
return ($language === 'native' || $this->isTranslationEndpoint($language));
}
public function getSelectionNames()
{
$selections = array();
@ -284,8 +314,9 @@ class Room
foreach ($selections as $selection) {
$streams[] = $this->createStreamObject($selection, 'native');
if($this->hasTranslation())
$streams[] = $this->createStreamObject($selection, 'translated');
foreach ($this->getTranslations() as $translation) {
$streams[] = $this->createStreamObject($selection, $translation['endpoint'], $translation['label']);
}
}
return $streams;
@ -305,17 +336,23 @@ class Room
if(!in_array($selection, $selections))
throw new NotFoundException('Selection '.$selection.' in Room '.$this->getSlug());
if($language == 'translated' && !$this->hasTranslation())
throw new NotFoundException('Translated Streams of Room '.$this->getSlug());
$translation_label = null;
if (substr($language, 0, strlen('native')) !== 'native') {
if (!$this->hasTranslation()) {
throw new NotFoundException('Translated Streams of Room '.$this->getSlug());
}
$translation_label = $this->findTranslationLabel($language);
}
return $this->createStreamObject($selection, $language);
return $this->createStreamObject($selection, $language, $translation_label);
}
public function createStreamObject($selection, $language = 'native')
public function createStreamObject($selection, $language = 'native', $languageLabel = null)
{
if($language == 'native' && $this->hasStereo())
$language = 'stereo';
return new Stream($this, $selection, $language);
return new Stream($this, $selection, $language, $languageLabel);
}
}

View file

@ -18,20 +18,24 @@ class RoomSelection
return $this->selection;
}
public function getLink()
{
private function getSelectionPath() {
$path = [$this->getRoom()->getConference()->getSlug(), $this->getRoom()->getSlug()];
$selection = $this->getRoom()->getSelectionNames();
if($selection[0] != $this->getSelection())
if ($selection[0] != $this->getSelection())
$path[] = $this->getSelection();
return joinpath($path).url_params();
return joinpath($path);
}
public function getLink()
{
return $this->getSelectionPath() . url_params();
}
public function getTranslatedLink()
public function getTranslatedLink($translation_endpoint)
{
return joinpath([$this->getLink(), 'translated']);
return joinpath([$this->getSelectionPath(), 'i18n', $translation_endpoint]) . url_params();
}
public function getDisplay()

View file

@ -2,11 +2,12 @@
class Stream
{
public function __construct(Room $room, $selection, $language)
public function __construct(Room $room, $selection, $language, $translation_label = null)
{
$this->room = $room;
$this->selection = $selection;
$this->language = $language;
$this->translation_label = (empty($translation_label)) ? $language : $translation_label;
}
public function getRoom()
@ -24,9 +25,14 @@ class Stream
return $this->language;
}
public function getTranslationLabel()
{
return $this->translation_label;
}
public function isTranslated()
{
return $this->getLanguage() == 'translated';
return !empty($this->getLanguage()) && $this->getLanguage() !== 'native';
}
public function getVideoSize()
@ -98,7 +104,7 @@ class Stream
}
if($this->isTranslated())
$display .= ' (Translation)';
$display .= ' ('. $this->getTranslationLabel() .')';
return $display;
}

View file

@ -10,12 +10,14 @@
<a href="<?=h($selection->getLink())?>" class="btn btn-primary">
<span class="fa fa-flag-o"></span>
native
Native
</a>
<a href="<?=h($selection->getTranslatedLink())?>" class="btn btn-primary">
<? foreach($room->getTranslations() as $translation): ?>
<a href="<?=h($selection->getTranslatedLink($translation['endpoint']))?>" class="btn btn-primary">
<span class="fa fa-flag"></span>
translated
<?=h(ucfirst($translation['label']))?>
</a>
<? endforeach ?>
</div>
</div>
@ -39,12 +41,14 @@
<a href="<?=h($room->createStreamObject('audio', 'native')->getAudioUrl($proto))?>" class="btn btn-default">
<span class="fa fa-flag-o"></span>
native
</a>
<a href="<?=h($room->createStreamObject('audio', 'translated')->getAudioUrl($proto))?>" class="btn btn-default">
<span class="fa fa-flag"></span>
translated
Native
</a>
<? foreach($room->getTranslations() as $translation): ?>
<a href="<?=h($room->createStreamObject('audio', $translation['endpoint'])->getAudioUrl($proto))?>" class="btn btn-default">
<span class="fa fa-flag"></span>
<?=h(ucfirst($translation['label']))?>
</a>
<? endforeach ?>
<? else: ?>

View file

@ -10,12 +10,14 @@
<a href="<?=h($selection->getLink())?>" class="btn btn-primary">
<span class="fa fa-flag-o"></span>
native
</a>
<a href="<?=h($selection->getTranslatedLink())?>" class="btn btn-primary">
<span class="fa fa-flag"></span>
translated
Native
</a>
<? foreach($room->getTranslations() as $translation): ?>
<a href="<?=h($selection->getTranslatedLink($translation['endpoint']))?>" class="btn btn-primary">
<span class="fa fa-flag"></span>
<?=h(ucfirst($translation['label']))?>
</a>
<? endforeach ?>
</div>
</div>

View file

@ -12,18 +12,20 @@
<a href="<?=h($selection->getLink())?>" class="btn btn-primary">
<span class="fa fa-flag-o"></span>
native
</a>
<a href="<?=h($selection->getTranslatedLink())?>" class="btn btn-primary">
<span class="fa fa-flag"></span>
translated
Native
</a>
<? foreach($room->getTranslations() as $translation): ?>
<a href="<?=h($selection->getTranslatedLink($translation['endpoint']))?>" class="btn btn-primary">
<span class="fa fa-flag"></span>
<?=h(ucfirst($translation['label']))?>
</a>
<? endforeach ?>
<? else: ?>
<a href="<?=h($selection->getLink())?>" class="btn btn-primary">
<span class="fa fa-video-camera"></span>
video
Video
</a>
<? endif ?>
@ -51,18 +53,20 @@
<a href="<?=h($room->createStreamObject($res, 'native')->getVideoUrl($proto))?>" class="btn btn-default">
<span class="fa fa-flag-o"></span>
native
</a>
<a href="<?=h($room->createStreamObject($res, 'translated')->getVideoUrl($proto))?>" class="btn btn-default">
<span class="fa fa-flag"></span>
translated
Native
</a>
<? foreach($room->getTranslations() as $translation): ?>
<a href="<?=h($room->createStreamObject($res, $translation['endpoint'])->getVideoUrl($proto))?>" class="btn btn-default">
<span class="fa fa-flag"></span>
<?=h(ucfirst($translation['label']))?>
</a>
<? endforeach ?>
<? else: ?>
<a href="<?=h($switcherstream->getVideoUrl($proto))?>" class="btn btn-default">
<span class="fa fa-video-camera"></span>
video
Video
</a>
<? endif ?>

View file

@ -1,8 +1,14 @@
<?php
$room = $conference->getRoom($_GET['room']);
$stream = $room->selectStream(
$_GET['selection'], $_GET['language']);
$selection = $_GET['selection'];
$language = $_GET['language'];
if (! $room->isValidLanguage($language)) {
throw new NotFoundException('Language not found');
}
$stream = $room->selectStream($selection, $language);
echo $tpl->render(array(
'page' => 'room',