For this, you will want to create a specific slug behavior on your model. The specifics are on "How to create a Slug" documentation.
This uses slugify dependency on your endpoint.
Please check the documentation there, you can configure it appropriately to allow a specific locale and or special characters.
Slugify example options:
slugify('some string', {
replacement: '-', // replace spaces with replacement character, defaults to `-`
remove: undefined, // remove characters that match regex, defaults to `undefined`
lower: false, // convert to lower case, defaults to `false`
strict: false, // strip special characters except replacement, defaults to `false`
locale: 'vi', // language code of the locale to use
trim: true // trim leading and trailing replacement chars, defaults to `true`
})
And now on your model JavaScript file:
const slugify = require('slugify');
module.exports = {
/**
* Triggered before user creation.
*/
lifecycles: {
async beforeCreate(data) {
if (data.title) {
data.slug = slugify(data.title, {HERE_YOUR_OPTIONS});
}
},
async beforeUpdate(params, data) {
if (data.title) {
data.slug = slugify(data.title, {HERE_YOUR_OPTIONS});
}
},
},
};
Ref:
https://strapi.io/documentation/developer-docs/latest/guides/slug.html#create-attributes
https://github.com/simov/slugify