Skip to content

Commit

Permalink
Translation fallback to both, add notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Merlin Buczek committed Sep 1, 2019
1 parent 9e72d1e commit 56a109f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@
('de', _('German')),
)

MODELTRANSLATION_FALLBACK_LANGUAGES = ('en', 'de')

LOCALE_PATHS = [
os.path.join(ROOT_DIR, 'locale'),
]
Expand Down
10 changes: 9 additions & 1 deletion mpicms/base/mixins.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.utils import translation
from django.conf import settings
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_lazy as _, get_language_info
from django.contrib.auth import get_user_model
from django.contrib import messages

from wagtail.admin.edit_handlers import StreamFieldPanel
from wagtail.core.models import Page
Expand Down Expand Up @@ -64,5 +65,12 @@ def preview_text(self):
'markdown'
] else None

def serve(self, request):
lang = request.LANGUAGE_CODE
if not getattr(self, 'body_' + lang):
messages.info(request, _('Page not available in ') + get_language_info(lang)['name_local'])

return super().serve(request)

class Meta: # noqa
abstract = True

0 comments on commit 56a109f

Please sign in to comment.