Home

Awesome

Iuliia — Swift Version

Transliterate Cyrillic → Latin in every possible way

This is a Swift package for Iuliia by Anton Zhiyanov. It requires Swift 5.3 and Xcode 12 since from Swift 5.3 SPM supports package resources (JSON schema files and localization files in this case).

Transliteration means representing Cyrillic data (mainly names and geographic locations) with Latin letters. It is used for international passports, visas, green cards, driving licenses, mail and goods delivery etc.

Iuliia makes transliteration easy as calling iuliia.translate() in your favorite programming language.

Why use Iuliia:

Supported schemas

Actual schemas:

And deprecated ones:

For schema details and other information, see https://dangry.ru/iuliia (in Russian).

Basic Usage

let iuliia = try! Iuliia(name: .wikipedia) // Parses schema file and initializes Schema
iuliia.translate("Юлия") // → Iuliia

Custom Schemas

You can create your own schema JSON file with the following structure:

{
    "name": "Your Schema name", 
    "mapping": {
        "а": "a",
        "б": "b",
        "в": "v",
        .
        .
        .
        "э": "e",
        "ю": "yu",
        "я": "ya"
    },
    "prev_mapping": {
        "е": "ye",
        "ае": "ye"
    },
    "next_mapping": {
        "ъа": "y",
        "ъи": "y"
    },
    "ending_mapping": {
        "ий": "y",
        "ый": "y"
    }
}
KeyRequiredTypeDescriptionComment
nameNOStringReadable title for schema"Custom" by default
mappingYES[String: String]Key — Cyrillic letter; Value — Latin represenationOnly one character per key allowed, keys with more than one character will be ommited during transliteration. To define custom transliteration logic for sequence of characters use prev_mapping, next_mapping and ending_mapping.
prev_mappingNO[String: String]Key — 1 or 2 cyrillic letters; Value — Latin represenationMapping for letters with respect to previous sibling. One letter used for transliteration in beginning of words. According to this schema any е character in beginning of word or after а character will be transliterated to ye.
next_mappingNO[String: String]Key — 2 cyrillic letters; Value — Latin represenationMapping for letters with respect to next sibling. According to this schema any ъ character before а and и characters will be transliterated to y.
ending_mappingNO[String: String]Key — Any quantity of cyrillic letters; Value — Latin represenationMapping for word endings. According to this schema any word ended with ий or ый will end with just y.

For example, if you want to transliterate sequence of two cyrillic characters into one latin character (ксx is the common case) you can achieve this with the following prev_mapping and next_mapping structure:

{
    "prev_mapping": {
        "кс": "x"
    },
    "next_mapping": {
        "кс": ""
    }
}

To use your schema with Iuliia initialize it with schema URL

let iuliia = try! Iuliia(schemaURL: /path/to/your/custom/schema.json)

Additionaly you can create Swift Schema object and initialize Iuliia with it.

let schema = Schema(
    name: "My Custom Schema",
    letters: [ ... ],
    previous: [ ... ],
    next: [ ... ],
    ending: [ ... ]
)
let iuliia = Iuliia(schema: schema)

As with JSON schema files only letters required, other parameters are optional.

Additional features

Issues and limitations

In general:

Schema-specific:

If you found any problems while working with Iuliia feel free to create an Issue here.