Developer Interface (API)¶
Srtools provides both CLI functionality (srts
utility) and a Python package
you can use from your own code.
The API intended for external use is documented in this file.
Transliteration functions¶
Two simple transliteration functions are provided by the package.
-
srtools.
cyrillic_to_latin
(text)[source]¶ Transliterate Serbian Cyrillic string to Latin.
- Parameters
text (
str
) – input Cyrillic string to be transliterated.- Returns
Input string transliterated to Latin.
- Return type
str
Examples
>>> from srtools import cyrillic_to_latin >>> in_str = "Ђаче, уштеду плаћај жаљењем због џиновских цифара." >>> cyrillic_to_latin(in_str) 'Đače, uštedu plaćaj žaljenjem zbog džinovskih cifara.'
-
srtools.
latin_to_cyrillic
(text)[source]¶ Transliterate Serbian Latin string to Cyrillic.
You may use a special separator
!
to split digraphs lj, nj, dž to prevent their conversion to single Cyrillic letters like so: l!j.- Parameters
text (
str
) – input Latin string to be transliterated.- Returns
Input string transliterated to Cyrillic.
- Return type
str
Examples
>>> from srtools import latin_to_cyrillic >>> in_str = "Đače, uštedu plaćaj žaljenjem zbog džinovskih cifara." >>> latin_to_cyrillic(in_str) 'Ђаче, уштеду плаћај жаљењем због џиновских цифара.' >>> latin_to_cyrillic('N!J je skraćenica za Nju Džersi') 'НЈ је скраћеница за Њу Џерси'
Translation tables and dictionaries¶
The dictionaries and str.translate()
translation tables used internally
are also provided as a part of the public API.
I believe you don’t need to use these variables, since the mechanism for
transliteration provided in this package is decent enough for most uses.
-
srtools.character_dictionaries.
CYR_TO_LAT_DICT
¶ Cyrillic → Latin character translation dict.
Not used internally. Can be used to look up equivalent Latin letter strings.
- Type
Dict[str, str]
-
srtools.character_dictionaries.
CYR_TO_LAT_TTABLE
¶ Cyrillic → Latin character translation table.
Used internally with
str.translate()
to transliterate text.- Type
Dict[int, str]
-
srtools.character_dictionaries.
LAT_TO_CYR_DICT
¶ Latin → Cyrillic character translation dict.
Not used internally. Can be used to look up equivalent Cyrillic letter strings.
- Type
Dict[str, str]
-
srtools.character_dictionaries.
LAT_TO_CYR_DIGRAPHS_DICT
¶ Latin → Cyrillic digraph translation dict.
Covers only mappings from Latin digraphs to equivalent Cyrillic letters. Used internally with
str.translate()
to transliterate text.- Type
Dict[str, str]
-
srtools.character_dictionaries.
LAT_TO_CYR_TTABLE
¶ Latin → Cyrillic character translation table.
Covers only transitions from single-character Latin letters to equivalent Cyrillic letters. Used internally with
str.translate()
to transliterate text.- Type
Dict[int, str]