Created
December 14, 2012 08:30
-
-
Save lovevn/4283650 to your computer and use it in GitHub Desktop.
Generating Slugs for Vietnamese language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this gist get from | |
#http://flask.pocoo.org/snippets/5/ | |
import re | |
from unidecode import unidecode | |
_punct_re = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+') | |
def slugify(text, delim=u'-'): | |
"""Generates an ASCII-only slug.""" | |
result = [] | |
for word in _punct_re.split(text.lower()): | |
result.extend(unidecode(word).split()) | |
return unicode(delim.join(result)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment