changeset 93:9ae3d9c8b28a

actually display the subtitles (with Firefox it is used only when it's the first <track /> of the list, and when the "default" option is present)
author souliane <souliane@mailoo.org>
date Tue, 16 Jun 2015 21:26:58 +0200
parents 7a79cb5ed43b
children c1b77f07f644
files sat_website/media.py sat_website/templatetags/utils.py templates/sat_website/membership.html
diffstat 3 files changed, 19 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/sat_website/media.py	Tue Jun 16 20:31:16 2015 +0200
+++ b/sat_website/media.py	Tue Jun 16 21:26:58 2015 +0200
@@ -19,7 +19,7 @@
 You should have received a copy of the GNU Affero General Public License
 along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 """
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import get_language, ugettext_lazy as _
 from django.conf import settings
 from collections import namedtuple, OrderedDict
 import os.path
@@ -29,11 +29,17 @@
 class VideoDesc(namedtuple("VideoDesc", "paths description poster data")):
     @property
     def subtitles(self):
-        key = _(u"subtitles")
+        key = "subtitles"
         if key not in self.data:
             return {}
         result = OrderedDict()
-        for lang in self.data[key]:
+
+        # put the current lang first
+        current_lang = get_language()
+        langs = [current_lang] if current_lang in self.data[key] else []
+        langs.extend([lang for lang in self.data[key] if lang != current_lang])
+
+        for lang in langs:
             try:
                 result[lang] = os.path.splitext(self.paths[lang])[0] + '.vtt'
             except IndexError:
@@ -53,7 +59,7 @@
                            "fr": video + "libervia_adhesion_2015_fr.webm"}),
               _(u"Membership campaign for Libervia"),
               video + "posters/libervia_adhesion_2015.png",
-              {_(u"version"): "0.5", _(u"year"): "2015", _(u"subtitles"): ["en", "fr"]}),
+              {_(u"version"): "0.5", _(u"year"): "2015", "subtitles": ["en", "fr"]}),
 
     ImageDesc("images/screenshots/0.5/overview_libervia.png", _(u"Overview"),
               {_(u"frontend"): "libervia", _(u"version"): "0.5", _(u"year"): "2014"}),
--- a/sat_website/templatetags/utils.py	Tue Jun 16 20:31:16 2015 +0200
+++ b/sat_website/templatetags/utils.py	Tue Jun 16 21:26:58 2015 +0200
@@ -93,7 +93,12 @@
 
     def get_item(key, value):
         return "%s%s%s" % (key, sep, value)
-    items = [get_item(key.translate(lang), value) for key, value in entry.data.iteritems()]
+    
+    items = []
+    for key, value in entry.data.iteritems():
+        if key == "subtitles":  # is used as another dict key in media.py
+            key = _(u"subtitles")
+        items.append(get_item(key.translate(lang), value))
     try:
         lang_key = _(u"language").translate(lang)
         lang_value = lang if lang in entry.paths else entry.paths.keys()[0]
--- a/templates/sat_website/membership.html	Tue Jun 16 20:31:16 2015 +0200
+++ b/templates/sat_website/membership.html	Tue Jun 16 21:26:58 2015 +0200
@@ -33,7 +33,9 @@
 	    <video class="video-campaign" poster="http://ftp.goffi.org/media/video/posters/libervia_adhesion_2015.png" controls preload="none">
             <source src="http://ftp.goffi.org/media/video/libervia_adhesion_2015_{{LANGUAGE_CODE}}.webm" type='video/webm; codecs="vp8.0, vorbis"'>
             <source src="http://ftp.goffi.org/media/video/libervia_adhesion_2015_{{LANGUAGE_CODE}}.ogv" type='video/ogg; codecs="theora, vorbis"'>
-             {% blocktrans with firefox="<a href=\"http://www.mozilla.org/\">Firefox</a>" %}Your browser doesn't manage the « video » tag, you should update, e.g. with the last {{ firefox }}.{% endblocktrans %}
+            {% get_language_info for LANGUAGE_CODE as lang %}
+		    <track label="{{lang.name_local}}" src="http://ftp.goffi.org/media/video/libervia_adhesion_2015_{{LANGUAGE_CODE}}.vtt" kind="subtitles" srclang="{{LANGUAGE_CODE}}" default />
+            {% blocktrans with firefox="<a href=\"http://www.mozilla.org/\">Firefox</a>" %}Your browser doesn't manage the « video » tag, you should update, e.g. with the last {{ firefox }}.{% endblocktrans %}
 	    </video>
     </div>
 </div>