English support
This commit is contained in:
parent
48e520630d
commit
1e910656ee
5 changed files with 35 additions and 4 deletions
|
@ -38,9 +38,11 @@ class ArticleIndexPage(Page):
|
||||||
|
|
||||||
intro_de = RichTextField(default='', blank=True)
|
intro_de = RichTextField(default='', blank=True)
|
||||||
intro_fr = RichTextField(default='', blank=True)
|
intro_fr = RichTextField(default='', blank=True)
|
||||||
|
intro_en = RichTextField(default='', blank=True)
|
||||||
trans_intro = TranslatedField(
|
trans_intro = TranslatedField(
|
||||||
'intro_de',
|
'intro_de',
|
||||||
'intro_fr',
|
'intro_fr',
|
||||||
|
'intro_en',
|
||||||
)
|
)
|
||||||
|
|
||||||
feed_image = models.ForeignKey(
|
feed_image = models.ForeignKey(
|
||||||
|
@ -54,6 +56,8 @@ class ArticleIndexPage(Page):
|
||||||
FieldPanel('intro_de'),
|
FieldPanel('intro_de'),
|
||||||
FieldPanel('title_fr'),
|
FieldPanel('title_fr'),
|
||||||
FieldPanel('intro_fr'),
|
FieldPanel('intro_fr'),
|
||||||
|
FieldPanel('title_en'),
|
||||||
|
FieldPanel('intro_en'),
|
||||||
ImageChooserPanel('feed_image'),
|
ImageChooserPanel('feed_image'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -87,16 +91,20 @@ class ImageCarouselBlock(StructBlock):
|
||||||
|
|
||||||
class ArticlePage(Page):
|
class ArticlePage(Page):
|
||||||
title_fr = models.CharField(max_length=255, default="")
|
title_fr = models.CharField(max_length=255, default="")
|
||||||
|
title_en = models.CharField(max_length=255, default="")
|
||||||
trans_title = TranslatedField(
|
trans_title = TranslatedField(
|
||||||
'title',
|
'title',
|
||||||
'title_fr',
|
'title_fr',
|
||||||
|
'title_en',
|
||||||
)
|
)
|
||||||
|
|
||||||
intro_de = RichTextField(default='', blank=True)
|
intro_de = RichTextField(default='', blank=True)
|
||||||
intro_fr = RichTextField(default='', blank=True)
|
intro_fr = RichTextField(default='', blank=True)
|
||||||
|
intro_en = RichTextField(default='', blank=True)
|
||||||
trans_intro = TranslatedField(
|
trans_intro = TranslatedField(
|
||||||
'intro_de',
|
'intro_de',
|
||||||
'intro_fr',
|
'intro_fr',
|
||||||
|
'intro_en',
|
||||||
)
|
)
|
||||||
|
|
||||||
gallery = StreamField([
|
gallery = StreamField([
|
||||||
|
@ -122,9 +130,18 @@ class ArticlePage(Page):
|
||||||
('gallery', 'Image gallery'),
|
('gallery', 'Image gallery'),
|
||||||
], icon='media'))
|
], icon='media'))
|
||||||
], null=True, blank=True)
|
], 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(
|
trans_body = TranslatedField(
|
||||||
'body_de',
|
'body_de',
|
||||||
'body_fr',
|
'body_fr',
|
||||||
|
'body_en',
|
||||||
)
|
)
|
||||||
|
|
||||||
date = models.DateField("Date", null=True, blank=True)
|
date = models.DateField("Date", null=True, blank=True)
|
||||||
|
@ -142,10 +159,13 @@ class ArticlePage(Page):
|
||||||
search_fields = Page.search_fields + [
|
search_fields = Page.search_fields + [
|
||||||
index.SearchField('title', partial_match=True, boost=10),
|
index.SearchField('title', partial_match=True, boost=10),
|
||||||
index.SearchField('title_fr', 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_de', partial_match=True),
|
||||||
index.SearchField('body_fr', 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_de', partial_match=True),
|
||||||
index.SearchField('intro_fr', partial_match=True),
|
index.SearchField('intro_fr', partial_match=True),
|
||||||
|
index.SearchField('intro_en', partial_match=True),
|
||||||
]
|
]
|
||||||
content_panels = [
|
content_panels = [
|
||||||
MultiFieldPanel([
|
MultiFieldPanel([
|
||||||
|
@ -158,6 +178,11 @@ class ArticlePage(Page):
|
||||||
FieldPanel('intro_fr'),
|
FieldPanel('intro_fr'),
|
||||||
], heading="Français"),
|
], heading="Français"),
|
||||||
StreamFieldPanel('body_fr'),
|
StreamFieldPanel('body_fr'),
|
||||||
|
MultiFieldPanel([
|
||||||
|
FieldPanel('title_en'),
|
||||||
|
FieldPanel('intro_en'),
|
||||||
|
], heading="Français"),
|
||||||
|
StreamFieldPanel('body_en'),
|
||||||
MultiFieldPanel([
|
MultiFieldPanel([
|
||||||
ImageChooserPanel('feed_image'),
|
ImageChooserPanel('feed_image'),
|
||||||
], heading="Images"),
|
], heading="Images"),
|
||||||
|
@ -241,7 +266,7 @@ class HomePage(Page):
|
||||||
def blogentries(self):
|
def blogentries(self):
|
||||||
# Get list of latest news
|
# Get list of latest news
|
||||||
curlang = translation.get_language()
|
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)
|
parent = BlogPage.objects.filter(slug='news-%s' % curlang)
|
||||||
if not parent: return []
|
if not parent: return []
|
||||||
posts = EntryPage.objects.live().descendant_of(parent[0])
|
posts = EntryPage.objects.live().descendant_of(parent[0])
|
||||||
|
@ -257,8 +282,9 @@ class HomePage(Page):
|
||||||
curlang = translation.get_language()
|
curlang = translation.get_language()
|
||||||
if curlang in ['de']:
|
if curlang in ['de']:
|
||||||
entries = entries.exclude(lang='fr')
|
entries = entries.exclude(lang='fr')
|
||||||
elif curlang in ['fr']:
|
else:
|
||||||
entries = entries.exclude(lang='de')
|
entries = entries.exclude(lang='de')
|
||||||
|
# TODO: English news?
|
||||||
news = events = jobs = []
|
news = events = jobs = []
|
||||||
Stream1 = Stream.objects.filter(title='News')
|
Stream1 = Stream.objects.filter(title='News')
|
||||||
if Stream1: news = entries.filter(stream=Stream1)
|
if Stream1: news = entries.filter(stream=Stream1)
|
||||||
|
|
|
@ -17,6 +17,7 @@ def language_switcher(context):
|
||||||
'languages': [
|
'languages': [
|
||||||
{ 'code': 'de', 'title': 'De', 'url': url.replace('$lang$','de') },
|
{ 'code': 'de', 'title': 'De', 'url': url.replace('$lang$','de') },
|
||||||
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('$lang$','fr') }
|
{ 'code': 'fr', 'title': 'Fr', 'url': url.replace('$lang$','fr') }
|
||||||
|
# { 'code': 'en', 'title': 'En', 'url': url.replace('$lang$','en') }
|
||||||
],
|
],
|
||||||
'currentlangcode': translation.get_language(),
|
'currentlangcode': translation.get_language(),
|
||||||
'request': context['request'],
|
'request': context['request'],
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
class TranslatedField(object):
|
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.de_field = de_field
|
||||||
self.fr_field = fr_field
|
self.fr_field = fr_field
|
||||||
|
self.en_field = en_field
|
||||||
|
|
||||||
def __get__(self, instance, owner):
|
def __get__(self, instance, owner):
|
||||||
if translation.get_language() == 'fr':
|
if translation.get_language() == 'fr':
|
||||||
return getattr(instance, self.fr_field)
|
return getattr(instance, self.fr_field)
|
||||||
|
elif translation.get_language() == 'en':
|
||||||
|
return getattr(instance, self.en_field)
|
||||||
else:
|
else:
|
||||||
return getattr(instance, self.de_field)
|
return getattr(instance, self.de_field)
|
||||||
|
|
|
@ -146,6 +146,7 @@ PASSWORD_REQUIRED_TEMPLATE = 'password.html'
|
||||||
LANGUAGES = (
|
LANGUAGES = (
|
||||||
('de', u'Deutsch'),
|
('de', u'Deutsch'),
|
||||||
('fr', u'Français'),
|
('fr', u'Français'),
|
||||||
|
('en', u'English'),
|
||||||
)
|
)
|
||||||
LANGUAGE_CODE = 'de' # default language
|
LANGUAGE_CODE = 'de' # default language
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# Updated: 17.11.2017
|
# Updated: 16.5.2018
|
||||||
|
|
||||||
# Core
|
# Core
|
||||||
wagtail>=1.13.1,<2.0.0
|
wagtail>=1.13.1,<2.0.0
|
||||||
|
|
Loading…
Reference in a new issue