wanakana-core

Kotlin port of WanaKana, a library for detecting and transliterating Hiragana, Katakana and Romaji.

License

License

GroupId

GroupId

dev.esnault.wanakana
ArtifactId

ArtifactId

wanakana-core
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

wanakana-core
Kotlin port of WanaKana, a library for detecting and transliterating Hiragana, Katakana and Romaji.
Project URL

Project URL

https://github.com/esnaultdev/wanakana-kt
Source Code Management

Source Code Management

https://github.com/esnaultdev/wanakana-kt/tree/master

Download wanakana-core

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

ワナカナ <--> WanaKana <--> わなかな

Kotlin utility library for detecting and transliterating Hiragana, Katakana, and Romaji

Ported from WaniKani/WanaKana v4.0.2.

This library is written in Kotlin, but it can be used from Java.

Demo

Visit the website to see WanaKana in action (JS version).

Or use the demo Android app included in this repository: ./gradlew demo:installDebug.

Usage

// Android bindings
implementation 'dev.esnault.wanakana:wanakana-android:1.1.1'

// Conversion and detection
// You don't need to include this if you use wanakana-android.
implementation 'dev.esnault.wanakana:wanakana-core:1.1.1'

The artifacts are available on mavenCentral, make sure that your buildscript repositories include mavenCentral.

Documentation

Quick Reference

Android bindings

// Automatically converts text using a TextWatcher.
// Uses `toKanaIme()` as converter by default
val binding = WanakanaAndroid.bind(editText)

// Adds a listener for text updates.
binding.addListener(initialize = true) { convertedText -> /* Do something. */ }

// Turns off the conversion.
// Not needed for cleanup, you can ignore the binding safely.
binding.clear()

Text conversion

Wanakana.toKana("ONAJI buttsuuji")
// => "オナジ ぶっつうじ"
Wanakana.toKana("座禅‘zazen’スタイル")
// => "座禅「ざぜん」スタイル"
Wanakana.toKana("batsuge-mu")
// => "ばつげーむ"

Wanakana.toHiragana("toukyou, オオサカ")
// => "とうきょう、 おおさか"
Wanakana.toHiragana("only カナ", passRomaji = true)
// => "only かな"
Wanakana.toHiragana("wi", useObsoleteKana = true)
// => "ゐ"

Wanakana.toKatakana("toukyou, おおさか")
// => "トウキョウ、 オオサカ"
Wanakana.toKatakana("only かな", passRomaji = true)
// => "only カナ"
Wanakana.toKatakana("wi", useObsoleteKana = true)
// => "ヰ"

Wanakana.toRomaji("ひらがな カタカナ")
// => "hiragana katakana"
Wanakana.toRomaji("ひらがな カタカナ", upcaseKatakana = true)
// => "hiragana KATAKANA"

Text checking utilities

// Available for both Char and String.
// Extensions functions are also available.

Wanakana.isJapanese("泣き虫。!〜2¥zenkaku")
// => true

Wanakana.isKana("あーア")
// => true

Wanakana.isHiragana("すげー")
// => true

Wanakana.isKatakana("ゲーム")
// => true

Wanakana.isKanji("切腹")
// => true
Wanakana.isKanji("勢い")
// => false

Wanakana.isRomaji("Tōkyō and Ōsaka")
// => true

Extra utilities

Wanakana.stripOkurigana("お祝い")
// => "お祝"
Wanakana.stripOkurigana("踏み込む")
// => "踏み込"
Wanakana.stripOkurigana("お腹", leading = true)
// => "腹"
Wanakana.stripOkurigana("ふみこむ", matchKanji = "踏み込む")
// => "ふみこ"
Wanakana.stripOkurigana("おみまい", matchKanji = "お祝い", leading = true)
// => "みまい"

Wanakana.tokenize("ふふフフ")
// => ["ふふ", "フフ"]
Wanakana.tokenize("hello 田中さん")
// => ["hello", " ", "田中", "さん"]
Wanakana.tokenize("I said 私はすごく悲しい", compact = true)
// => [ "I said ", "私はすごく悲しい"]

Differences with Wanakana JS

Wakakana JS Wanakana KT
String detection false if the input is empty true if the input is empty
(matches the behavior of String::all)
Detailed tokenize tokenize(input, { detailed: true }) tokenizeWithType(input)

Custom mappings are not implemented yet.

Credits

Original JavaScript library sponsored by Tofugu & WaniKani.

Versions

Version
1.1.1