From 4a324ba7acd2660538a81b1fb423de89ff515665 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sat, 1 Jul 2006 03:09:14 +0000 Subject: [PATCH] Added USE_I18N setting, which lets you turn off internationalization overhead with a single setting. Defaults to True. Currently only affects the admin i18n JavaScript, but I'll be adding other optimizations. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3247 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/conf/global_settings.py | 4 ++++ django/contrib/admin/urls.py | 10 +++++++++- django/views/i18n.py | 8 +++++++- docs/i18n.txt | 15 ++++++++++++++- docs/settings.txt | 10 ++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py index a1dff3c815..ab09f364fb 100644 --- a/django/conf/global_settings.py +++ b/django/conf/global_settings.py @@ -67,6 +67,10 @@ LANGUAGES = ( # Languages using BiDi (right-to-left) layout LANGUAGES_BIDI = ("he",) +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + # Not-necessarily-technical managers of the site. They get broken link # notifications and other various e-mails. MANAGERS = ADMINS diff --git a/django/contrib/admin/urls.py b/django/contrib/admin/urls.py index a2d3ccae48..bd894d8de1 100644 --- a/django/contrib/admin/urls.py +++ b/django/contrib/admin/urls.py @@ -1,9 +1,15 @@ +from django.conf import settings from django.conf.urls.defaults import * +if settings.USE_I18N: + i18n_view = 'django.views.i18n.javascript_catalog' +else: + i18n_view = 'django.views.i18n.null_javascript_catalog' + urlpatterns = patterns('', ('^$', 'django.contrib.admin.views.main.index'), ('^r/(\d+)/(.*)/$', 'django.views.defaults.shortcut'), - ('^jsi18n/$', 'django.views.i18n.javascript_catalog', {'packages': 'django.conf'}), + ('^jsi18n/$', i18n_view, {'packages': 'django.conf'}), ('^logout/$', 'django.contrib.auth.views.logout'), ('^password_change/$', 'django.contrib.auth.views.password_change'), ('^password_change/done/$', 'django.contrib.auth.views.password_change_done'), @@ -29,3 +35,5 @@ urlpatterns = patterns('', ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'), ) + +del i18n_view diff --git a/django/views/i18n.py b/django/views/i18n.py index a2bc54c9ed..80fc04d170 100644 --- a/django/views/i18n.py +++ b/django/views/i18n.py @@ -104,6 +104,13 @@ function interpolate(fmt, obj, named) { } """ +def null_javascript_catalog(request, domain=None, packages=None): + """ + Returns "identity" versions of the JavaScript i18n functions -- i.e., + versions that don't actually do anything. + """ + return http.HttpResponse(NullSource + InterPolate, 'text/javascript') + def javascript_catalog(request, domain='djangojs', packages=None): """ Returns the selected language catalog as a javascript library. @@ -191,4 +198,3 @@ def javascript_catalog(request, domain='djangojs', packages=None): src.append(InterPolate) src = ''.join(src) return http.HttpResponse(src, 'text/javascript') - diff --git a/docs/i18n.txt b/docs/i18n.txt index 1220ea95b3..1382d6df0c 100644 --- a/docs/i18n.txt +++ b/docs/i18n.txt @@ -35,12 +35,25 @@ How to internationalize your app: in three steps support. 3. Activate the locale middleware in your Django settings. - .. admonition:: Behind the scenes Django's translation machinery uses the standard ``gettext`` module that comes with Python. +If you don't need internationalization +====================================== + +Django's internationalization hooks are on by default, and that means there's a +bit of i18n-related overhead in certain places of the framework. If you don't +use internationalization, you should take the two seconds to set +``USE_I18N = False`` in your settings file. If ``USE_I18N`` is set to +``False``, then Django will make some optimizations so as not to load the +internationalization machinery. + +See the `documentation for USE_I18N`_. + +.. _documentation for USE_I18N: http://www.djangoproject.com/documentation/settings/#use-i18n + How to specify translation strings ================================== diff --git a/docs/settings.txt b/docs/settings.txt index 553736b280..7832569455 100644 --- a/docs/settings.txt +++ b/docs/settings.txt @@ -738,6 +738,16 @@ A boolean that specifies whether to output the "Etag" header. This saves bandwidth but slows down performance. This is only used if ``CommonMiddleware`` is installed (see the `middleware docs`_). +USE_I18N +-------- + +Default: ``True`` + +A boolean that specifies whether Django's internationalization system should be +enabled. This provides an easy way to turn it off, for performance. If this is +set to ``False, Django will make some optimizations so as not to load the +internationalization machinery. + YEAR_MONTH_FORMAT -----------------