Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cream.util.string.slugify #3

Open
kkris opened this issue Apr 19, 2011 · 2 comments
Open

Improve cream.util.string.slugify #3

kkris opened this issue Apr 19, 2011 · 2 comments
Assignees

Comments

@kkris
Copy link
Member

kkris commented Apr 19, 2011

I would like to use this little snippet from Armin Ronacher, because it produces real nice slugs and e.g. converts ö to oe instead of o or -- like it is doing now.
But to use this we need http://pypi.python.org/pypi/translitcodec as a dependency.

import re
import translitcodec

_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()):
        word = word.encode('translit/long')
        if word:
            result.append(word)
    return unicode(delim.join(result))
@ghost ghost assigned kkris Apr 19, 2011
@jonashaag
Copy link
Contributor

-1 as slugify isn't used for stuff users see but just for file names (which are an implementation detail)

@kkris
Copy link
Member Author

kkris commented Apr 20, 2011

yeah, but the current implementation has some pitfalls, as "ö", "ä" and "ü" result in the same string.

e.g. it is possible to have two different profiles (think of "hülle", "hölle") which result in the same filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants