Code Monkey home page Code Monkey logo

unicode-slugify's Introduction

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

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

unicode-slugify's People

Contributors

aiiie avatar amcanadas avatar davedash avatar dylanncordel avatar ebsaral avatar jeffwidman avatar jezdez avatar lauraxt avatar marceltschoppch avatar mozilla-github-standards avatar nitely avatar pydanny avatar santiagobasulto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

unicode-slugify's Issues

Example from README is not accurate

The readme file shows this example:

# Replace non ascii chars with their "best" representation
slugify(u'北京 (capital of China)', only_ascii=True)
# u'bei-jing-capital-of-china'

but when running it locally, the result is different:

In [1]: from slugify import slugify                                                                                                                                                           

In [2]: slugify('北京 (capital of China)', only_ascii=True)                                                                                                                                   
Out[2]: 'Bei Jing -capital-of-china'

I'm using v0.1.3 and Python 3.6.8

"pip install unicode-slugify" is missing files

I cannot install this package with pip, the following happens

$ sudo pip install unicode-slugify
Downloading/unpacking unicode-slugify
Could not find any downloads that satisfy the requirement unicode-slugify
No distributions at all found for unicode-slugify
Storing complete log in /home/tirithen/.pip/pip.log

And the log says:


/usr/bin/pip run on Wed Jan 25 13:58:45 2012
Downloading/unpacking unicode-slugify
Getting page http://pypi.python.org/simple/unicode-slugify
URLs to search for versions for unicode-slugify:

UnicodeDecodeError installing in 3.6.8

I have recived a UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 361: ordinal not in range(128) error when installing using pip and Python 3.6.8. there is the trace:

ERROR: Command errored out with exit status 1:
 command: /home/devikhxr/virtualenv/public_comohay.com/3.6/bin/python3.6_bin -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-68hcpkqo/unicode-slugify/setup.py'"'"'; __file__='"'"'/tmp/pip-install-68hcpkqo/unicode-slugify/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-2f7x6_ul
     cwd: /tmp/pip-install-68hcpkqo/unicode-slugify/
Complete output (7 lines):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-install-68hcpkqo/unicode-slugify/setup.py", line 7, in <module>
    long_description=open('README.md').read(),
  File "/home/devikhxr/virtualenv/public_comohay.com/3.6/lib64/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 361: ordinal not in range(128)
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Slugify-ing foreign characters?

Calling:
slugify.slufigy("Ставки земельного налога в городах Свердловской области в 2014 году")

generates this slug:
stavki-zemel'nogo-naloga-v-gorodakh-sverdlovskoi-oblasti-v-2014-godu

The single quote char was unexpected. Is there a way to force the slugs to only contain alphanumeric or hyphen characters, even when using a foreign language?

Release 0.1.4

Pypi only has 0.1.3. But 0.1.4 is in the code, right?

'ascii' codec can't decode byte 0xc3 in position 361 at open('README.md').read(),

  Downloading unicode-slugify-0.1.3.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-s4ot22tg/unicode-slugify/setup.py", line 7, in <module>
        long_description=open('README.md').read(),
      File "/var/cache/drone/src/github.com/dz0ny/app/.tox/py34/lib/python3.4/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 361: ordinal not in range(128)

Deprecation and syntax warnings in Python 3.8

Deprecation warning due to invalid escape sequences. Using raw strings or escaping them again helps in resolving this. Check https://github.com/asottile/pyupgrade/ for automatic fix of this.

find . -iname '*.py' | grep -Ev 'rdf4|doc|benchmark|tool' | xargs -P4 -I{} python3.8 -Wall -m py_compile {}
./slugify/__init__.py:84: DeprecationWarning: invalid escape sequence \s
  new = re.sub('[%s\s]+' % space_replacement, space_replacement, new)

Working example code

#models.py
from slugify import slugify, smart_text


title = models.CharField(_('file name'), max_length=255)
slug = slugify(_('url'), max_length=250, unique=True)
summary = models.TextField(_('summary'))

As a newbie, having tried many but without success, any working example ?

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please reach out to [email protected].

(Message COC001)

License collision?

As I see this project is using Unidecode lib, which is GPL-licensed. Is it ok?

I'm currently looking for solution licensed under MIT/ BSD / Apache.

Wiki changes

FYI: The following changes were made to this repository's wiki:

  • defacing spam has been removed

  • the wiki has been disabled, as it was not used

These were made as the result of a recent automated defacement of publically writeable wikis.

Conflict with python-slugify

Both this project and python-slugify (which logzero uses as a dependency) have the root module as slugify which I'm guessing a lot of users have experienced. I like this package, but I think it'd help to rename the root folder something like UnicodeSlugify or unicodeslugify.

Just a thought...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.