diff options
author | Val Neekman <val@neekware.com> | 2019-10-10 18:12:07 -0400 |
---|---|---|
committer | Val Neekman <val@neekware.com> | 2019-10-10 18:12:07 -0400 |
commit | 33bf07efc82c00b811df02bca8c5862f95db3294 (patch) | |
tree | 5ce14d61e8f5faff7e5238c6292723cc3ad9d05d | |
parent | 67c16a409063578d38bf69ee345254e67b237206 (diff) | |
download | python-slugify-33bf07efc82c00b811df02bca8c5862f95db3294.tar.gz |
add special pre translation file, more unit test, updated readme3.0.5
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | slugify/__init__.py | 3 | ||||
-rw-r--r-- | slugify/special.py | 44 | ||||
-rw-r--r-- | test.py | 5 |
5 files changed, 62 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index cc98d31..0e1a514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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. diff --git a/slugify/__init__.py b/slugify/__init__.py index 52a07b4..0c86a4c 100644 --- a/slugify/__init__.py +++ b/slugify/__init__.py @@ -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' diff --git a/slugify/special.py b/slugify/special.py new file mode 100644 index 0000000..767541a --- /dev/null +++ b/slugify/special.py @@ -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 @@ -223,6 +223,11 @@ class TestSlugification(unittest.TestCase): 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): |