Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Django's new i18n_patterns: How to fall back to the default language specified in the settings module?

I'm using the new i18n_patterns of Django 1.4:

from django.conf.urls import patterns, include, url
from django.conf.urls.i18n import i18n_patterns

from django.contrib import admin
admin.autodiscover()

urlpatterns += i18n_patterns('',
    url(r'^admin/', include(admin.site.urls)),
)

It works for every active language:

/en/admin/ # Ok
/es/admin/ # Ok

But this fails:

/admin/ # 404 Not found

How to avoid the 404 error and redirect to a language-prefixed version of the requested URL (not only the admin panel)?

Is to write a custom middleware the solution? Why this doesn't come by default in Django?

like image 267
Armando Pérez Marqués Avatar asked Jun 11 '12 23:06

Armando Pérez Marqués


People also ask

How to translate in Django?

In order to make a Django project translatable, you have to add a minimal number of hooks to your Python code and templates. These hooks are called translation strings.

Which among the given below internationalization function in Django marks a string as a translation string without actually translating it at that moment?

Lazy Translation utils. translation. ugettext_lazy() to translate strings lazily – when the value is accessed rather than when the ugettext_lazy() function is called. In this example, ugettext_lazy() stores a lazy reference to the string – not the actual translation.

What is Django po?

PO file is a portable object file, which is text-based. These types of files are used in common in software development. The . PO file may be referenced by Java programs, GNU gettext, or other software programs as a properties file. Django uses gettext to interact with translation PO and mo files.


1 Answers

It looks like you did not enable django.middleware.locale.LocaleMiddleware.

like image 158
jpic Avatar answered Nov 15 '22 19:11

jpic