2nd Django Friends Meetup, 2013-11-21
project recap
PocketScience GmbH, NOUS
Wissensmanagement GmbH,
Stephan Pötschner, Florian Demmer
www.staatsoperlive.com
the project
basically: stream live events
(with subtitles and other things)
- multi language
- api for smart tv and mobile
- external shop/payment
- external cdn for video
- cms backend
the timeline
"ambitious"
june : concept
july - september : development
mid october : go live
the result
https://www.staatsoperlive.com
Am 27. Oktober wurde die erste Staatsopern-Produktion live auf die Computer übertragen.
Per Streaming im Internet konnte man den „Rosenkavalier“ von Richard Strauss verfolgen. Über 350 Opernfans zahlten dafür je 14 Euro und klickten sich in die Vorstellung.
Jeder dritte Zuseher vor dem Computer stammte aus Österreich.
translatable content
what do we want?
model for data in multiple languages
- no migrations
- no primary language fall back
- required and optional fields
translatable content
the two ways ...
- additional columns
- related table
translatable content
and the weird way ...
- primary in db + translation in po
translatable content
additional columns
class News(models.Model):
title = models.CharField() # default, "no language"?
title_en = models.CharField(blank=True, null=True)
title_es = models.CharField(blank=True, null=True)
- requires migration to add/remove
- cannot enforce required field
- language per column
translatable content
related table
class News(models.Model):
title = models.CharField()
class NewsTranslation(models.Model):
base_obj = models.ForeignKey(News, related_name='translations')
language = models.CharField(max_length=2)
title = models.CharField()
- requires join
- language per row
translatable content
surely, there's an app for that!
yes, lots...
translatable content
- django-mothertongue
- django-multilingual-model
- django-translatable
- django-hvad (django-nani, django-multilingual-ng)
- django-model-i18n (django-pluggable-model-i18n)
- django-multilingual
- django-modeltranslation
- django-transmeta
- django-linguo
- ...
translatable content
django-transmeta
https://github.com/Yaco-Sistemas/django-transmeta
- additional columns
- custom meta class
class Book(models.Model): __metaclass__ = TransMeta
- translate via meta
class Meta: translate = ('name', 'description')
- comes with migration tool
translatable content
django-linguo
https://github.com/zmathew/django-linguo
- additional columns
- custom base model, manager
class Product(MultilingualModel):
objects = MultilingualManager() - translate via meta
class Meta: translate = ('name', 'description')
translatable content
django-modeltranslation
https://github.com/deschler/django-modeltranslation
- additional columns
- translator register
class NewsTranslationOptions(TranslationOptions): fields = ('title', 'text',) translator.register(News, NewsTranslationOptions)
- automatic fallback & prepopulation
- popular on djangopackages
translatable content
django-model-i18n
https://github.com/juanpex/django-model-i18n
- additional columns
- previously django-pluggable-model-i18n
- translator register
class PollTranslation(translator.ModelTranslation): fields = ('title',) translator.register(Poll, PollTranslation)
- sorry, looks messy
translatable content
django-hvad
https://github.com/KristianOellegaard/django-hvad
- related table (!)
- previously django-nani and django-multilingual(-ng)
-
Jonas Obrist, Divio, DjangoCon EU '11, ... DjangoORM
- joins hidden, 2nd table hidden
- no "default" translation in the main table
translatable content
django-hvad
- custom base model, manager
-
translate via special attribute
class DjangoApplication(TranslatableModel):
name = models.CharField(max_length=255, unique=True)
author = models.CharField(max_length=255)
translations = TranslatedFields(
description = models.TextField(),
description_author = models.CharField(max_length=255),
)
translatable content
django-hvad
the problem?
- django admin limitations:
"list_display", "search_fields", ...
only work on non-translated fields
translatable content
django-translatable
https://github.com/msiedlarek/django-translatable- related table
- custom base model, explicit 2nd model
class BookTranslation(
get_translation_model(Book, "book")): name = models.CharField() - no magic
TranslatableModel.get_translation(
language=None, fallback=True) - no major updates in 3 years
translatable content
django-multilingual-model
https://github.com/dokterbob/django-multilingual-model- related table
- custom base model, 2nd model, boilerplate!
class BookTranslation(MultilingualTranslation): class Meta: unique_together = ('parent', 'language_code')
parent = models.ForeignKey('Book',
related_name='translations') class Book(MultilingualModel):
[...] - no magic
book = Book(ISBN="1234567890") book_en = BookTranslation(language_code='en')
translatable content
django-mothertongue
https://github.com/robcharlwood/django-mothertongue
- related table
- custom base model, 2nd model, special attributes
class Book(MothertongueModelTranslate):
title = models.CharField()
translation_set = 'booktranslation_set' translated_fields = ['title'] -
some magic
book = Book(ISBN="1234567890") book.title = "Deutscher Titel" translation.activate("en") book.title = "English Title"
- django-localeurl integration
translatable content
-
sorry, no clear recommendation
-
additional colums: django-modeltranslation
-
related table: django-hvad
- we wrote something based on the ideas of
django-translatable,
django-multilingual-model and
django-mothertongue
@fdemmer
gmail, twitter, github, 500px, flickr, ...
2nd Django Friends Meetup, 2013-11-21
By Florian Demmer
2nd Django Friends Meetup, 2013-11-21
project recap lightning talk
- 2,386