https://github.com/mozilla/unicode-slugify
A slugifier that works in unicode
https://github.com/mozilla/unicode-slugify
Last synced: 6 months ago
JSON representation
A slugifier that works in unicode
- Host: GitHub
- URL: https://github.com/mozilla/unicode-slugify
- Owner: mozilla
- License: bsd-3-clause
- Created: 2011-03-24T23:08:09.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2024-01-27T19:38:22.000Z (almost 2 years ago)
- Last Synced: 2025-05-08T19:25:51.965Z (6 months ago)
- Language: Python
- Homepage:
- Size: 28.3 KB
- Stars: 321
- Watchers: 8
- Forks: 52
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-python - unicode-slugify - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
- awesome-python-zh - unicode-slugify - 一个slugifier,它以Django作为依赖项生成unicode slugs。 (文本处理)
- awesome-python - unicode-slugify - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
- fucking_awesome_python - :octocat: unicode-slugify - :star: 208 :fork_and_knife: 38 - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
- awesome-python-resources - GitHub - 55% open · ⏱️ 22.10.2021): (文本处理)
- awesome-python - unicode-slugify - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
- fucking-awesome-python - unicode-slugify - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
- fucking-awesome-python - :octocat: unicode-slugify - :star: 318 :fork_and_knife: 52 - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
- awesome-python - unicode-slugify - A slugifier that generates unicode slugs with Django as a dependency. (Text Processing)
README
# Unicode Slugify
Unicode Slugify is a slugifier that generates unicode slugs. It was originally
used in the Firefox Add-ons web site to generate slugs for add-ons and add-on
collections. Many of these add-ons and collections had unicode characters and
required more than simple transliteration.
## Usage
```python
from slugify import slugify, SLUG_OK
# Default usage : lower, spaces replaced with "-", only alphanum and "-_~" chars, keeps unicode
slugify(u'Bän...g (bang)')
# u'bäng-bang'
# Keep capital letters and spaces
slugify(u'Bän...g (bang)', lower=False, spaces=True)
# u'Bäng bang'
# Replace non ascii chars with their "best" representation
slugify(u'北京 (capital of China)', only_ascii=True)
# u'bei-jing-capital-of-china'
# Allow some extra chars
slugify(u'北京 (capital of China)', ok=SLUG_OK+'()', only_ascii=True)
# u'bei-jing-(capital-of-china)'
# "snake_case" example
def snake_case(s):
# As "-" is not in allowed Chars, first one (`_`) is used for space replacement
return slugify(s, ok='_', only_ascii=True)
snake_case(u'北京 (capital of china)')
# u'bei_jing_capital_of_china'
# "CamelCase" example
def camel_case(s):
return slugify(s.title(), ok='', only_ascii=True, lower=False)
camel_case(u'北京 (capital of china)')
# u'BeiJingCapitalOfChina'
```
## Thanks
Tomaz Solc, unidecode, https://pypi.python.org/pypi/Unidecode