Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to request entities in a specific locale #98

Open
OldhamMade opened this issue Jun 7, 2021 · 1 comment
Open

Unable to request entities in a specific locale #98

OldhamMade opened this issue Jun 7, 2021 · 1 comment

Comments

@OldhamMade
Copy link
Contributor

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.

@OldhamMade
Copy link
Contributor Author

OldhamMade commented Jun 7, 2021

Ok, digging into this a bit further, I can see there are 2 options:

  1. Add another "filtering" function akin to by and content_type
  2. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants