Skip to content

Instantly share code, notes, and snippets.

@shunfan
Last active June 25, 2017 20:18
Show Gist options
  • Save shunfan/5847732 to your computer and use it in GitHub Desktop.
Save shunfan/5847732 to your computer and use it in GitHub Desktop.
Slugify Chinese
# coding=utf-8
"""
Slugify for Chinese
没有优化多音字
优化多音字的项目有:
https://github.com/jiedan/chinese_pinyin
"""
import re
import unidecode
def slugify(str):
return re.sub(r'\s+', '-', unidecode.unidecode(str).lower().strip())
# Test
print slugify(u"测试")
# >>> ce-shi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment