wagtail-localize icon indicating copy to clipboard operation
wagtail-localize copied to clipboard

.url not working on translated pages

Open itekhi opened this issue 4 years ago • 11 comments
trafficstars

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.

itekhi avatar Nov 20 '20 03:11 itekhi

Update: I realized that problem is in wagtail_localize.locales app, I changed it to wagtail.locales and everything is working now.

itekhi avatar Nov 21 '20 05:11 itekhi

Thanks @Shaffle1! Just wondering if you had a cache configured when you had this issue?

kaedroho avatar Feb 16 '21 18:02 kaedroho

@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.

itekhi avatar Feb 27 '21 22:02 itekhi

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 %}

benjaoming avatar May 19 '22 21:05 benjaoming

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 %}

benjaoming avatar May 22 '22 21:05 benjaoming

Sounds like this is a documentation task

zerolab avatar May 23 '22 13:05 zerolab

I've suggested this in work happening to make the bakerydemo translation friendly: https://github.com/olifante/Baeckereidemo/pull/1

benjaoming avatar May 23 '22 21:05 benjaoming

Can you share that as a minimal code example @ArnarTumi ?

benjaoming avatar Jul 13 '22 13:07 benjaoming

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.

ArnarTumi avatar Jul 13 '22 13:07 ArnarTumi

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?

ArnarTumi avatar Jul 13 '22 13:07 ArnarTumi

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

zerolab avatar Oct 15 '22 12:10 zerolab