Skip to main content

Languages and Dialects transliteration

Project description

3aransia

Transliteration of languages and dialects

Open Source Love License made-with-python GitHub last commit

Contribution

For contribution you can refer to CONTRIBUTING.md

Prerequisites

Installation

pip install aaransia

Usage

Get all alphabets codes

from aaransia import get_alphabets_codes

print(get_alphabets_codes())
>>> ['ma', 'ar', 'la', 'ab', 'gr']

Get all alphabets

from aaransia import get_alphabets

print(get_alphabets())
>>> {   
>>>     'ab': 'Abjadi Alphabet',
>>>     'ar': 'Arabian Alphabet',
>>>     'gr': 'Greek Alphabet',
>>>     'la': 'Latin Alphabet',
>>>     'ma': 'Moroccan Alphabet'
>>> }

Transliterate from a language or dialect to another

ARABIC_SENTENCE = "كتب بلعربيا هنايا شحال ما بغيتي"

print(transliterate(ARABIC_SENTENCE, source='ar', target='ma'))
>>> ktb bl3rbya hnaya ch7al ma bghiti

Transliterate from all languages to all languages

from aaransia import transliterate, SourceLanguageError

MOROCCAN_SENTENCE = "ktb bl3rbya hnaya ch7al ma bghiti"
ARABIC_SENTENCE = "كتب بلعربيا هنايا شحال ما بغيتي"
ENGLISH_SENTENCE = "ktb bl'rbya hnaya chhal ma bghiti"
GREEK_SENTENCE = "κτμπ μπλ'ρμπυα χναυα σχχαλ μα μπγχιτι"

SENTENCES = [MOROCCAN_SENTENCE, ARABIC_SENTENCE, ENGLISH_SENTENCE, GREEK_SENTENCE]

ALPHABETS = get_alphabets_codes()

for i in range(len(SENTENCES)):
    try:
        for target_language in ALPHABETS:
            print(f'{SENTENCES[i]}\n'
                  f'{ALPHABETS[i]} ==> {target_language}\n'
                  f'{transliterate(SENTENCES[i], ALPHABETS[i], target_language)}\n')
    except SourceLanguageError as sle:
        print(SENTENCES[i], sle)
>>> ktb bl3rbya hnaya ch7al ma bghiti
>>> ma ==> ma
>>> ktb bl3rbya hnaya ch7al ma bghiti
>>> 
>>> ktb bl3rbya hnaya ch7al ma bghiti
>>> ma ==> ar
>>> كتب بلعربيا هنايا شحال ما بغيتي
>>> 
>>> ktb bl3rbya hnaya ch7al ma bghiti
>>> ma ==> en
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> 
>>> ktb bl3rbya hnaya ch7al ma bghiti
>>> ma ==> gr
>>> κτμπ μπλ'ρμπυα χναυα σχαλ μα μπριτι
>>> 
>>> كتب بلعربيا هنايا شحال ما بغيتي
>>> ar ==> ma
>>> ktb bl3rbya hnaya chhal ma bghyty
>>> 
>>> كتب بلعربيا هنايا شحال ما بغيتي
>>> ar ==> ar
>>> كتب بلعربيا هنايا شحال ما بغيتي
>>> 
>>> كتب بلعربيا هنايا شحال ما بغيتي
>>> ar ==> en
>>> ktb bl'rbya hnaya chhal ma bghyty
>>> 
>>> كتب بلعربيا هنايا شحال ما بغيتي
>>> ar ==> gr
>>> κτμπ μπλ'ρμπυα χναυα σχαλ μα μπρυτυ
>>> 
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> en ==> ma
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> 
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> en ==> ar
>>> كتب بل'ربيا هنايا شهال ما بغيتي
>>> 
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> en ==> en
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> 
>>> ktb bl'rbya hnaya chhal ma bghiti
>>> en ==> gr
>>> κτμπ μπλ'ρμπυα χναυα σχαλ μα μπριτι
>>> 
>>> κτμπ μπλ'ρμπυα χναυα σχχαλ μα μπγχιτι
>>> gr ==> ma
>>> ktb bl'ghbya hnaya chhhal ma bghiti
>>> 
>>> κτμπ μπλ'ρμπυα χναυα σχχαλ μα μπγχιτι
>>> gr ==> ar
>>> كتب بل'غبيا هنايا شههال ما بڭهيتي
>>> 
>>> κτμπ μπλ'ρμπυα χναυα σχχαλ μα μπγχιτι
>>> gr ==> en
>>> ktb bl'ghbya hnaya chhhal ma bghiti
>>> 
>>> κτμπ μπλ'ρμπυα χναυα σχχαλ μα μπγχιτι
>>> gr ==> gr
>>> κτμπ μπλ'ρμπυα χναυα σχχαλ μα μπγχιτι

Adding a language or a dialect

  1. Add it to the alphabet CSV file
  2. Generate the whole alphabet with the construct_alphabet function from utils.py
  3. Update the defaults.py
    1. Add the alphabet code
    2. Add the alphabet name
    3. Add both of them to the alphabet dictionary
    4. Add the double letters if they are
    5. Add the updated alphabet got from construct_alphabet earlier (use PrettyPrinter and pylint to format it, you can refer to main.py line 15)
  4. Test a text with the language just added against all other languages in test.py
    1. Add a language text to test in text_samples
    2. Add test handling for the new language
    3. Test it by using the command python -m unittest discover -s aaransia
    4. Fix the bugs
  5. Validate it semantically and phonetically
  6. Make a pull request

Other related projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aaransia-0.20.tar.gz (10.5 kB view details)

Uploaded Source

File details

Details for the file aaransia-0.20.tar.gz.

File metadata

  • Download URL: aaransia-0.20.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.2

File hashes

Hashes for aaransia-0.20.tar.gz
Algorithm Hash digest
SHA256 19c6d498cb260c097e4dcc9fd8a8222d851eed5b3a97833d876e81404d6468a3
MD5 3b0cc7cc92ff032292e08465c0e1c4e0
BLAKE2b-256 5f5f7a8ae4b2f8e0b525bbd02bf609ef0922dfe62114905dd164b36ba71df8e4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page