slugify with transliteration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re
import translitcodec # needed to install it

from django.template import Library
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe

register = Library()

PUNCT_RE = re.compile(r'[\t !"#$%&\'()*\-/<=>?@\[\\\]^_`{|},.]+')


@stringfilter
def slugify(value, delim=u'-'):
    """
    Generates an ASCII-only slug.
    
    Borrowed from http://flask.pocoo.org/snippets/5/
    """
    result = []
    for word in PUNCT_RE.split(value.lower()):
        word = word.encode('translit/long')
        if word:
            result.append(word)
    return mark_safe(unicode(delim.join(result)))
slugify.is_safe = True

More like this

  1. Using the built-in slugify filter outside a template by jcroft 6 years, 2 months ago
  2. jQuery slugify plugin by girasquid 4 years ago
  3. RecaptchaForm by oggy 4 years, 11 months ago
  4. Markup Selection in Admin by jonathan 5 years, 9 months ago
  5. autotranslatslugify by Ciantic 6 years, 1 month ago

Comments

(Forgotten your password?)