From 577b69f2b64362cb1b64650bdf817390decb5a95 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Sun, 8 Nov 2020 17:19:59 +0100 Subject: [PATCH] Use default language from settings if language is not recognizable --- calendarweek/django.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/calendarweek/django.py b/calendarweek/django.py index d9d72a0..331e45d 100644 --- a/calendarweek/django.py +++ b/calendarweek/django.py @@ -17,6 +17,7 @@ import json import locale from typing import Any, List, Optional, Tuple +from django.conf import settings from django.http import HttpRequest, HttpResponse from django.utils.encoding import DEFAULT_LOCALE_ENCODING from django.utils.functional import lazy @@ -29,7 +30,7 @@ def i18n_day_names(loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of day names for the current locale. """ if loc is None: - loc = to_locale(get_language()) + loc = to_locale(get_language() or settings.LANGUAGE_CODE) try: return CalendarWeek.day_names(loc) @@ -41,7 +42,7 @@ def i18n_day_abbrs(loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of day name abbreviations for the current locale. """ if loc is None: - loc = to_locale(get_language()) + loc = to_locale(get_language() or settings.LANGUAGE_CODE) try: return CalendarWeek.day_abbrs(loc) @@ -53,7 +54,7 @@ def i18n_month_names(loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of month names for the current locale. """ if loc is None: - loc = to_locale(get_language()) + loc = to_locale(get_language() or settings.LANGUAGE_CODE) try: return CalendarWeek.month_names(loc) @@ -65,7 +66,7 @@ def i18n_month_abbrs(loc: Optional[str] = None) -> Tuple[str]: """ Return a tuple of month name abbreviations for the current locale. """ if loc is None: - loc = to_locale(get_language()) + loc = to_locale(get_language() or settings.LANGUAGE_CODE) try: return CalendarWeek.month_abbrs(loc) -- GitLab