[PYTHON] Make Japanese into Romaji

Install pykakasi

You can convert Japanese characters to Romaji by using this module.

pip install pykakasi

Create a function that converts the bid price to Romaji.

from pykakasi import kakasi
kakasi = kakasi()
def jp2rome(text):
    kakasi.setMode("H", "a")  # Hiragana to ascii
    kakasi.setMode("K", "a")  # Katakana to ascii
    kakasi.setMode("J", "a")  # Japanese(kanji) to ascii
    kakasi.setMode("r", "Hepburn")  # Use Hepburn romanization
    conv = kakasi.getConverter()
    result = conv.do(text)
    return(result)

Example of use

jp2rome("Tesuto")
→'tesuto'
jp2rome("test")
→'tesuto'
jp2rome("test")
→'shiken'

Recommended Posts

Make Japanese into Romaji
How to make scrapy JSON output into Japanese
Make matplotlib Japanese compatible in 3 minutes
Make Raspberry Pi speak Japanese using OpenJtalk
[Python] Let's make matplotlib compatible with Japanese