willhardy / django-seo

Provides a set of tools for managing Search Engine Optimisation (SEO) for Django sites.
BSD 3-Clause "New" or "Revised" License
251 stars 117 forks source link

When using i18n_patterns, every path is prefixed with the current language so it can have several versions #34

Open mandx opened 12 years ago

mandx commented 12 years ago

If in your Django has several languages configured, and your root URLConf is using the new i18n_patterns, then every path under that urlpatterns setup can have two or more versions. Currently, DjangoSEO assumes that every get_absolute_url call will return an unique URL, when that's not the case for multilingual projects.

For instance, when i18n_patterns is active, a call to get_absolute_url can return /en/objects/myobject_slug/ or /de/objects/myobject_slug/, depending on the current request language.

The result of every call to get_absolute_url (or when using request.path) should be unprefixed from the current language, before using it as "key" to save the metadata instance.

danigosa commented 10 years ago

The workaround is using the views Backend using named views.

Add your seo model:

Meta: use_i18n = True seo_views = ("your_view_name",)

Then add two views in the admin, each with a different language from the dropdown.

In your view, add a context parameter like that:

{"view_name": "your_view_name"}

In the template use the following:

{% get_metada for view_name in LANGUAGE_CODE %}

Eh voilà.