simov / slugify

Slugifies a string
MIT License
1.51k stars 129 forks source link

Add (Persian/Farsi) locale #89

Open deasurv opened 4 years ago

deasurv commented 4 years ago

Hi. Thanks for your work!

Please add Persian (or Farsi) support to locales.

simov commented 4 years ago

Hi @deasurv, locales are being added only when the existing transliteration in the main charmap file conflicts with a letter from that specific locale. So if you are a native speaker and you spot some incorrectly transliterated characters, then open up a PR and add the offending characters in a [locale].json file.

Trott commented 4 years ago

I don't think slugify supports Farsi characters (yet?) so I think the addition needs to happen in charmap.json?

$ cat index.js 
const slugify = require('slugify');
console.log(slugify('سلام دنیا'));
$ node index.js

$

The slug module has support for Farsi so that's an option.

$ cat index.js 
const slug = require('slugify');
console.log(slug('سلام دنیا'));
$ node index.js
slam-dnia
$

Not perfect, but possibly usable? (I don't know Farsi or Arabic, but a quick web search indicates that the greeting is typically transliterated as "salam" with some diacritics. Looks like it gives "slam" instead here.)

To get Farsi characters into slugify, I think all that's needed is to copy the character map from https://github.com/Trott/slug/blob/6fe210016d7da58856594891f47b8258ce11c4a1/slug.js#L486-L523 into https://github.com/simov/slugify/blob/master/config/charmap.json. I don't know if there are criteria about what gets included and omitted from charmap.json in slugify but it seems to be "whatever people need within reason". Anyway, adding Farsi and Arabic to slugify would be great (in my opinion).

(Full disclosure: I'm the current maintainer of slug. But I ❤️ slugify and you should totally use it.)