Git Product home page Git Product logo

cyrillic-transliteration's Introduction

DOI

What is CyrTranslit?

A Python package for bi-directional transliteration of Cyrillic script to Latin script and vice versa.

By default, transliterates for the Serbian language. A language flag can be set in order to transliterate to and from Bulgarian, Montenegrin, Macedonian, Mongolian, Russian, Serbian, Tajik, and Ukrainian.

What is transliteration?

Transliteration is the conversion of a text from one script to another. For instance, a Latin alphabet transliteration of the Serbian phrase "Мој ховеркрафт је пун јегуља" is "Moj hoverkraft je pun jegulja".

Citation

A citation would be much appreciated if you use CyrTranslit in a research publication:

Georges Labrèche. (2023). CyrTranslit (v1.1.1). Zenodo. https://doi.org/10.5281/zenodo.7734906

BibTex entry:

@software{georges_labreche_2023_7734906,
  author       = {Georges Labrèche},
  title        = {CyrTranslit},
  month        = mar,
  year         = 2023,
  note         = {{A Python package for bi-directional 
                   transliteration of Cyrillic script to Latin script
                   and vice versa. Supports transliteration for
                   Bulgarian, Montenegrin, Macedonian, Mongolian,
                   Russian, Serbian, Tajik, and Ukrainian.}},
  publisher    = {Zenodo},
  version      = {v1.1.1},
  doi          = {10.5281/zenodo.7734906},
  url          = {https://doi.org/10.5281/zenodo.7734906}
}

Supporting research

CyrTranslit is actively used as a reliable tool to advance research! Here's an incomplete list of publications for research projects that have relied on CyrTranslit:

How do I install this?

CyrTranslit is hosted in the Python Package Index (PyPI) so it can be installed using pip:

python -m pip install cyrtranslit         # latest version
python -m pip install cyrtranslit==1.1.1  # specific version
python -m pip install cyrtranslit>=1.1.1  # minimum version

What languages are supported?

CyrTranslit currently supports bi-directional transliteration of Bulgarian, Montenegrin, Macedonian, Mongolian, Russian, Serbian, Tajik, and Ukrainian:

>>> import cyrtranslit
>>> cyrtranslit.supported()
['bg', 'me', 'mk', 'mn', 'ru', 'sr', 'tj', 'ua']

How do I use this?

CyrTranslit can be used both programatically and via command line interface.

Programmatically

Bulgarian

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Съединението прави силата!", "bg")
"Săedinenieto pravi silata!"
>>> cyrtranslit.to_cyrillic("Săedinenieto pravi silata!", "bg")
"Съединението прави силата!"

Montenegrin

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Република", "me")
"Republika"
>>> cyrtranslit.to_cyrillic("Republika", "me")
"Република"

Macedonian

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Моето летачко возило е полно со јагули", "mk")
"Moeto letačko vozilo e polno so jaguli"
>>> cyrtranslit.to_cyrillic("Moeto letačko vozilo e polno so jaguli", "mk")
"Моето летачко возило е полно со јагули"

Mongolian

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Амрагаа Сүнжидмаагаа гэсээр ирлээ дээ хө-хө-хө", "mn")
"Amragaa Sünjidmaagaa geseer irlee dee khö-khö-khö"
>>> cyrtranslit.to_cyrillic("Amragaa Sünjidmaagaa geseer irlee dee khö-khö-khö", "mn")
"Амрагаа Сүнжидмаагаа гэсээр ирлээ дээ хө-хө-хө"

Russian

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Моё судно на воздушной подушке полно угрей", "ru")
"Moyo sudno na vozdushnoj podushke polno ugrej"
>>> cyrtranslit.to_cyrillic("Moyo sudno na vozdushnoj podushke polno ugrej", "ru")
"Моё судно на воздушной подушке полно угрей"

Serbian

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Мој ховеркрафт је пун јегуља")
"Moj hoverkraft je pun jegulja"
>>> cyrtranslit.to_cyrillic("Moj hoverkraft je pun jegulja")
"Мој ховеркрафт је пун јегуља"

Tajik

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Ман мактуб навишта истодам", "tj")
"Man maktub navišta istodam"
>>> cyrtranslit.to_cyrillic("Man maktub navišta istodam", "tj")
"Ман мактуб навишта истодам"

Ukrainian

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Під лежачий камінь вода не тече", "ua")
"Pid ležačyj kamin' voda ne teče"
>>> cyrtranslit.to_cyrillic("Pid ležačyj kamin' voda ne teče", "ua")
"Під лежачий камінь вода не тече"

Command Line Interface

Sample command line call to transliterate a Russian text file:

$ cyrtranslit -l RU -i tests/ru.txt -o tests/output.txt

Use the -c argument to accomplish the reverse, that is to input latin characters and output cyrillic.

Use the -h argument for help.

You can also omit the input and output files and use standard input/output

$ echo 'Мој ховеркрафт је пун јегуља' | cyrtranslit -l sr
Moj hoverkraft je pun jegulja
$ echo 'Moj hoverkraft je pun jegulja' | cyrtranslit -l sr
Мој ховеркрафт је пун јегуља

You can test the "script" by running it directly on the Python command line interface, e.g.:

>>> import sys
>>> import cyrtranslit.cyrtranslit
>>> sys.argv.extend(['-l', 'RU'])
>>> sys.argv.extend(['-i', 'tests/ru.txt'])
>>> sys.argv.extend(['-o', 'tests/output.txt'])
>>> cyrtranslit.cyrtranslit.main()
>>> exit()

How can I contribute?

You can include support for other Cyrillic script alphabets. Follow these steps in order to do so:

  1. Create a new transliteration dictionary in the mapping.py file and reference to it in the TRANSLIT_DICT dictionary.
  2. Watch out for cases where two consecutive Latin alphabet letters are meant to transliterate into a single Cyrillic script letter. These cases need to be explicitly checked for inside the to_cyrillic() function in __init__.py.
  3. Add test cases inside of tests.py.
  4. Add test CLI input files in the tests directory.
  5. Update the documentation in the README.md.
  6. List yourself as one of the contributors.

Before tagging a release version and deploying to PyPI:

  1. Update the version and download_url properties in setup.py.
  2. Reserve a Zenodo DOI for the release and update this readme's Zenodo badge and citation instructions.

A big thank you to everyone who contributed:

cyrillic-transliteration's People

Contributors

anonymousvoice1 avatar cclauss avatar georgeslabreche avatar ratijas avatar rominf avatar savagej avatar serbipunk avatar shurph avatar sparkycz avatar syndamia avatar zjaume avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

cyrillic-transliteration's Issues

Support casing variations for 2 letters in latin from Mongolian

Montenegrin language does not support casing variations for 2 letters in latin, e.g.:

>>> import cyrtranslit
>>> cyrtranslit.to_cyrillic("Kh", "mn")
'Х'
>>> cyrtranslit.to_cyrillic("KH", "mn")
'КH'
>>> cyrtranslit.to_cyrillic("kh", "mn")
'х'
>>> cyrtranslit.to_cyrillic("kH", "mn")
'кH'
>>> cyrtranslit.to_cyrillic("Sh", "mn")
'Ш'
>>> cyrtranslit.to_cyrillic("SH", "mn")
'СH'
>>> cyrtranslit.to_cyrillic("TS", "mn")
'ТС'
>>> cyrtranslit.to_cyrillic("Ts", "mn")
'Ц'

Different output to_latin for v1.0 and v1.1

I received different outputs for the same inputs based on code version:

Version: 1.0

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Я часто пью водку", "ru")
"JA chasto p'ju vodku"

Version: 1.1

>>> import cyrtranslit
>>> cyrtranslit.to_latin("Я часто пью водку", "ru")
"YA chasto p'yu vodku"

Why not combine all *_CYR_TO_LAT_DICTs?

It seems to me that the safest code would simply combine all 3 - sr, me and mk.

The extra letters in me and mk do not conflict with any sr letters.

That way, a client can pass any Western South Slavic Cyrillic text, and be guaranteed an output.

(Likewise, in production code I would want Russian or Bulgarian letters to be handled in some way, in case they occur in text my code must process.)

ImportError: No module named 'mapping'

python 3.5.2
cyrtranslit-0.3

Traceback:

>>> import cyrtranslit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/lib/python3.5/site-packages/cyrtranslit/__init__.py", line 2, in <module>
    from mapping import TRANSLIT_DICT
ImportError: No module named 'mapping'

Latin letter "q" is not transliterated to Russian

When I try to transliterate any word written in Latin, which contain letter q, q letter kept as is.

Example:

In [1]: import cyrtranslit

In [2]: cyrtranslit.to_cyrillic('Question', lang_code='ru')
Out[2]: 'Qуестион'

Letter q doesn't exist in Russian alphabet, and in most cases q should be replaced with к.

Reference of mappings

Thank to develop and share this great project. I wonder what is the reference or historical background of the Cyrillic-Latin mappings in CyrTranslit. Is it based on the Soviet project? Or something similar exsiting transliteration scheme?

Python 3: 'str' object has no attribute 'decode'

string_to_transliterate = string_to_transliterate.decode('utf-8') does not work in Python 3, returns the error

AttributeError: 'str' object has no attribute 'decode'

Similarly, return latinized_str.encode('utf-8') means a byte-string is returned in Python 3.

b'my latin string'

Removing the encode and decode of strings in init.py makes the package work with python 3

Related to issue #6

Non existing examples

Sorry, but you should know that "Republika Kosovo" doesn't exist. And most of all THERE IS NO "Serbian phrase 'Republika kosovo'". Please, don't spread the confusion.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.