ainconv 0.3.0

Converts Ainu words between different scripts (Katakana, Latin, Cyrillic)
Documentation

ainconv - Ainu language script converter

Crates.io GitHub issues GitHub

Overview

This cargo crate provides a comprehensive set of functions for converting text between different writing systems of the Ainu language.

Currently, Latin (Romanization), Katakana and Cyrillic scripts are supported. The default Katakana output uses the broadly adopted modern forms, and optional Katakana variant flags are available for compact historical or small-kana forms.

Sentence-style input is supported by converting Ainu words while preserving surrounding non-Ainu text and punctuation. Latin input is normalized to lower case during conversion.

Important Note

Conversion between Latin and Cyrillic script are lossless, however, conversion between Katakana and other scripts are lossy. This means that converting from Katakana to other scripts and then back to Katakana may not give the original string and the result may be ambiguous or even incorrect.

This is because the Katakana script used broadly for the Ainu language is intrinsically ambiguous. For example, it does not distinguish between tow and tu (both トゥ), iw and i.u (both イウ), ay and a.i (both アイ), etc. Some alternative Katakana scripts are proposed to solve this problem, but none of them are widely adopted. We are planning to support some of these alternative scripts in the future.

For a full survey of Ainu orthographic variation and how each issue maps to converter behaviour, see the shared orthographic variation catalogue in ainconv-tests (cross-implementation; maps to its options.schema.json).

Installation

Install the package using cargo

cargo add ainconv

or add the following line to your Cargo.toml file

[dependencies]
ainconv = "0.3.0"

Usage

Word Conversion

use ainconv::{
    convert_kana_to_latn,
    convert_latn_to_kana,
    convert_cyrl_to_latn,
    convert_latn_to_cyrl,
    convert_kana_to_cyrl,
    convert_cyrl_to_kana,
    // ...
}

println!("{}", convert_kana_to_latn("イランカラㇷ゚テ")); // "irankarapte"
println!("{}", convert_latn_to_kana("irankarapte")); // "イランカラㇷ゚テ"
println!("{}", convert_cyrl_to_latn("иранкараптэ")); // "irankarapte"
println!("{}", convert_latn_to_cyrl("irankarapte")); // "иранкараптэ"
println!("{}", convert_cyrl_to_kana("иранкараптэ")); // "イランカラㇷ゚テ"
println!("{}", convert_kana_to_cyrl("イランカラㇷ゚テ")); // "иранкараптэ"

Katakana Variants

convert_latn_to_kana keeps the default modern spelling, such as ウィ, ウェ, ウォ, , , and .

Use KanaOptions with convert_latn_to_kana_with_options or convert_cyrl_to_kana_with_options when you need compact Katakana variants.

use ainconv::{
    convert_cyrl_to_kana_with_options,
    convert_latn_to_kana_with_options,
    KanaOptions,
};

let opts = KanaOptions {
    use_wi: true,
    use_we: true,
    use_wo: true,
    use_small_i: true,
    use_small_u: true,
    use_small_n: true,
};

println!("{}", convert_latn_to_kana_with_options("wiki", &opts)); // "ヰキ"
println!("{}", convert_latn_to_kana_with_options("wenkur", &opts)); // "ヱンㇰㇽ"
println!("{}", convert_cyrl_to_kana_with_options("айну", &opts)); // "アイㇴ"

Each KanaOptions field defaults to false, so you can opt into only the variants you need:

field keeps default output
use_wi ウィ
use_we ウェ
use_wo ウォ
use_small_i for -y coda
use_small_u for -w coda
use_small_n for -n coda

Extra Functionality

Script Detection

Detect the script of a given string.

use ainconv::detect;

println!("{}", detect("aynu")); // "Latn"
println!("{}", detect("アイヌ")); // "Kana"
println!("{}", detect("айну")); // "Cyrl"

Syllable Splitting

use ainconv::separate;

println!("{:?}", separate("eyaykosiramsuypa")); // ["e", "yay", "ko", "si", "ram", "suy", "pa"]

License

MIT License (c) 2024 mkpoli

See also