Localization in custom controller

I’m trying to use a custom contoller (for a single type) with internationalized data.
Without any custom scripts everything works like expected:

GET: /my_single_type?_locale=en

returns the en-data,

GET: /my_single_type?_locale=fr

returns the fr-data.

When copy&paste the controller logic from the docs (single type | find) all locales return the default language content.

const { sanitizeEntity } = require('strapi-utils');
module.exports = {
    async find(ctx) {
        const entity = await strapi.services.my_single_type.find();
        return sanitizeEntity(entity, { model: strapi.models.my_single_type});
    }
};

How can I create custom controller logic for localized data?

1 Like

I found the problem. It was the missing ctx.query in find():

const entity = await strapi.services.my_single_type.find(ctx.query);
1 Like