How it works...

The default Django slugify() function handles German diacritical symbols incorrectly. To see this for yourself, run the following code in the Django shell, without the monkey patch:

(myproject_env)$ python3 manage.py shell
>>> from django.utils.text import slugify
>>> slugify("Heizölrückstoßabdämpfung")
'heizolruckstoabdampfung'

This is incorrect in German, as the letter ß is totally stripped out, instead of substituting it with ss; the letters ä, ö, and ü are changed to a, o, and u, whereas they should be substituted with ae, oe, and ue.

The monkey patch that we created loads the django.utils.text module at initialization and reassigns transliteration.slugify in place of the core slugify() function. Now, if you run the same code in the Django shell, you will get different (but correct) results, as follows:

(myproject_env)$ python manage.py shell
>>> from django.utils.text import slugify 
>>> slugify("Heizölrückstoßabdämpfung") 
'heizoelrueckstossabdaempfung'

To read more about how to utilize the transliterate module, refer to https://pypi.org/project/transliterate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.204.142