Ported from WaniKani/WanaKana v4.0.2.
This library is written in Kotlin, but it can be used from Java.
Visit the website to see WanaKana in action (JS version).
Or use the demo Android app included in this repository: ./gradlew demo:installDebug
.
// 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.
// 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()
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"
// 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
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 ", "私はすごく悲しい"]
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.