talha-asad / mongoose-url-slugs

Create URL compatiable slugs on mongoose models, ensuring uniqueness.
MIT License
40 stars 22 forks source link

Work with Chinese, Japanese and Korean characters #31

Closed guoyunhe closed 6 years ago

guoyunhe commented 7 years ago

Currently, mongoose-url-slugs will remove all CJK characters. If the name is totally CJK characters, the slug will become empty.

Here are some node packages that can convert CJK to alphabeta, like Pinyin in Chinese, and Romaji in Japanese. Then they can be convert to slug. For example, the chinese-to-pinyin package can convert Chinese characters to Pinyin:

var pinyin = require("chinese-to-pinyin");
pinyin('今天天气真好', {noTone: true});
// Output:
// jin tian tian qi zhen hao

Pinyin is easy to slugify as English.

talha-asad commented 7 years ago

There are lots of languages with different characters, we cannot support all of them, for this reason the module exposes generator function which you can override and use any transformation you want before the slug is saved.

Give it a try and let me know how it works for you.