Skip to content

Instantly share code, notes, and snippets.

@shunfan
Last active June 25, 2017 20:18
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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