demo12
This commit is contained in:
parent
4100506988
commit
48e73ad92f
Binary file not shown.
@ -42,6 +42,8 @@ SESSION_COOKIE_SECURE = True
|
||||
CSRF_COOKIE_SECURE = True
|
||||
SESSION_COOKIE_SAMESITE = "None"
|
||||
CSRF_COOKIE_SAMESITE = "None"
|
||||
LANGUAGE_COOKIE_SECURE = True
|
||||
LANGUAGE_COOKIE_SAMESITE = "None"
|
||||
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
@ -63,6 +65,7 @@ MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.locale.LocaleMiddleware',
|
||||
'core.middleware.LanguageDebugMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
@ -83,6 +86,7 @@ TEMPLATES = [
|
||||
'OPTIONS': {
|
||||
'context_processors': [
|
||||
'django.template.context_processors.request',
|
||||
'django.template.context_processors.i18n',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
# IMPORTANT: do not remove – injects PROJECT_DESCRIPTION/PROJECT_IMAGE_URL and cache-busting timestamp
|
||||
|
||||
BIN
core/__pycache__/middleware.cpython-311.pyc
Normal file
BIN
core/__pycache__/middleware.cpython-311.pyc
Normal file
Binary file not shown.
14
core/middleware.py
Normal file
14
core/middleware.py
Normal file
@ -0,0 +1,14 @@
|
||||
from django.utils.translation import get_language
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class LanguageDebugMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
response = self.get_response(request)
|
||||
# Log the current language for debugging
|
||||
print(f"DEBUG: Path: {request.path}, Lang: {get_language()}, Cookie: {request.COOKIES.get('django_language')}")
|
||||
return response
|
||||
@ -1,6 +1,7 @@
|
||||
{% load static i18n %}
|
||||
{% get_current_language as CURRENT_LANG %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ request.LANGUAGE_CODE }}" {% if request.LANGUAGE_CODE == 'ar' %}dir="rtl"{% endif %}>
|
||||
<html lang="{{ CURRENT_LANG }}" {% if CURRENT_LANG == 'ar' %}dir="rtl"{% endif %}>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@ -12,7 +13,7 @@
|
||||
|
||||
<!-- Bootstrap 5 CSS -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
{% if request.LANGUAGE_CODE == 'ar' %}
|
||||
{% if CURRENT_LANG == 'ar' %}
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css">
|
||||
{% endif %}
|
||||
|
||||
@ -23,7 +24,7 @@
|
||||
{% block head %}{% endblock %}
|
||||
<style>
|
||||
body { font-family: 'Outfit', sans-serif; background-color: #f8f9fa; }
|
||||
{% if request.LANGUAGE_CODE == 'ar' %}
|
||||
{% if CURRENT_LANG == 'ar' %}
|
||||
body { font-family: 'Cairo', sans-serif; }
|
||||
{% endif %}
|
||||
.navbar { background-color: #0A1D37; }
|
||||
@ -57,13 +58,13 @@
|
||||
|
||||
<li class="nav-item dropdown ms-lg-3">
|
||||
<a class="nav-link dropdown-toggle" href="#" id="langDropdown" role="button" data-bs-toggle="dropdown">
|
||||
<i class="fa-solid fa-globe me-1"></i> {{ request.LANGUAGE_CODE|upper }}
|
||||
<i class="fa-solid fa-globe me-1"></i> {{ CURRENT_LANG|upper }}
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li>
|
||||
<form action="{% url 'set_language' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input name="next" type="hidden" value="{{ request.path }}">
|
||||
<input name="next" type="hidden" value="{{ request.get_full_path }}">
|
||||
<input name="language" type="hidden" value="en">
|
||||
<button type="submit" class="dropdown-item">English</button>
|
||||
</form>
|
||||
@ -71,7 +72,7 @@
|
||||
<li>
|
||||
<form action="{% url 'set_language' %}" method="post">
|
||||
{% csrf_token %}
|
||||
<input name="next" type="hidden" value="{{ request.path }}">
|
||||
<input name="next" type="hidden" value="{{ request.get_full_path }}">
|
||||
<input name="language" type="hidden" value="ar">
|
||||
<button type="submit" class="dropdown-item">العربية</button>
|
||||
</form>
|
||||
@ -148,9 +149,10 @@
|
||||
<p class="text-center text-white-50 mb-0">© 2026 MASAR CARGO. All rights reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
<div class="container text-center text-muted small py-2">Debug: Lang={{ CURRENT_LANG }}, Cookie={{ request.COOKIES.django_language }}</div>
|
||||
|
||||
<!-- Bootstrap 5 JS Bundle -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user