Транслит с русского на английский python

transliterate package¶

The attributes below shall be defined in every language pack.

language_code : Language code (obligatory). Example value: ‘hy’, ‘ru’. language_name : Language name (obligatory). Example value: ‘Armenian’,

character_ranges : Character ranges that are specific to the language. When making a pack, check this page for the ranges. mapping : Mapping (obligatory). A tuple, consisting of two strings (source and target). Example value: (u’abc’, u’աբց’). reversed_specific_mapping : Specific mapping (one direction only) used when transliterating from target script to source script (reversed transliteration). ՝՝pre_processor_mapping՝՝: Pre processor mapping (optional). A dictionary mapping for letters that can’t be represented by a single latin letter. ՝՝reversed_specific_pre_processor_mapping՝՝: Pre processor mapping ( optional). A dictionary mapping for letters that can’t be represented by a single latin letter (reversed transliteration).

example:
>>> class ArmenianLanguagePack(TranslitLanguagePack): >>> language_code = "hy" >>> language_name = "Armenian" >>> character_ranges = ((0x0530, 0x058F), (0xFB10, 0xFB1F)) >>> mapping = ( >>> u"abgdezilxkhmjnpsvtrcq&ofABGDEZILXKHMJNPSVTRCQOF", # Source script >>> u"աբգդեզիլխկհմյնպսվտրցքևօֆԱԲԳԴԵԶԻԼԽԿՀՄՅՆՊՍՎՏՐՑՔՕՖ", # Target script >>> ) >>> reversed_specific_mapping = ( >>> u"ռՌ", >>> u"rR" >>> ) >>> pre_processor_mapping =  >>> # lowercase >>> u"e'": u"է", >>> u"y": u"ը", >>> u"th": u"թ", >>> u"jh": u"ժ", >>> u"ts": u"ծ", >>> u"dz": u"ձ", >>> u"gh": u"ղ", >>> u"tch": u"ճ", >>> u"sh": u"շ", >>> u"vo": u"ո", >>> u"ch": u"չ", >>> u"dj": u"ջ", >>> u"ph": u"փ", >>> u"u": u"ու", >>> >>> # uppercase >>> u"E'": u"Է", >>> u"Y": u"Ը", >>> u"Th": u"Թ", >>> u"Jh": u"Ժ", >>> u"Ts": u"Ծ", >>> u"Dz": u"Ձ", >>> u"Gh": u"Ղ", >>> u"Tch": u"Ճ", >>> u"Sh": u"Շ", >>> u"Vo": u"Ո", >>> u"Ch": u"Չ", >>> u"Dj": u"Ջ", >>> u"Ph": u"Փ", >>> u"U": u"Ու" >>> > >>> reversed_specific_pre_processor_mapping =  >>> u"ու": u"u", >>> u"Ու": u"U" >>> > Note, that in Python 3 you won't be using u prefix before the strings. 

Check if given character belongs to the language pack.

Return bool:

classmethod detect ( num_words=None ) [source] ¶

Heavy language detection, which is activated for languages that are harder detect (like Russian Cyrillic and Ukrainian Cyrillic).

True if detected and False otherwise.

Strip out unnecessary characters from the string.

Suggest possible variants (some sort of auto-complete).

Transliterate the given value according to the rules.

Rules are set in the transliteration pack.

transliterate.conf module¶

transliterate.decorators module¶

alias of transliterate.decorators.TransliterateFunction

alias of transliterate.decorators.TransliterateMethod

transliterate.defaults module¶

transliterate.discover module¶

Auto-discover the language packs in contrib/apps.

transliterate.exceptions module¶

Exception raised when developer didn’t configure the code properly.

exception transliterate.exceptions. InvalidRegistryItemType [source] ¶

Raised when an attempt is made to register an item in the registry.

Raised when an attempt is made to register an item in the registry which does not have a proper type.

exception transliterate.exceptions. LanguageCodeError [source] ¶

Exception raised when language code is empty or has incorrect value.

exception transliterate.exceptions. LanguageDetectionError [source] ¶

Exception raised when language can’t be detected.

Exception raised when language can’t be detected for the text given.

exception transliterate.exceptions. LanguagePackNotFound [source] ¶

Exception raised when language pack is not found.

Exception raised when language pack is not found for the language code given.

transliterate.helpers module¶

transliterate.helpers. project_dir ( base ) [source] ¶

transliterate.utils module¶

transliterate.utils. detect_language ( text, num_words=None, fail_silently=True, heavy_check=False ) [source] ¶

Detect the language from the value given.

Detect the language from the value given based on ranges defined in active language packs.

  • value (unicode) – Input string.
  • num_words (int) – Number of words to base decision on.
  • fail_silently (bool) –
  • heavy_check (bool) – If given, heavy checks would be applied when simple checks don’t give any results. Heavy checks are language specific and do not apply to a common logic. Heavy language detection is defined in the detect method of each language pack.

Get list of language codes for registered language packs.

Return list:

transliterate.utils. get_available_language_packs ( ) [source] ¶

Get list of registered language packs.

Return list:

transliterate.utils. get_translit_function ( language_code ) [source] ¶

Return translit function for the language given.

Parameters: language_code (str) –
Return callable:

transliterate.utils. slugify ( text, language_code=None ) [source] ¶

If no language_code is given, auto-detect the language code from text given.

Suggest possible variants.

Transliterate the text for the language given.

Language code is optional in case of reversed translations (from some script to latin).

Module contents¶

transliterate. detect_language ( text, num_words=None, fail_silently=True, heavy_check=False ) [source] ¶

Detect the language from the value given.

Detect the language from the value given based on ranges defined in active language packs.

  • value (unicode) – Input string.
  • num_words (int) – Number of words to base decision on.
  • fail_silently (bool) –
  • heavy_check (bool) – If given, heavy checks would be applied when simple checks don’t give any results. Heavy checks are language specific and do not apply to a common logic. Heavy language detection is defined in the detect method of each language pack.

Get list of language codes for registered language packs.

Return list:

transliterate. get_available_language_packs ( ) [source] ¶

Get list of registered language packs.

Return list:

transliterate. get_translit_function ( language_code ) [source] ¶

Return translit function for the language given.

Parameters: language_code (str) –
Return callable:

transliterate. slugify ( text, language_code=None ) [source] ¶

If no language_code is given, auto-detect the language code from text given.

Transliterate the text for the language given.

Language code is optional in case of reversed translations (from some script to latin).

© Copyright 2013-2018 Artur Barseghyan Revision 9333f242 .

Versions latest 1.10.2 1.9 1.8.1 1.7.3 1.6.1 1.5 1.4 1.3 1.2 1.1 Downloads pdf html epub On Read the Docs Project Home Builds Free document hosting provided by Read the Docs.

Источник

ledovsky / translit.py

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

# name: это строка которую транслитим
def transliterate ( name ):
«»»
Автор: LarsKort
Дата: 16/07/2011; 1:05 GMT-4;
Не претендую на «хорошесть» словарика. В моем случае и такой пойдет,
вы всегда сможете добавить свои символы и даже слова. Только
это нужно делать в обоих списках, иначе будет ошибка.
«»»
# Слоаврь с заменами
slovar = < 'а' : 'a' , 'б' : 'b' , 'в' : 'v' , 'г' : 'g' , 'д' : 'd' , 'е' : 'e' , 'ё' : 'yo' ,
‘ж’ : ‘zh’ , ‘з’ : ‘z’ , ‘и’ : ‘i’ , ‘й’ : ‘i’ , ‘к’ : ‘k’ , ‘л’ : ‘l’ , ‘м’ : ‘m’ , ‘н’ : ‘n’ ,
‘о’ : ‘o’ , ‘п’ : ‘p’ , ‘р’ : ‘r’ , ‘с’ : ‘s’ , ‘т’ : ‘t’ , ‘у’ : ‘u’ , ‘ф’ : ‘f’ , ‘х’ : ‘h’ ,
‘ц’ : ‘c’ , ‘ч’ : ‘ch’ , ‘ш’ : ‘sh’ , ‘щ’ : ‘sch’ , ‘ъ’ : » , ‘ы’ : ‘y’ , ‘ь’ : » , ‘э’ : ‘e’ ,
‘ю’ : ‘u’ , ‘я’ : ‘ya’ , ‘А’ : ‘A’ , ‘Б’ : ‘B’ , ‘В’ : ‘V’ , ‘Г’ : ‘G’ , ‘Д’ : ‘D’ , ‘Е’ : ‘E’ , ‘Ё’ : ‘YO’ ,
‘Ж’ : ‘ZH’ , ‘З’ : ‘Z’ , ‘И’ : ‘I’ , ‘Й’ : ‘I’ , ‘К’ : ‘K’ , ‘Л’ : ‘L’ , ‘М’ : ‘M’ , ‘Н’ : ‘N’ ,
‘О’ : ‘O’ , ‘П’ : ‘P’ , ‘Р’ : ‘R’ , ‘С’ : ‘S’ , ‘Т’ : ‘T’ , ‘У’ : ‘U’ , ‘Ф’ : ‘F’ , ‘Х’ : ‘H’ ,
‘Ц’ : ‘C’ , ‘Ч’ : ‘CH’ , ‘Ш’ : ‘SH’ , ‘Щ’ : ‘SCH’ , ‘Ъ’ : » , ‘Ы’ : ‘y’ , ‘Ь’ : » , ‘Э’ : ‘E’ ,
‘Ю’ : ‘U’ , ‘Я’ : ‘YA’ , ‘,’ : » , ‘?’ : » , ‘ ‘ : ‘_’ , ‘~’ : » , ‘!’ : » , ‘@’ : » , ‘#’ : » ,
‘$’ : » , ‘%’ : » , ‘^’ : » , ‘&’ : » , ‘*’ : » , ‘(‘ : » , ‘)’ : » , ‘-‘ : » , ‘=’ : » , ‘+’ : » ,
‘:’ : » , ‘;’ : » , » : » , ‘ \’ ‘ : » , ‘»‘ : » , ‘ \\ ‘ : » , ‘/’ : » , ‘№’ : » ,
‘[‘ : » , ‘]’ : » , » : » , ‘ґ’ : » , ‘ї’ : » , ‘є’ : » , ‘Ґ’ : ‘g’ , ‘Ї’ : ‘i’ ,
‘Є’ : ‘e’ , ‘—’ : » >
# Циклически заменяем все буквы в строке
for key in slovar :
name = name . replace ( key , slovar [ key ])
return name

Источник

Читайте также:  Array column php многомерный массив
Оцените статью