Skip to content

Commit 7213cda

Browse files
committed
Add hook and Kanji.
1 parent d249867 commit 7213cda

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# @package ext
2+
3+
__doc__ = """
4+
Transliterate Kanji, Katakana, and Hiragana into Romaji. """
5+
6+
7+
from logging import getLogger
8+
9+
from pykakasi import kakasi
10+
11+
from scriptshifter.exceptions import BREAK
12+
13+
14+
logger = getLogger(__name__)
15+
trans = kakasi()
16+
17+
18+
def s2r_post_config(ctx, src_code):
19+
if src_code not in "HKJ":
20+
raise ValueError(f"Source script code {src_code} not supported.")
21+
trans.setMode(src_code, "a")
22+
# TODO Use option switch: “Hepburn” , “Kunrei” or “Passport”
23+
trans.setMode("r", "Hepburn")
24+
trans.setMode("C", ctx.options["capitalize"] is not False)
25+
26+
ctx.dest = trans.getConverter().do(ctx.src)
27+
28+
return BREAK
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
general:
3+
name: Japanese (Kanji)
4+
case_sensitive: false
5+
description: Japanese language mapping for Kanji syllabary.
6+
version: 1.0.0
7+
date: 2026-02-11
8+
9+
script_to_roman:
10+
hooks:
11+
post_config:
12+
-
13+
- japanese.s2r_post_config
14+
- src_code: "J"

0 commit comments

Comments
 (0)