wagtailtrans
wagtailtrans copied to clipboard
Using wagtail headless API
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?
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?
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.