Hello, I’d like to ask you for help or suggestions on how our content team can manage efficiently the relations when working with languages different from the default.
Our content is available in 4 different languages: English, Thai, Russian and Chinese.
We are using relations to create content categories and subcategories and we have commissioned the category’s translations to an external translation service.
The problem comes when we create new content and we need to assign a category or subcategory, because nobody is able to read Chinese (for example).
It would be great to have the “default” language in brackets near the relations.
Do you have any idea how we can achieve that?
I know a way how to do this it is realy hacky you can overwrite the relationship display by doing the following.
module.exports = (config, { strapi }) => {
// Add your own logic here.
return async (ctx, next) => {
await next();
if (
ctx.request.method == "GET" &&
ctx.request.url.startsWith(
"/content-manager/relations/course.course-navigation-section/training_pages"
)
) {
let { entityId, idsToInclude, idsToOmit } = ctx.request.query;
if (idsToInclude === undefined) {
idsToInclude = [];
}
if (idsToOmit === undefined) {
idsToOmit = [];
}
const entry = await strapi.entityService.findPage(
"api::training-page.training-page",
{
...ctx.request.query,
filters: {
$and: [
{
id: allowedPages,
},
{
id: idsToInclude,
},
],
},
fields: ["id",mainField, "publishedAt"],
}
);
return (ctx.response.body = entry);
}
};
};
You could use this and change the entiry mainField to what ever you want or add what you want by for example doing an other quary and getting the english translation
1 Like
Hi @Boegie19 thanks a lot for your input. I have very beginner and trying to understand how I can customize the Strapi backend via code.
Can you please give me more tips on which file should I define this function? Should I create a custom controller or a custom route, or is it something I need to add to the Strapi config folder?
It then mind be easyer for you to join the discord and join the vc since that would be faster.
But to answer your question the code I send above needs to be a global middleware.