strapi slug Hebrew character support

Viewed 407

I am having an issue finding any documentation regarding allowing the strapi slug filter manipulation I would like to allow it to whitelist Hebrew characters.

at current state when trying to change the characters to Hebrew i get the error "This does not match the format"

2 Answers

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

In version 4 of strapi this become a none issue it now supports all languages

Related