Add region setting to supplement localization (#1875)

This commit is contained in:
Raphael Michel
2020-12-14 13:15:38 +01:00
committed by GitHub
parent e311341d01
commit 04bfa63a5e
46 changed files with 281 additions and 90 deletions

View File

@@ -1,8 +1,9 @@
from django.core.cache import cache
from django.utils.translation import get_language
from django_countries import Countries
from django_countries.fields import CountryField
from pretix.base.i18n import get_language_without_region
class CachedCountries(Countries):
_cached_lists = {}
@@ -14,7 +15,7 @@ class CachedCountries(Countries):
django-countries performs a unicode-aware sorting based on pyuca which is incredibly
slow.
"""
cache_key = "countries:all:{}".format(get_language())
cache_key = "countries:all:{}".format(get_language_without_region())
if self.cache_subkey:
cache_key += ":" + self.cache_subkey
if cache_key in self._cached_lists:

View File

@@ -0,0 +1,18 @@
# Date according to https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
SHORT_DATE_FORMAT = 'm/d/Y'
SHORT_DATETIME_FORMAT = 'm/d/Y P'
TIME_FORMAT = 'P'
WEEK_FORMAT = '\\W W, o'
WEEK_DAY_FORMAT = 'D, M jS'
DATE_INPUT_FORMATS = [
'%m/%d/%Y',
'%Y-%m-%d',
'%m/%d/%y',
]
TIME_INPUT_FORMATS = [
'%I:%M %p',
'%H:%M:%S', # '14:30:59'
'%H:%M:%S.%f', # '14:30:59.000200'
'%H:%M', # '14:30'
]

View File

@@ -126,6 +126,7 @@ def get_javascript_format_without_seconds(format_name):
def get_moment_locale(locale=None):
cur_lang = locale or translation.get_language()
cur_lang = cur_lang.lower()
if cur_lang in moment_locales:
return cur_lang
if '-' in cur_lang or '_' in cur_lang: