special.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from __future__ import annotations
  2. def add_uppercase_char(char_list: list[tuple[str, str]]) -> list[tuple[str, str]]:
  3. """ Given a replacement char list, this adds uppercase chars to the list """
  4. for item in char_list:
  5. char, xlate = item
  6. upper_dict = char.upper(), xlate.capitalize()
  7. if upper_dict not in char_list and char != upper_dict[0]:
  8. char_list.insert(0, upper_dict)
  9. return char_list
  10. # Language specific pre translations
  11. # Source awesome-slugify
  12. _CYRILLIC = [ # package defaults:
  13. (u'ё', u'e'), # io / yo
  14. (u'я', u'ya'), # ia
  15. (u'х', u'h'), # kh
  16. (u'у', u'y'), # u
  17. (u'щ', u'sch'), # sch
  18. (u'ю', u'u'), # iu / yu
  19. ]
  20. CYRILLIC = add_uppercase_char(_CYRILLIC)
  21. _GERMAN = [ # package defaults:
  22. (u'ä', u'ae'), # a
  23. (u'ö', u'oe'), # o
  24. (u'ü', u'ue'), # u
  25. ]
  26. GERMAN = add_uppercase_char(_GERMAN)
  27. _GREEK = [ # package defaults:
  28. (u'χ', u'ch'), # kh
  29. (u'Ξ', u'X'), # Ks
  30. (u'ϒ', u'Y'), # U
  31. (u'υ', u'y'), # u
  32. (u'ύ', u'y'),
  33. (u'ϋ', u'y'),
  34. (u'ΰ', u'y'),
  35. ]
  36. GREEK = add_uppercase_char(_GREEK)
  37. # Pre translations
  38. PRE_TRANSLATIONS = CYRILLIC + GERMAN + GREEK