-
Notifications
You must be signed in to change notification settings - Fork 6
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
added i18n feature to enable i18n and internationalized url prefixes #21
Conversation
this feature also adds the LocaleMiddlware and the i18n context processor It introduces the LANGUAGES setting and refines the root_urlconf to internationalize the urls Added *args to the run_product_test task to enable all the django test args or args from third party testing tools like django-test-without-migrations
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.
Thank you!
Generally i think this is a great addition to django_productline.
I have added some comments inline.
django_productline/settings.py
Outdated
@@ -38,11 +38,11 @@ | |||
|
|||
# If you set this to False, Django will make some optimizations so as not | |||
# to load the internationalization machinery. | |||
USE_I18N = True |
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.
leave this set to True, otherwise this impacts all available products
django_productline/settings.py
Outdated
|
||
# If you set this to False, Django will not format dates, numbers and | ||
# calendars according to the current locale. | ||
USE_L10N = True |
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.
same as above
@@ -0,0 +1,8 @@ | |||
# coding: utf-8 |
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.
Let's keep the i18n machinery turned on by default in django_productline base feature.
How about calling this feature "multilang", because it will enable use-cases where the language needs to be customizable depending on the user that is visiting the application.
|
||
return get_urls | ||
""" | ||
|
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.
Please add this docstring to the sphinx docs using the autodoc extension. See section on ape tasks for an example on how to do this.
from django.conf.urls.i18n import i18n_patterns | ||
from django_productline import urls | ||
|
||
urlpatterns = i18n_patterns(*urls.get_urls(), prefix_default_language=True) |
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.
would it be possible to have a setting, so we could configure prefix_default_language?
] | ||
|
||
return original | ||
|
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.
I think it would be better to refine only TEMPLATE_CONTEXT_PROCESSORS "in situ" i.e. changing the existing original, not reassigning a new instance to the refined name.
That way, we do not break installations with django < 1.9.
(In the future, we should investigate how situations like this could be handled in a more elegant way)
def refine_MIDDLEWARE_CLASSES(original): | ||
original.insert(2, 'django.middleware.locale.LocaleMiddleware') | ||
return original | ||
|
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.
This refinement is brittle because LocaleMiddleware is always inserted at index 2. If i remember correctly, there are some constraints on the position where the LocaleMiddleware needs to be placed (e.g. "needs to be after CommonMiddleware").
Therefore, this refinement needs to make sure that the conditions hold (by inspecting the original, injecting LocaleMiddleware at a valid position).
django_productline/settings.py
Outdated
@@ -95,7 +95,6 @@ | |||
TEMPLATE_CONTEXT_PROCESSORS = [ | |||
"django.contrib.auth.context_processors.auth", | |||
"django.template.context_processors.debug", | |||
"django.template.context_processors.i18n", |
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.
same as above
""" | ||
features = featuremonkey.get_features_from_equation_file(os.environ['PRODUCT_EQUATION_FILENAME']) | ||
args = ['test'] + features | ||
base_args = ['test'] + features | ||
args = base_args + list(args) |
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.
yipi 😄
changes as described in the pull requests comments, except the sphinx docs
moved admin urls to separate module to make it refineable removed root_urlconf from multilanguage and instead added refineable get_multilang_urls made admin i18n optional removed weird append-slash stuff from get_urls in djpl-admin
…ltilanguage feature doesn't depend on it. updated docs
awesome ... thx! |
also finally added the args for the run_product_tests task
Changed some standard settings of django productline which will be set correctly in the new feature