From 0cf8e237b584b69c2408eb6bc655b096470621b1 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 16 Sep 2017 20:55:37 +0530 Subject: [PATCH] Now passing user's language to celery task --- datacenterlight/locale/de/LC_MESSAGES/django.po | 15 ++++++++++++++- datacenterlight/tasks.py | 6 ++++++ hosting/views.py | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/datacenterlight/locale/de/LC_MESSAGES/django.po b/datacenterlight/locale/de/LC_MESSAGES/django.po index 6c9d36ae..dedd3f84 100644 --- a/datacenterlight/locale/de/LC_MESSAGES/django.po +++ b/datacenterlight/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-09-03 16:44+0000\n" +"POT-Creation-Date: 2017-09-16 14:09+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,6 +18,10 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#, python-format +msgid "Your New VM %(vm_name)s at Data Center Light" +msgstr "Deine neue VM %(vm_name)s bei Data Center Light" + msgid "Enter name" msgstr "Name" @@ -183,9 +187,18 @@ msgstr "Kontakt" msgid "All Rights Reserved" msgstr "Alle Rechte vorbehalten" +msgid "Toggle navigation" +msgstr "Konfiguration" + msgid "Why Data Center Light?" msgstr "Warum Data Center Light?" +msgid "Login" +msgstr "" + +msgid "Dashboard" +msgstr "" + msgid "Finally, an affordable VM hosting in Switzerland!" msgstr "Endlich: bezahlbares VM Hosting in der Schweiz" diff --git a/datacenterlight/tasks.py b/datacenterlight/tasks.py index 1a20751a..1335869b 100644 --- a/datacenterlight/tasks.py +++ b/datacenterlight/tasks.py @@ -5,6 +5,7 @@ from celery.utils.log import get_task_logger from celery import current_task from django.conf import settings from django.core.mail import EmailMessage +from django.utils import translation from django.utils.translation import ugettext_lazy as _ from dynamicweb.celery import app @@ -141,6 +142,11 @@ def create_vm_task(self, vm_template_id, user, specs, template, email.send() if 'pass' in user: + lang = 'en-us' + if user.get('language') is not None: + logger.debug("Language is set to {}".format(user.get('language'))) + lang = user.get('language') + translation.activate(lang) # Send notification to the user as soon as VM has been booked context = { 'vm': vm, diff --git a/hosting/views.py b/hosting/views.py index db5a2238..e1d2feb2 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -14,7 +14,7 @@ from django.shortcuts import redirect from django.shortcuts import render from django.utils.http import urlsafe_base64_decode from django.utils.safestring import mark_safe -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import get_language, ugettext_lazy as _ from django.views.generic import View, CreateView, FormView, ListView, \ DetailView, \ DeleteView, TemplateView, UpdateView @@ -757,6 +757,7 @@ class OrdersHostingDetailView(LoginRequiredMixin, 'pass': self.request.user.password, 'request_scheme': request.scheme, 'request_host': request.get_host(), + 'language': get_language(), } create_vm_task.delay(vm_template_id, user, specs, template, stripe_customer_id, billing_address_data,