English support

This commit is contained in:
Oleg Lavrovsky 2018-05-16 15:08:59 +02:00
parent 48e520630d
commit 1e910656ee
5 changed files with 35 additions and 4 deletions

View file

@ -38,9 +38,11 @@ class ArticleIndexPage(Page):
intro_de = RichTextField(default='', blank=True)
intro_fr = RichTextField(default='', blank=True)
intro_en = RichTextField(default='', blank=True)
trans_intro = TranslatedField(
'intro_de',
'intro_fr',
'intro_en',
)
feed_image = models.ForeignKey(
@ -54,6 +56,8 @@ class ArticleIndexPage(Page):
FieldPanel('intro_de'),
FieldPanel('title_fr'),
FieldPanel('intro_fr'),
FieldPanel('title_en'),
FieldPanel('intro_en'),
ImageChooserPanel('feed_image'),
]
@ -87,16 +91,20 @@ class ImageCarouselBlock(StructBlock):
class ArticlePage(Page):
title_fr = models.CharField(max_length=255, default="")
title_en = models.CharField(max_length=255, default="")
trans_title = TranslatedField(
'title',
'title_fr',
'title_en',
)
intro_de = RichTextField(default='', blank=True)
intro_fr = RichTextField(default='', blank=True)
intro_en = RichTextField(default='', blank=True)
trans_intro = TranslatedField(
'intro_de',
'intro_fr',
'intro_en',
)
gallery = StreamField([
@ -122,9 +130,18 @@ class ArticlePage(Page):
('gallery', 'Image gallery'),
], icon='media'))
], null=True, blank=True)
body_en = StreamField([
('paragraph', RichTextBlock()),
('section', CharBlock(classname="full title")),
('info', InfoBlock(icon='help')),
('media', ChoiceBlock(choices=[
('gallery', 'Image gallery'),
], icon='media'))
], null=True, blank=True)
trans_body = TranslatedField(
'body_de',
'body_fr',
'body_en',
)
date = models.DateField("Date", null=True, blank=True)
@ -142,10 +159,13 @@ class ArticlePage(Page):
search_fields = Page.search_fields + [
index.SearchField('title', partial_match=True, boost=10),
index.SearchField('title_fr', partial_match=True, boost=10),
index.SearchField('title_en', partial_match=True, boost=10),
index.SearchField('body_de', partial_match=True),
index.SearchField('body_fr', partial_match=True),
index.SearchField('body_en', partial_match=True),
index.SearchField('intro_de', partial_match=True),
index.SearchField('intro_fr', partial_match=True),
index.SearchField('intro_en', partial_match=True),
]
content_panels = [
MultiFieldPanel([
@ -158,6 +178,11 @@ class ArticlePage(Page):
FieldPanel('intro_fr'),
], heading="Français"),
StreamFieldPanel('body_fr'),
MultiFieldPanel([
FieldPanel('title_en'),
FieldPanel('intro_en'),
], heading="Français"),
StreamFieldPanel('body_en'),
MultiFieldPanel([
ImageChooserPanel('feed_image'),
], heading="Images"),
@ -241,7 +266,7 @@ class HomePage(Page):
def blogentries(self):
# Get list of latest news
curlang = translation.get_language()
if not curlang in ['de', 'fr']: curlang = 'de' # Default language
if not curlang in ['de', 'fr', 'en', 'it']: curlang = 'de' # Default language
parent = BlogPage.objects.filter(slug='news-%s' % curlang)
if not parent: return []
posts = EntryPage.objects.live().descendant_of(parent[0])
@ -257,8 +282,9 @@ class HomePage(Page):
curlang = translation.get_language()
if curlang in ['de']:
entries = entries.exclude(lang='fr')
elif curlang in ['fr']:
else:
entries = entries.exclude(lang='de')
# TODO: English news?
news = events = jobs = []
Stream1 = Stream.objects.filter(title='News')
if Stream1: news = entries.filter(stream=Stream1)

View file

@ -17,6 +17,7 @@ def language_switcher(context):
'languages': [
{ 'code': 'de', 'title': 'De', 'url': url.replace('$lang$','de') },
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('$lang$','fr') }
# { 'code': 'en', 'title': 'En', 'url': url.replace('$lang$','en') }
],
'currentlangcode': translation.get_language(),
'request': context['request'],

View file

@ -1,12 +1,15 @@
from django.utils import translation
class TranslatedField(object):
def __init__(self, de_field, fr_field):
def __init__(self, de_field, fr_field, en_field):
self.de_field = de_field
self.fr_field = fr_field
self.en_field = en_field
def __get__(self, instance, owner):
if translation.get_language() == 'fr':
return getattr(instance, self.fr_field)
elif translation.get_language() == 'en':
return getattr(instance, self.en_field)
else:
return getattr(instance, self.de_field)

View file

@ -146,6 +146,7 @@ PASSWORD_REQUIRED_TEMPLATE = 'password.html'
LANGUAGES = (
('de', u'Deutsch'),
('fr', u'Français'),
('en', u'English'),
)
LANGUAGE_CODE = 'de' # default language

View file

@ -1,4 +1,4 @@
# Updated: 17.11.2017
# Updated: 16.5.2018
# Core
wagtail>=1.13.1,<2.0.0