mirror of
				https://github.com/django/django.git
				synced 2025-10-31 03:54:51 +00:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									c81d69354a
								
							
						
					
					
						commit
						4a324ba7ac
					
				
					 5 changed files with 44 additions and 3 deletions
				
			
		|  | @ -67,6 +67,10 @@ LANGUAGES = ( | ||||||
| # Languages using BiDi (right-to-left) layout | # Languages using BiDi (right-to-left) layout | ||||||
| LANGUAGES_BIDI = ("he",) | 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 | # Not-necessarily-technical managers of the site. They get broken link | ||||||
| # notifications and other various e-mails. | # notifications and other various e-mails. | ||||||
| MANAGERS = ADMINS | MANAGERS = ADMINS | ||||||
|  |  | ||||||
|  | @ -1,9 +1,15 @@ | ||||||
|  | from django.conf import settings | ||||||
| from django.conf.urls.defaults import * | 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('', | urlpatterns = patterns('', | ||||||
|     ('^$', 'django.contrib.admin.views.main.index'), |     ('^$', 'django.contrib.admin.views.main.index'), | ||||||
|     ('^r/(\d+)/(.*)/$', 'django.views.defaults.shortcut'), |     ('^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'), |     ('^logout/$', 'django.contrib.auth.views.logout'), | ||||||
|     ('^password_change/$', 'django.contrib.auth.views.password_change'), |     ('^password_change/$', 'django.contrib.auth.views.password_change'), | ||||||
|     ('^password_change/done/$', 'django.contrib.auth.views.password_change_done'), |     ('^password_change/done/$', 'django.contrib.auth.views.password_change_done'), | ||||||
|  | @ -29,3 +35,5 @@ urlpatterns = patterns('', | ||||||
|     ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), |     ('^([^/]+)/([^/]+)/(.+)/delete/$', 'django.contrib.admin.views.main.delete_stage'), | ||||||
|     ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'), |     ('^([^/]+)/([^/]+)/(.+)/$', 'django.contrib.admin.views.main.change_stage'), | ||||||
| ) | ) | ||||||
|  | 
 | ||||||
|  | del i18n_view | ||||||
|  |  | ||||||
|  | @ -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): | def javascript_catalog(request, domain='djangojs', packages=None): | ||||||
|     """ |     """ | ||||||
|     Returns the selected language catalog as a javascript library. |     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.append(InterPolate) | ||||||
|     src = ''.join(src) |     src = ''.join(src) | ||||||
|     return http.HttpResponse(src, 'text/javascript') |     return http.HttpResponse(src, 'text/javascript') | ||||||
| 
 |  | ||||||
|  |  | ||||||
|  | @ -35,12 +35,25 @@ How to internationalize your app: in three steps | ||||||
|        support. |        support. | ||||||
|     3. Activate the locale middleware in your Django settings. |     3. Activate the locale middleware in your Django settings. | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| .. admonition:: Behind the scenes | .. admonition:: Behind the scenes | ||||||
| 
 | 
 | ||||||
|     Django's translation machinery uses the standard ``gettext`` module that |     Django's translation machinery uses the standard ``gettext`` module that | ||||||
|     comes with Python. |     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 | How to specify translation strings | ||||||
| ================================== | ================================== | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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`` | bandwidth but slows down performance. This is only used if ``CommonMiddleware`` | ||||||
| is installed (see the `middleware docs`_). | 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 | YEAR_MONTH_FORMAT | ||||||
| ----------------- | ----------------- | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Adrian Holovaty
						Adrian Holovaty