def post(self, request, *args, **kwargs): config = Config.load() config.locale = request.POST['locale'] config.save() locales = self.get_locales() return render(request, NabWebView.template_name, context={ 'current_locale': config.locale, 'locales': locales })
def post(self, request, *args, **kwargs): if "locale" in request.POST: config = Config.load() config.locale = request.POST["locale"] config.save() asyncio.run(self.notify_config_update("nabd", "locale")) user_language = to_language(config.locale) translation.activate(user_language) request.LANGUAGE_CODE = translation.get_language() context = self.get_context() return render(request, self.template_name(), context=context)
def get(self, request, *args, **kwargs): user_locale = Config.load().locale user_language = to_language(user_locale) translation.activate(user_language) self.request.session[translation.LANGUAGE_SESSION_KEY] = user_language locales = self.get_locales() return render(request, NabWebView.template_name, context={ 'current_locale': user_locale, 'locales': locales })
def get_context(self): user_locale = Config.load().locale locales = self.get_locales() return {"current_locale": user_locale, "locales": locales}
def get_locales(self): config = Config.load() return [(to_locale(lang), name, to_locale(lang) == config.locale) for (lang, name) in settings.LANGUAGES]
def process_request(self, request): user_locale = Config.load().locale user_language = to_language(user_locale) translation.activate(user_language) request.LANGUAGE_CODE = translation.get_language()