Skip to content

Commit

Permalink
add special pre translation file, more unit test, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
un33k committed Oct 10, 2019
1 parent 67c16a4 commit 33bf07e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
## 3.0.5
- Add test for pre-translation (e.g German Umlaut)
- Add special char supports (optional Use)

## 3.0.4
- Now supporting text-unidecode>=1.3
- Now supporting Unidecode>=1.1.1

## 3.0.3
- Remove unicode chars from file

## 3.0.2
- Add official support of Py 3.7

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ txt = '10 | 20 %'
r = slugify(txt, replacements=[['|', 'or'], ['%', 'percent']])
self.assertEqual(r, "10-or-20-percent")

txt = 'ÜBER Über German Umlaut'
r = slugify(txt, replacements=[['Ü', 'UE'], ['ü', 'ue']])
self.assertEqual(r, "ueber-ueber-german-umlaut")

```

For more examples, have a look at the [test.py](test.py) file.
Expand Down
3 changes: 2 additions & 1 deletion slugify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .special import *
from .slugify import *


__author__ = 'Val Neekman @ Neekware Inc. [@vneekman]'
__description__ = 'A Python slugify application that also handles Unicode'
__version__ = '3.0.4'
__version__ = '3.0.5'
44 changes: 44 additions & 0 deletions slugify/special.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
def add_uppercase_char(char_list):
""" Given a replacement char list, this adds uppercase chars to the list """

for item in char_list:
char, xlate = item
upper_dict = char.upper(), xlate.capitalize()
if upper_dict not in char_list and char != upper_dict[0]:
char_list.insert(0, upper_dict)
return char_list


# Language specific pre translations
# Source awesome-slugify

_CYRILLIC = [ # package defaults:
(u'ё', u'e'), # io / yo
(u'я', u'ya'), # ia
(u'х', u'h'), # kh
(u'у', u'y'), # u
(u'щ', u'sch'), # shch
(u'ю', u'u'), # iu / yu
]
CYRILLIC = add_uppercase_char(_CYRILLIC)

_GERMAN = [ # package defaults:
(u'ä', u'ae'), # a
(u'ö', u'oe'), # o
(u'ü', u'ue'), # u
]
GERMAN = add_uppercase_char(_GERMAN)

_GREEK = [ # package defaults:
(u'χ', u'ch'), # kh
(u'Ξ', u'X'), # Ks
(u'ϒ', u'Y'), # U
(u'υ', u'y'), # u
(u'ύ', u'y'),
(u'ϋ', u'y'),
(u'ΰ', u'y'),
]
GREEK = add_uppercase_char(_GREEK)

# Pre translations
PRE_TRANSLATIONS = CYRILLIC + GERMAN + GREEK
5 changes: 5 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ def test_replacements(self):
r = slugify(txt, replacements=[['♥', 'amour'], ['🦄', 'licorne']])
self.assertEqual(r, "i-amour-licorne")

def test_replacements_german_umlaut_custom(self):
txt = 'ÜBER Über German Umlaut'
r = slugify(txt, replacements=[['Ü', 'UE'], ['ü', 'ue']])
self.assertEqual(r, "ueber-ueber-german-umlaut")


class TestUtils(unittest.TestCase):

Expand Down

0 comments on commit 33bf07e

Please sign in to comment.