-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
|
|
@@ -38,6 +39,11 @@ def get_worker_class(worker_class=None): | |
| return worker_class | ||
|
|
||
|
|
||
| def activate_localization(): | ||
| if getattr(settings, 'RQ_USE_LOCALIZATION', False): | ||
|
||
| activate(getattr(settings, 'RQ_LANGUAGE_CODE', django_settings.LANGUAGE_CODE)) | ||
|
|
||
|
|
||
| def get_worker(*queue_names, **kwargs): | ||
| """ | ||
| Returns a RQ worker for all queues or specified ones. | ||
|
|
@@ -49,6 +55,7 @@ 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)) | ||
| activate_localization() | ||
|
||
| return worker_class(queues, | ||
| connection=queues[0].connection, | ||
| exception_handlers=get_exception_handlers() or None, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we rename this to
RQ_USE_L10Nto keep it consistent with Django's naming scheme?RQ_LANGUAGE_CODEdefaults to Django'sLANGUAGE_CODEsetting, should we also change this to default to Django'sUSE_L10Nsetting?