Login

slugify with transliteration

Author:
jezdez
Posted:
November 26, 2010
Language:
Python
Version:
Not specified
Tags:
slug slugify special chars trans transliteration umlauts
Score:
1 (after 1 ratings)

This slugify correctly transliterates special characters using the translitcodec package from PyPI.

Make sure you've installed http://pypi.python.org/pypi/translitcodec/ before using this.

 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. jQuery slugify plugin by girasquid 6 years ago
  2. Slugify alternative by exogen 8 years, 1 month ago
  3. autotranslatslugify by Ciantic 8 years, 1 month ago
  4. Better slugify by mmajcher 3 years, 6 months ago
  5. slug_and_slash_to_dash - modified slugify for urls by bradmontgomery 4 years, 8 months ago

Comments

Please login first before commenting.