Django

Code

Ticket #2276 (closed: duplicate)

Opened 2 years ago

Last modified 1 year ago

[patch] make slugify filter to be aware of unicode

Reported by: nkeric Assigned to: adrian
Milestone: Component: Template system
Version: SVN Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Currently the slugify filter only works with english alphanumeric characters, here is a simple patch that makes it to be able to "match the characters [0-9_] plus whatever is classified as alphanumeric in the Unicode character properties database".

here is the ref:

http://docs.python.org/lib/re-syntax.html

http://docs.python.org/lib/node115.html

Regards,

- Eric

Attachments

defaultfilters.py.diff (0.6 kB) - added by nkeric on 07/01/06 11:51:14.
defaultfilters.py.2.diff (0.6 kB) - added by nkeric on 07/01/06 12:11:33.
new diff with re.U replaced with re.UNICODE
validators.py.diff (0.6 kB) - added by nkeric on 07/01/06 12:12:32.
patch the validator isSlug
defaultfilters.py.3.diff (0.7 kB) - added by nkeric on 07/01/06 14:51:19.
output string should be utf-8 encoded as input string
validators.py.2.diff (1.0 kB) - added by nkeric on 07/01/06 14:52:46.
decode utf-8 encoded string for doing re search
defaultfilters.py.patch (0.8 kB) - added by Jonas on 06/19/07 06:34:02.
Normallizes string

Change History

07/01/06 11:51:14 changed by nkeric

  • attachment defaultfilters.py.diff added.

07/01/06 11:59:56 changed by nkeric

I tested it and it handles Chinese Characters properly (should work with other language's characters too), and all Chinese punctuations are removed as expected :)

07/01/06 12:11:33 changed by nkeric

  • attachment defaultfilters.py.2.diff added.

new diff with re.U replaced with re.UNICODE

07/01/06 12:12:32 changed by nkeric

  • attachment validators.py.diff added.

patch the validator isSlug

07/01/06 14:51:19 changed by nkeric

  • attachment defaultfilters.py.3.diff added.

output string should be utf-8 encoded as input string

07/01/06 14:52:46 changed by nkeric

  • attachment validators.py.2.diff added.

decode utf-8 encoded string for doing re search

08/05/06 18:28:16 changed by adrian

  • status changed from new to closed.
  • resolution set to duplicate.

Closing in favor of #2489.

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted

06/18/07 14:49:22 changed by Jonas

  • status changed from closed to reopened.
  • resolution deleted.

I found this program: Slughifi is slugify with support for international characters.

http://amisphere.com/contrib/python-django/
http://amisphere.com/contrib/python-django/slughifi.py

06/18/07 18:43:07 changed by mtredinnick

  • status changed from reopened to closed.
  • resolution set to duplicate.

Somebody brought that up on the mailing list at one point. Further investigation revealed is was under the GPL license (no license is mentioned in the file, which is even worse), so we cannot use it.

We have a different solution in the works over at #4365 which I'll resolve in the near future.

06/19/07 06:33:00 changed by Jonas

  • status changed from closed to reopened.
  • resolution deleted.

By now, I found a solution.

Got from http://www.djangosnippets.org/snippets/98/ (_string_to_slug method) that points to http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/251871 (Aaron Bentley)

E.g:
It translates: Á È ï ô ü ñ
to:            A E i o u n

so it's very usefull for a lot of languages.

I add a patch.

06/19/07 06:34:02 changed by Jonas

  • attachment defaultfilters.py.patch added.

Normallizes string

06/20/07 06:05:30 changed by Jonas

  • status changed from reopened to closed.
  • resolution set to duplicate.

Closing in favor of #4365


Add/Change #2276 ([patch] make slugify filter to be aware of unicode)




Change Properties
Action