Content Delivery API - How to know which language/...
# help-with-umbraco
l
Hi! I'm working on a POC/demo using the new Content Delivery API and I'm using the
/umbraco/delivery/api/v1/content/item/{path}
endpoint passing in whatever relative url I receive from the browser. I have two cultures, en-US at
/
and pt-PT at
/pt
. If I pass in
/pt
as the path, I do get the content in portuguese, but I don't see an easy way to know which culture I'm receiving... Unless I look at the
cultures
dictionary and see which culture path matches the
route.path
, but that feels a bit meh 😅 As for the use case, I was basically trying to build a language switcher and wanted to know the current culture. (also thinking that in the future I might want to grab translations based on the culture) Anything I am missing? Thanks! 🙂
p
Hi @Laura Neto It looks like there is a cultures property returned but it is empty for me in all cases.
s
Cultures is filled if the doctype is set to
Allow vary by culture
. But since you don't have 1:1 translations (I assume) you won't get that. You will indeed have to rely on the path I think.
I think you can extend the model, but I can't remember how!
Yeah I think you can add a field, I think (from this example)
featured
will show up in the
items
result. So it's basically adding a field to the examine index: https://docs.umbraco.com/umbraco-cms/reference/content-delivery-api/extension-api-for-querying#custom-selector
So in your case, you could consider adding a
culture
field and set it based on what language the parent (or the first ascendant) has set on the
Cultures and hostnames
config.
but I feel like we should have a feature of just outputting the culture as configured on the nearest ascendant node
p
Thanks @Sebastiaan Something else missing that would help is the hostnames but I guess would have to add that in the same way
s
Yep.
p
> but I feel like we should have a feature of just outputting the culture as configured on the nearest ascendant node I agree. I'm actually finding it very limiting at the moment so building my own controllers and trying to utilise as much of the API as I can for future proofing and not reinventing the wheel.
s
but.. you'd have to query the correct domain name to get the correct culture, which feels weird.
what's limiting? not having the cultures and hostnames info?
p
> what's limiting? not having the cultures and hostnames info? The Delivery API, I have another thread I am going to create about another problem I need to solve but don't want to hijack this one
s
What I mean with the correct domain name is that, for example here.. test2.com could be defined as portugal..
p
There seems to be not a lot of conversation around the use of the Delivery API at the moment which I am surprised about but I guess it's still fairly new
s
It's too new. People already on other headless solutions are not there yet. I am still figuring out how to work with it myself, but it's fun! Curious about your other question!
p
l
As far as I am aware there is no documented way to extend the response... The docs I saw only allowed you to add fields to the examine index, but that won't make it so they are exposed in the API. I did find a way to do it eventually, but a bit hacky... 😅 If there is an easy way to do it, would love to hear it!
(I was also trying to add a field in order to get the breadcrumbs of a page (without having to ask for all the ascendants and get all that unnecessary data)
s
I remember from Kenn's talk now that a hacky way to do it is to implement your own property editor that does nothing on the node, but it adds a property for which you can make a property value converter and in that you can return any data you want.
l
I did not do that, I found a way to "extend" the code that builds the model, but I will try to give that one a try 👍
2 Views