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?
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.
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.
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.
It looks like you did not enable django.middleware.locale.LocaleMiddleware.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With