Japanese Character Interconverter
jaconv is a pure-Python library designed for interconverting Japanese characters, including Hiragana, Katakana, Hankaku (half-width), Zenkaku (full-width), and Romaji. It provides a straightforward API for various common text processing tasks involving Japanese script. The library is actively maintained, with its latest version being 0.5.0, and has a consistent release cadence addressing bug fixes and improvements.
Warnings
- gotcha The conversion logic for `alphabet2kana` and `kana2alphabet` functions, especially concerning small kana and specific romanization rules, has undergone several bug fixes and refinements across various versions (e.g., 0.2.3, 0.3, 0.5.0). This may lead to different conversion results for the same input when migrating between `jaconv` versions.
- deprecated Some original function names, such as `hankaku2zenkaku` and `zenkaku2hankaku`, were deprecated in very early versions (e.g., 0.1) in favor of more concise and commonly used aliases like `h2z` and `z2h`. While the deprecated names might still function for backward compatibility in some cases, it is strongly recommended to use the modern aliases for clarity and future-proofing.
Install
-
pip install jaconv
Imports
- jaconv
import jaconv
Quickstart
import jaconv
# Hiragana to Katakana
h_to_k = jaconv.hira2kata('ともえまみ') # => 'トモエマミ'
print(f"Hiragana to Katakana: {h_to_k}")
# Katakana to Hiragana
k_to_h = jaconv.kata2hira('巴マミ') # => '巴まみ'
print(f"Katakana to Hiragana: {k_to_h}")
# Half-width character to Full-width character
h_to_z = jaconv.h2z('ティロ・フィナーレabc123', kana=True, ascii=True, digit=True) # => 'ティロ・フィナーレabc123'
print(f"Half-width to Full-width: {h_to_z}")
# Full-width character to Half-width character
z_to_h = jaconv.z2h('ティロ・フィナーレabc123', kana=True, ascii=True, digit=True) # => 'ティロ・フィナーレabc123'
print(f"Full-width to Half-width: {z_to_h}")
# Alphabet to Hiragana
alph_to_hira = jaconv.alphabet2kana('japan') # => 'じゃぱん'
print(f"Alphabet to Hiragana: {alph_to_hira}")
# Hiragana to Alphabet (Hepburn-style)
hira_to_alph = jaconv.kana2alphabet('じゃぱん') # => 'japan'
print(f"Hiragana to Alphabet: {hira_to_alph}")