wagtail-localize
wagtail-localize copied to clipboard
.url not working on translated pages
I don't know if this should be in wagtail's issues or not, but here it is.
My main language is Russian(ru-ru).
I tried {{ self.url }}, {% pageurl self %}/{% pageurl self.localized %} with {% load wagtailcore_tags %} on the main home page('/ru') and everything worked as expected. Then I switched to translated home page('/en') and got None from all of the tags.
I also tried these tags on the other templates, on main language(Russian) everything works, but on the other languages it doesn't.
I also tried to get url of the translated page in shell like this:
>>> HomePage.objects.get(locale__language_code="ru").get_children().live().public().first().url,
I got '/ru-ru/%D0%BF%D0%BE%D1%80%D1%82%D1%84%D0%BE%D0%BB%D0%B8%D0%BE/' as expected.
When I replace ru with en, it returns None... And there is actually page present, if I remove .url it returns <Page: Portfolio>.
So .url doesn't work on translated pages.
Hope this helps.
Update:
I realized that problem is in wagtail_localize.locales app, I changed it to wagtail.locales and everything is working now.
Thanks @Shaffle1! Just wondering if you had a cache configured when you had this issue?
@kaedroho Sorry for the late answer. I am not sure, but I think it was not
Edit: Checked, it was not configured at that moment.
I have a related example. Is there any way to get this working? It should display the main menu of the root site page of the activated language, but it just displays stuff in English - both titles and urls.
{% wagtail_site as current_site %}
{% with root_p=current_site.root_page %}
<ul class="navbar-nav ms-auto">
{% for nav in root_p.get_children.specific.live.in_menu %}
<li class="nav-item">
<a class="nav-link{% if page.url == nav.url %} active{% endif %}" href="{{ nav.url }}">{{ nav.title }}</a>
</li>
{% endfor %}
</ul>
{% endwith %}
Sorry, I found the solution now - I need to add .localized. So the example code becomes:
{% wagtail_site as current_site %}
{% with root_p=current_site.root_page %}
<ul class="navbar-nav ms-auto">
{% for nav in root_p.localized.get_children.specific.live.in_menu %}
<li class="nav-item">
<a class="nav-link{% if page.url == nav.url %} active{% endif %}" href="{{ nav.url }}">{{ nav.title }}</a>
</li>
{% endfor %}
</ul>
{% endwith %}
Sounds like this is a documentation task
I've suggested this in work happening to make the bakerydemo translation friendly: https://github.com/olifante/Baeckereidemo/pull/1
Can you share that as a minimal code example @ArnarTumi ?
Sorry, I think this might have been my fault, due to other reasons... I am gonna dig deeper and will let you know if its really related.
Ok @benjaoming this seems to be happening to me for pages that are mirrored, not yet translated, which kinda makes sense. The problem with that is, I get a page object, my search index picks it up, but I am unable to route to it... Maybe .url should return the url of the page being mirrored?
As far as I see this, it is a documentation issue here and Wagtail core. Will happilly review PRs for either/both.
Marking for the next release which aims to look primarily at outstanding issues