wagtail / wagtail-localize

Translation plugin for Wagtail CMS
https://wagtail-localize.org/
Other
226 stars 86 forks source link

pageurl Template Tag not working with translations #312

Open andre-fuchs opened 3 years ago

andre-fuchs commented 3 years ago

Following your instructions for wagtail-localize and Wagtail Internationalisation I get a fresh install of Wagtail up and running. After setting the second locale via the UI (just following your example with English as default and French), the "home" page is duplicated as expected. So I translate and publish the french version.

After that I added a basic language switcher to the base template, like described in the Wagtail docs. Neither the pageurl template tag, nor page.url property return the correct URL. On the default locale ('en' in my case) both pageurl and page.url return None. On the alternative locale ('fr') both return the french/current URL /fr/.

Via page.url_path I am able to get the path representing the page tree, e.g. /home/. This way I can figure a workaround solution by substituting the top level slug with the locale. But I reckon that this problem is a bug. Or what am I missing?

# settings/base.py

INSTALLED_APPS = [
    'home',
    'search',
    "wagtail_localize",
    "wagtail_localize.locales",  # Note: This replaces "wagtail.locales"
    ...
]

MIDDLEWARE = [
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    ...
]

LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = [
    ("en", "English"),
    ("fr", "French"),
]
# urls.py

from django.conf.urls.i18n import i18n_patterns
from django.conf.urls import url

...

urlpatterns += i18n_patterns(
    url(r"^search/$", search_views.search, name="search"),
    url(r"", include(wagtail_urls)),
)
# templates/base.html

...

<body>
    {% for translation in page.get_translations.live %}
        {{ translation.title }}<br>
        {{ translation.url }}<br>
        {{ translation.url_path }}<br>
        {% pageurl translation %}<br>
    {% endfor %}
</body>
kaedroho commented 3 years ago

@andre-fuchs did you set WAGTAIL_I18N_ENABLED to True in your settings?

zerolab commented 2 years ago

Looks related to #256

zerolab commented 2 years ago

@andre-fuchs I tried replicating this on a more recent version of Wagtail and could not reproduce this. Do (or did) you have WAGTAIL_I18N_ENABLED = True in your settings?