Add unidecode for translating slugs in asian languages

This commit is contained in:
Leonard Huang 2012-07-16 11:36:20 +08:00
commit 6f40e452e1
3 changed files with 6 additions and 2 deletions

View file

@ -49,6 +49,8 @@ def slugify(value):
value = Markup(value).striptags()
if type(value) == unicode:
import unicodedata
from unidecode import unidecode
value = unicode(unidecode(value))
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = unicode(re.sub('[^\w\s-]', '', value).strip().lower())
return re.sub('[-\s]+', '-', value)