aded full functionality to lang menu
This commit is contained in:
parent
feb591ea79
commit
1816301952
|
@ -1,6 +1,7 @@
|
||||||
from django.contrib.auth.mixins import UserPassesTestMixin
|
from django.contrib.auth.mixins import UserPassesTestMixin
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic.base import ContextMixin
|
from django.views.generic.base import ContextMixin
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from . import api, get_version
|
from . import api, get_version
|
||||||
from .auth import SESSION_KEY_TOKEN
|
from .auth import SESSION_KEY_TOKEN
|
||||||
|
@ -20,6 +21,7 @@ class CustomContextMixin(ContextMixin):
|
||||||
context.update({
|
context.update({
|
||||||
'services_menu': services_menu,
|
'services_menu': services_menu,
|
||||||
'version': get_version(),
|
'version': get_version(),
|
||||||
|
'languages': settings.LANGUAGES,
|
||||||
})
|
})
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
|
@ -81,9 +81,9 @@
|
||||||
<i class="fas fa-globe"></i> {% trans "Language" %}
|
<i class="fas fa-globe"></i> {% trans "Language" %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<a class="dropdown-item" href="#Select-Lang">{% trans 'English'%}</a>
|
{% for code, language in languages %}
|
||||||
<a class="dropdown-item" href="#Select-Lang">{% trans 'Català'%}</a>
|
<a class="dropdown-item" href="{% url 'musician:profile-set-lang' code %}">{{ language }}</a>
|
||||||
<a class="dropdown-item" href="#Select-Lang">{% trans 'Español'%}</a>
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -19,7 +19,7 @@ urlpatterns = [
|
||||||
path('billing/', views.BillingView.as_view(), name='billing'),
|
path('billing/', views.BillingView.as_view(), name='billing'),
|
||||||
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
|
path('bills/<int:pk>/download/', views.BillDownloadView.as_view(), name='bill-download'),
|
||||||
path('profile/', views.ProfileView.as_view(), name='profile'),
|
path('profile/', views.ProfileView.as_view(), name='profile'),
|
||||||
path('profile/setLang/<lang>', views.ProfileSetLang, name='profile'),
|
path('profile/setLang/<code>', views.ProfileSetLang, name='profile-set-lang'),
|
||||||
path('address/', views.MailView.as_view(), name='address-list'),
|
path('address/', views.MailView.as_view(), name='address-list'),
|
||||||
path('address/new/', views.MailCreateView.as_view(), name='address-create'),
|
path('address/new/', views.MailCreateView.as_view(), name='address-create'),
|
||||||
path('address/<int:pk>/', views.MailUpdateView.as_view(), name='address-update'),
|
path('address/<int:pk>/', views.MailUpdateView.as_view(), name='address-update'),
|
||||||
|
|
|
@ -126,12 +126,12 @@ class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def ProfileSetLang(request, lang):
|
def ProfileSetLang(request, code):
|
||||||
# set user language as active language
|
# set user language as active language
|
||||||
|
|
||||||
if any(x[0] == lang for x in settings.LANGUAGES):
|
if any(x[0] == code for x in settings.LANGUAGES):
|
||||||
# http://127.0.0.1:8080/profile/setLang/es
|
# http://127.0.0.1:8080/profile/setLang/es
|
||||||
user_language = lang
|
user_language = code
|
||||||
translation.activate(user_language)
|
translation.activate(user_language)
|
||||||
|
|
||||||
response = HttpResponseRedirect('/dashboard')
|
response = HttpResponseRedirect('/dashboard')
|
||||||
|
|
Loading…
Reference in New Issue