Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How transliterate unicode text with PyICU to ASCII?

There is the PyICU library, which I understand can be used to transliterate strings. However there are no docs. Anyone have a simple example which transliterates a unicode string to ASCII, with PyICU?

The C++ ICU documentation for transliteration is here, but I don't understand how to call it from Python.

like image 984
Prof. Falken Avatar asked Nov 04 '25 06:11

Prof. Falken


1 Answers

There is a nice cheat sheet for PyICU here: https://gist.github.com/dpk/8325992

Here's a slightly modified example:

>>> import icu
>>> tl = icu.Transliterator.createInstance('Any-Latin; Latin-ASCII')
>>> tl.transliterate('Ψάπφω')
'Psappho'
like image 191
Tavian Barnes Avatar answered Nov 06 '25 18:11

Tavian Barnes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!