-
Notifications
You must be signed in to change notification settings - Fork 183
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Looks good to me
singularName: 'article', | ||
pluginOptions: { | ||
i18n: { | ||
locale: 'fr', // Only fetch a specific locale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also provide an array of locales right? Don't know if it's worth mentioning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible, it's either one locale or "all" to fetch everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with an array ["fr", "en"]
and seemed to work but I'm not sure if it is defaulting to 'all' or fetching what is specified in the array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked and it seems to work indeed. But I see no mention of this in the Strapi i18n docs, so maybe we shouldn't document it either
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed 👍
What this does:
First, I check if a content type has
pluginOptions.i18n.locale
defined. If it does, for collection types I set that value as thelocale
query param. For single types types, I do the same, except if the locale is "all", because it's not supported for single types in Strapi.So in this case, I populate the localizations key in order to get the list of all available locales for a single type. Then, I make a dedicated request for each of these locales, so that they have the same response (level of population etc.) as the base request. I then merge all the localizations together with the default one.
How to test it: