Package: transliterate
Bi-directional transliterator for Python. Transliterates (unicode) strings
according to the rules specified in the language packs (source script <->
target script).Comes with language packs for the following languages (listed in alphabetical
order):ArmenianBulgarian (beta)GeorgianGreekMacedonian (alpha)Mongolian (alpha)RussianSerbian (alpha)Ukrainian (beta)There are also a number of useful tools included, such as:Simple lorem ipsum generator, which allows lorem ipsum generation in the
language chosen.Language detection for the text (if appropriate language pack is available).Slugify function for non-latin texts.PrerequisitesPython >=2.7, >=3.4, PyPyInstallationInstall with latest stable version from PyPI.pipinstalltransliterateor install the latest stable version from BitBucket:pipinstallhttps://bitbucket.org/barseghyanartur/transliterate/get/stable.tar.gzor install the latest stable version from GitHub:pipinstallhttps://github.com/barseghyanartur/transliterate/archive/stable.tar.gzThat’s all. See theUsage and examplessection for more.Usage and examplesSimple usageRequired importsfromtransliterateimporttranslit,get_available_language_codesOriginal texttext="Lorem ipsum dolor sit amet"Transliteration to Armenianprint(translit(text,'hy'))# Լօրեմ իպսում դօլօր սիտ ամետTransliteration to Georgianprint(translit(text,'ka'))# ლორემ იპსუმ დოლორ სით ამეთTransliteration to Greekprint(translit(text,'el'))# Λορεμ ιψθμ δολορ σιτ αμετTransliteration to Russianprint(translit(text,'ru'))# Лорем ипсум долор сит аметList of available (registered) languagesprint(get_available_language_codes())# ['el', 'hy', 'ka', 'ru']Reversed transliterations are transliterations made from target language to
source language (in terms they are defined in language packs). In case of
reversed transliterations, you may leave out thelanguage_codeattribute,
although if you know it on beforehand, specify it since it works faster that
way.Reversed transliteration from Armenianprint(translit(u"Լօրեմ իպսում դօլօր սիտ ամետ",'hy',reversed=True))# Lorem ipsum dolor sit ametReversed transliteration from Armenian withlanguage_codeargument left outprint(translit(u"Լօրեմ իպսում դօլօր սիտ ամետ",reversed=True))# Lorem ipsum dolor sit ametReversed transliteration from Georgianprint(translit(u"ლორემ იპსუმ დოლორ სით ამეთ",'ka',reversed=True))# Lorem ipsum dolor sit ametReversed transliteration from Georgian withlanguage_codeargument left outprint(translit(u"ლორემ იპსუმ დოლორ სით ამეთ",reversed=True))# Lorem ipsum dolor sit ametReversed transliteration from Greekprint(translit(u"Λορεμ ιψθμ δολορ σιτ αμετ",'el',reversed=True))# Lorem ipsum dolor sit ametReversed transliteration from Greek withlanguage_codeargument left outprint(translit(u"Λορεμ ιψθμ δολορ σιτ αμετ",reversed=True))# Lorem ipsum dolor sit ametReversed transliteration from Russian (Cyrillic)print(translit(u"Лорем ипсум долор сит амет",'ru',reversed=True))# Lorеm ipsum dolor sit amеtReversed transliteration from Russian (Cyrillic) withlanguage_codeargument left outprint(translit(u"Лорем ипсум долор сит амет",reversed=True))# Lorem ipsum dolor sit ametTesting the decoratorfromtransliterate.decoratorsimporttransliterate_function@transliterate_function(language_code='hy')defdecorator_test(text):returntextprint(decorator_test(u"Lorem ipsum dolor sit amet"))# Լօրեմ իպսում դօլօր սիտ ամետWorking with large amounts of dataIf you know which language pack shall be used for transliteration, especially
when working with large amounts of data, it makes sense to get the
transliteration function in the following way:fromtransliterateimportget_translit_functiontranslit_hy=get_translit_function('hy')print(translit_hy(u"Լօրեմ իպսում դօլօր սիտ ամետ",reversed=True))# Lorem ipsum dolor sit ametprint(translit_hy(u"Lorem ipsum dolor sit amet"))# Լօրեմ իպսում դօլօր սիտ ամետRegistering a custom language packBasicsMake sure to call theautodiscoverfunction before registering your own
language packs if you want to use the bundled language packs along with your
own custom ones.fromtransliterate.discoverimportautodiscoverautodiscover()Then the custom language pack part comes.fromtransliterate.baseimportTranslitLanguagePack,registryclassExampleLanguagePack(TranslitLanguagePack):language_code="example"language_name="Example"mapping=(u"abcdefghij",u"1234567890",)registry.register(ExampleLanguagePack)print(get_available_language_codes())# ['el', 'hy', 'ka', 'ru', 'example']print(translit(text,'example'))# Lor5m 9psum 4olor s9t 1m5tIt’s possible to replace existing language packs with your own ones. By
default, existing language packs are not force-installed.To force install a language pack, set theforceargument to True when
registering a language pack. In that case, if a language pack with same
language code has already been registered, it will be replaced; otherwise,
if language pack didn’t exist in the registry, it will be just registered.registry.register(ExampleLanguagePack,force=True)Forced language packs can’t be replaced or unregistered.API in depthThere are 7 class properties that you could/should be using in your language
pack, of which 4 are various sorts of mappings.Mappingsmapping(tuple): A tuple of two strings, that simply represent the
mapping of characters from the source language to the target language. For
example, if your source language is Latin and you want to convert “a”, “b”,
“c”, “d” and “e” characters to appropriate characters in Russian Cyrillic,
your mapping would look as follows:mapping=(u"abcde",u"абцде")Example (taken from the Greek language pack).mapping=(u"abgdezhiklmnxoprstyfwuABGDEZHIKLMNXOPRSTYFWU",u"αβγδεζηικλμνξοπρστυφωθΑΒΓΔΕΖΗΙΚΛΜΝΞΟΠΡΣΤΥΦΩΘ",)reversed_specific_mapping(tuple): When making reversed translations,
themappingproperty is still used, but in some cases you need to provide
additional rules. This property (reversed_specific_mapping) is meant for
such cases. Further, is alike themapping.Example (taken from the Greek language pack).reversed_specific_mapping=(u"θΘ",u"uU")pre_processor_mapping(dict): A dictionary of mapping from source
language to target language. Use this only in cases if a single character
in source language shall be represented by more than one character in the
target language.Example (taken from the Greek language pack).pre_processor_mapping={u"th":u"θ",u"ch":u"χ",u"ps":u"ψ",u"TH":u"Θ",u"CH":u"Χ",u"PS":u"Ψ",}reversed_specific_pre_processor_mapping: Same aspre_processor_mapping, but used in reversed translations.Example (taken from the Armenian language pack)reversed_specific_pre_processor_mapping={u"ու":u"u",u"Ու":u"U"}Additionalcharacter_ranges(tuple): A tuple of character ranges (unicode table).
Used in language detection. Works only ifdetectableproperty is set
to True. Be aware, that language (or shall I better be saying - script)
detection is very basic and is based on characters only.detectable(bool): If set to True, language pack would be used
for automatic language detection.Using the lorem ipsum generatorNote, that due to incompatibility of the originallorem-ipsum-generatorpackage with Python 3, when used with Python 3transliterateuses its’ own
simplified fallback lorem ipsum generator (which still does the job).Required importsfromtransliterate.contrib.apps.translipsumimportTranslipsumGeneratorGenerating paragraphs in Armeniang_am=TranslipsumGenerator(language_code='hy')print(g_am.generate_paragraph())# Մագնա տրիստիքուե ֆաուցիբուս ֆամես նետուս նետուս օրցի մաուրիս,# սուսցիպիտ. Դապիբուս րիսուս սեդ ադիպիսցինգ դիցտում. Ֆերմենտում ուրնա# նատօքուե ատ. Uլտրիցես եգետ, տացիտի. Լիտօրա ցլասս ցօնուբիա պօսուերե# մալեսուադա ին իպսում իդ պեր վե.Generating sentense in Georgiang_ka=TranslipsumGenerator(language_code='ka')print(g_ka.generate_sentence())# გგეთ ყუამ არსუ ვულფუთათე რუთრუმ აუთორ.Generating sentense in Greekg_el=TranslipsumGenerator(language_code='el')print(g_el.generate_sentence())# Νεc cρασ αμετ, ελιτ vεστιβθλθμ εθ, αενεαν ναμ, τελλθσ vαριθσ.Generating sentense in Russian (Cyrillic)g_ru=TranslipsumGenerator(language_code='ru')print(g_ru.generate_sentence())# Рисус cонсеcтетуер, фусcе qуис лаореет ат ерос пэдэ фелис магна.Language detectionRequired importsfromtransliterateimportdetect_languageDetect Armenian textdetect_language(u'Լօրեմ իպսում դօլօր սիտ ամետ')# hyDetect Georgian textdetect_language(u'ლორემ იპსუმ დოლორ სით ამეთ')# kaDetect Greek textdetect_language(u'Λορεμ ιψθμ δολορ σιτ αμετ')# elDetect Russian (Cyrillic) textdetect_language(u'Лорем ипсум долор сит амет')# ruSlugifyRequired importsfromtransliterateimportslugifySlugify Armenian textslugify(u'Լօրեմ իպսում դօլօր սիտ ամետ')# lorem-ipsum-dolor-sit-ametSlugify Georgian textslugify(u'ლორემ იპსუმ დოლორ სით ამეთ')# lorem-ipsum-dolor-sit-ametSlugify Greek textslugify(u'Λορεμ ιψθμ δολορ σιτ αμετ')# lorem-ipsum-dolor-sit-ametSlugify Russian (Cyrillic) textslugify(u'Лорем ипсум долор сит амет')# lorem-ipsum-dolor-sit-ametMissing a language pack?Missing a language pack for your own language? Contribute to the project by
making one and it will appear in a new version (which will be released very
quickly).Writing documentationKeep the following hierarchy.=====
title
=====

header
======

sub-header
----------

sub-sub-header
~~~~~~~~~~~~~~

sub-sub-sub-header
^^^^^^^^^^^^^^^^^^

sub-sub-sub-sub-header
++++++++++++++++++++++

sub-sub-sub-sub-sub-header
**************************LicenseGPL 2.0/LGPL 2.1SupportFor any issues contact me at the e-mail given in theAuthorsection.AuthorArtur Barseghyan <artur.barseghyan@gmail.com>