wagtail / wagtailtrans

A Wagtail add-on for supporting multilingual sites
http://wagtailtrans.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
104 stars 60 forks source link

Using wagtail headless API #165

Open onno-timmerman opened 5 years ago

onno-timmerman commented 5 years ago

When I go to http://localhost:8000/api/v2/pages I only get results from one language. There is no mention in the docs how to handle the API with wagtail trans. How do you switch the language when using wagtail api?

mikedingjan commented 5 years ago

Hi @onno-timmerman ,

In the basics watailtrans (if configured right) is only a tool which makes it easier for site administrators to have multiple languages. Each language will have it's own page tree, which means all "homepages" are a child of the "root_page". so they all have their own id and you should be able to query the right pages as children of the site "homepage" TranslatableSiteRoot.. During development we didn't do anything for the API part of Wagtail since they're seperate page trees.

Having said that I must honestly say I don't know how the API handles this, but what I can say is that the TranslatableSiteRoot will select the right HomePage according to request.LANGUAGE_CODE kinda like django's LocaleMiddelware does.

Maybe you can share a bit more about your setup so helping you getting the right pages via API or determine where the problem lies would be a bit easier?

onno-timmerman commented 5 years ago

I solved the issue by first query for the language what the homepage is by passing slug=lang then fetching all the childs of it. I think that is correct way to handle it. I just expected that in /pages all the items would be available and not from one language.