I'm using Django 1.5.
I have setup internationalization in the project and has set up following variables in the settings.py file
LANGUAGE_CODE = 'en'
LANGUAGES = (
('en', 'English'),
('es', 'Spanish')
)
and the urls.py file contians
urlpatterns += i18n_patterns('',
url(r'^', include(app_urlpatterns)),
)
But this appends en to every URL like
https://example.com/en/dashboard
I want to hide the default language from the URL pattern.
I tried putting prefix_default_language=False in the url pattern
urlpatterns += i18n_patterns('',
url(r'^', include(app_urlpatterns)),
prefix_default_language=False
)
But this gives error as
i18n_patterns() got an unexpected keyword argument 'prefix_default_language'
How can I hide default language prefix from the URL in Django 1.5?
As far as I can understand from docs, by default there is no support for
prefix_default_languagein django 1.5. So either you need to discard the idea of using that, or you need to implement that on your own. If you choose latter option, you need to create a newi18n_patternsfunction, also need to updateLocaleRegexURLResolverinside that. For example:Now, you need to use
CustomLocaleRegexURLResolverin customi18n_patterns, like this:Finally, use this in your url:
Implementation has been done based on code available here.