contentful.ex
contentful.ex copied to clipboard
Unable to request entities in a specific locale
Right now there's no way to specify what locale should be used for the requested entities. Everything always comes back in the primary locale as defined in the Contentful interface.
Ok, digging into this a bit further, I can see there are 2 options:
- Add another "filtering" function akin to
by
andcontent_type
- Set the param
locale=*
for all requests, and change the result structs appropriately
Option 2 would mean that all locale data is always returned, which could be useful, but would mean all responses are "heavy" and the user has to implement fallback logic for missing values. The structs would need to change to match this, which I don't think would be backwards-compatible and would require a version bump. So I don't think this is a valid option.
I've got a local working version of option 1, implementing a method named using_locale/1
:
Contentful.Delivery.Entries |> Contentful.Query.using_locale("fr") |> Contentful.Query.fetch_all()
I'm not sure how I feel about this solution. It works, but it does require remembering to set it whenever making a request. I suppose that isn't too onerous. Maybe it's just the name I don't like… apply_locale
or with_locale
might be better, or try_locale
/attempt_locale
to imply the fallback if the locale isn't available… I dunno. Suggestions welcome!
Either way, I can't raise a PR for this until #97 is merged since I need both changes for the work I'm doing. I'll happily raise a PR for this code once #97 is merged.