45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
|
|
import ox
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.conf import settings
|
|
|
|
from ...render import add_translations
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'export all subtitles for translations'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument('--lang', action='store', dest='lang', default=None, help='subtitle language')
|
|
|
|
def handle(self, **options):
|
|
import annotation.models
|
|
import item.models
|
|
lang = options["lang"]
|
|
if lang:
|
|
lang = lang.split(',')
|
|
tlang = lang[1:]
|
|
lang = lang[0]
|
|
else:
|
|
tlang = None
|
|
if lang == "en":
|
|
lang = None
|
|
|
|
for i in item.models.Item.objects.filter(data__type__contains='Voice Over').order_by('sort__title'):
|
|
print("## %s %s" % (i.get("title"), i.public_id))
|
|
for sub in i.annotations.all().filter(layer='subtitles').exclude(value='').filter(languages=lang).order_by("start"):
|
|
if tlang:
|
|
value = add_translations(sub, tlang)
|
|
value = ox.strip_tags(value)
|
|
else:
|
|
value = sub.value.replace('<br/>', '<br>').replace('<br>\n', '\n').replace('<br>', '\n').strip()
|
|
if sub.languages:
|
|
value = ox.strip_tags(value)
|
|
print(value.strip() + "\n")
|
|
print("\n\n\n")
|
|
|