Skip to content

Add localization activation ability #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions django_rq/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@

# Token for querying statistics
API_TOKEN = getattr(settings, 'RQ_API_TOKEN', '')

# Activate locale for each task
RQ_USE_L10N = getattr(settings, 'RQ_USE_L10N', settings.USE_L10N)
# Use specified language code to activate locale
RQ_LANGUAGE_CODE = getattr(settings, 'RQ_LANGUAGE_CODE', settings.LANGUAGE_CODE)
9 changes: 6 additions & 3 deletions django_rq/workers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.conf import settings as django_settings
from django.utils import six
from django.utils.translation import activate
from rq import Worker
from rq.utils import import_attribute

from django.conf import settings
from django.utils import six

from . import settings
from .jobs import get_job_class
from .queues import filter_connection_params, get_connection, get_queues

Expand Down Expand Up @@ -49,6 +50,8 @@ def get_worker(*queue_names, **kwargs):
# normalize queue_class to what get_queues returns
queue_class = queues[0].__class__
worker_class = get_worker_class(kwargs.pop('worker_class', None))
if settings.RQ_USE_L10N:
activate(getattr(settings, 'RQ_LANGUAGE_CODE', django_settings.LANGUAGE_CODE))
return worker_class(queues,
connection=queues[0].connection,
exception_handlers=get_exception_handlers() or None,
Expand Down