I'm currently working on a Django application that includes various functionalities, including notification delivery, in multiple languages. While most of the application works well with Arabic and other languages, I'm facing an issue with Arabic translations in certain parts of the application, including notifications. The Arabic translations are not being displayed correctly, while translations in other languages, such as English and French, work without any issues.
Here are the details of my setup:
The application uses Django and Celery for task management and background processing. I have added Arabic translations for different text elements in the respective translation files. The Arabic translations work fine in most parts of the application, including UI labels and content. However, when it comes to notifications, specifically in Arabic, the translations are not displayed correctly. Other functionalities, such as database operations, user management, and data processing, work as expected with the Arabic translations.
I have ensured that the necessary translations are present, and the language preferences are correctly set for affected users. The issue seems to be specific to the notification tasks triggered by certain actions or events. It's puzzling because the Arabic translations work well in other areas of the application.
I would greatly appreciate any guidance or suggestions on how to investigate and resolve this issue. Is there any specific configuration, setup, or code implementation that I might be missing to ensure consistent and accurate Arabic translations in all parts of the application, including notifications?
ps i got the arabic once when the order took some time i'm thinking it might be celery issue racing or something here som details from my code `
@shared_task
def send_notification_fill_stage_infos():
to_be_filled_status = Status.objects.get(
name_eng=OrderResultStatusList.TO_BE_FILLED
)
order_results_to_be_filled = OrderResult.objects.filter(status=to_be_filled_status)
date = timezone.now()
notification_sent = []
for order_result in order_results_to_be_filled:
primary_order = order_result.primary_order
try:
fertisat_result = FertisatResult.objects.get(order=order_result)
order_stage = fertisat_result.ferti_stage_order_detail.fertigation_stage
except FertisatResult.DoesNotExist:
continue
stage = order_stage
previous_order_result = None
previous_fertistage_order_detail = None
n_stage_before = 1
while previous_order_result is None:
try:
previous_stage = FertigationStage.objects.get(next_stage=stage)
except FertigationStage.DoesNotExist:
break
try:
previous_fertisat_result = FertisatResult.objects.get(
order__primary_order=primary_order,
ferti_stage_order_detail__fertigation_stage=previous_stage,
)
except FertisatResult.DoesNotExist:
n_stage_before += 1
stage = previous_stage
continue
previous_order_result = previous_fertisat_result.order
previous_fertistage_order_detail = (
previous_fertisat_result.ferti_stage_order_detail
)
if previous_order_result is None:
continue
if previous_order_result.status == to_be_filled_status:
continue
n_days_between_stages = n_stage_before * settings.MIN_DAYS_BETWEEN_STAGES
if (
date - previous_fertistage_order_detail.fertilization_date
).days >= n_days_between_stages:
try:
user_lang = User.objects.get(pk=primary_order.user).config.lang
except Exception:
user_lang = 'en'
with translation.override(user_lang):
if user_lang == 'fr':
fertigation_stage_name = order_stage.name_fr
elif user_lang == 'ar':
fertigation_stage_name = order_stage.name_ar
else:
fertigation_stage_name = order_stage.name_en
notification_message = (
settings.FERTISTAGE_FILL_INFO_NOTIFICATION.format(
fertigation_stage_name, primary_order.plot.name
)
)
translated_message = str(notification_message)
data = {
'object_type': 'FERTISAT',
'object_id': order_result.id,
'plot_id': primary_order.plot.id,
'fertisat_result_id': fertisat_result.id,
'fertistage_order_detail_id': fertisat_result.ferti_stage_order_detail.id,
'stage_name_translated': fertigation_stage_name,
'stage_id': order_stage.pk,
'event': 'OTF',
'title': translated_message,
'primary_order_id': order_result.primary_order.id,
}
time.sleep(10)
notif_tasks.notify_user_async.delay(
obj_id=order_result.id,
obj_type=order_result.__class__.__name__,
user_id=primary_order.user,
message=translated_message,
data=data,
action=NotificationActions.FILL_STAGE_INFOS,
)
notification_sent.append(order_result.id)
return {'notification sent for': notification_sent}
celery.py
`from celery import Celery
from dst_api import celery_config
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dst_api.settings')
celery_app = Celery('dst_api')
celery_app.config_from_object(celery_config)
celery_app.autodiscover_tasks()
celery_app.conf.task_routes = {'weather.tasks.*': {'queue': 'weather'}}`
celery_config.py `
import os
rabbitmq_user = os.getenv('RABBITMQ_DEFAULT_USER', 'guest')
rabbitmq_password = os.getenv('RABBITMQ_DEFAULT_PASS', 'guest')
rabbitmq_host = os.getenv('RABBITMQ_HOST', 'rabbitmq')
broker_url = 'amqp://{user}:{password}@{host}:5672//'.format(
user=rabbitmq_user, password=rabbitmq_password, host=rabbitmq_host
)
result_backend = 'rpc://{user}:{password}@{host}:5672//'.format(
user=rabbitmq_user, password=rabbitmq_password, host=rabbitmq_host
)
timezone = 'Europe/Paris'
worker_send_task_events = True
task_send_sent_event = True
task_acks_late = False
task_reject_on_worker_lost = False
task_acks_on_failure_or_timeout = False
worker_lost_wait = 100
i tried a lot of things checking all configurations on all the project but i still missing something
some conf from settings.py
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en'
# Supported languages.
LANGUAGES = (
('ar', 'Arabic'),
('en', 'English'),
('fr', 'French'),
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.common.CommonMiddleware',
'users.middleware.app_version_middleware.AppVersionMiddleware',
"users.middleware.appconfigmiddleware.AppendTokenMiddleware",
"users.middleware.appconfigmiddleware.LanguageConfigMiddleware",
]
some conf from .po file generated
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR Saad Mrabet, 2022.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-01-16 09:08+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Saad Mrabet [email protected]\n"
"Language-Team: Arbic <[email protected]>\n"
"Language: ar\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 "
"&& n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n"
#: action/models.py:10
msgid "Advice"
msgstr "نصيحة"
#: action/models.py:11
msgid "Phytosanitary"
msgstr "صحة نباتية"