Skip to content
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

Merged
merged 12 commits into from
May 1, 2017
Merged

added i18n feature to enable i18n and internationalized url prefixes #21

merged 12 commits into from
May 1, 2017

Conversation

dodo1708
Copy link
Contributor

@dodo1708 dodo1708 commented Apr 6, 2017

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

Dominik Halle added 3 commits April 6, 2017 16:44
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
Copy link
Owner

@henzk henzk left a 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.

@@ -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
Copy link
Owner

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


# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
Copy link
Owner

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
Copy link
Owner

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
"""

Copy link
Owner

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)
Copy link
Owner

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

Copy link
Owner

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

Copy link
Owner

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).

@@ -95,7 +95,6 @@
TEMPLATE_CONTEXT_PROCESSORS = [
"django.contrib.auth.context_processors.auth",
"django.template.context_processors.debug",
"django.template.context_processors.i18n",
Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yipi 😄

Dominik Halle added 9 commits April 24, 2017 15:52
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
@henzk
Copy link
Owner

henzk commented May 1, 2017

awesome ... thx!

@henzk henzk merged commit 0794bd2 into henzk:master May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants