From bf198f37db7cf16b32b0d0eb0925c0ac3c46b99a Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Sat, 2 Jan 2021 01:19:01 +0100 Subject: [PATCH] fix locale discovery by django app --- src/documents/templates/index.html | 2 +- src/documents/views.py | 22 ++++++++++++++++++---- src/paperless/urls.py | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/documents/templates/index.html b/src/documents/templates/index.html index 753aa766c..21112b643 100644 --- a/src/documents/templates/index.html +++ b/src/documents/templates/index.html @@ -12,7 +12,7 @@ - + diff --git a/src/documents/views.py b/src/documents/views.py index 7dc3ae3e6..8af29ce05 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -57,15 +57,29 @@ from .serialisers import ( class IndexView(TemplateView): template_name = "index.html" + def get_language(self): + # This is here for the following reason: + # Django identifies languages in the form "en-us" + # However, angular generates locales as "en-US". + # this translates between these two forms. + lang = get_language() + if "-" in lang: + first = lang[:lang.index("-")] + second = lang[lang.index("-")+1:] + return f"{first}-{second.upper()}" + else: + return lang + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['cookie_prefix'] = settings.COOKIE_PREFIX context['username'] = self.request.user.username context['full_name'] = self.request.user.get_full_name() - context['styles_css'] = f"frontend/{get_language()}/styles.css" - context['runtime_js'] = f"frontend/{get_language()}/runtime.js" - context['polyfills_js'] = f"frontend/{get_language()}/polyfills.js" - context['main_js'] = f"frontend/{get_language()}/main.js" + context['styles_css'] = f"frontend/{self.get_language()}/styles.css" + context['runtime_js'] = f"frontend/{self.get_language()}/runtime.js" + context['polyfills_js'] = f"frontend/{self.get_language()}/polyfills.js" # NOQA: E501 + context['main_js'] = f"frontend/{self.get_language()}/main.js" + context['manifest'] = f"frontend/{self.get_language()}/manifest.webmanifest" # NOQA: E501 return context diff --git a/src/paperless/urls.py b/src/paperless/urls.py index 6adb1be5b..49e6e8b7a 100755 --- a/src/paperless/urls.py +++ b/src/paperless/urls.py @@ -90,7 +90,7 @@ urlpatterns = [ # Frontend assets TODO: this is pretty bad, but it works. path('assets/', - RedirectView.as_view(url='/static/frontend/en-us/assets/%(path)s')), + RedirectView.as_view(url='/static/frontend/en-US/assets/%(path)s')), # TODO: with localization, this is even worse! :/ # login, logout